tests.test_carapace module¶
- class tests.test_carapace.FruitType[source]¶
Bases:
ParamTypeA param type with a custom, dynamic
shell_completeoverride.- shell_complete(ctx, param, incomplete)[source]¶
Return a list of
CompletionItemobjects for the incomplete value. Most types do not provide completions, but some do, and this allows custom types to provide custom completions as well.- Parameters:
ctx – Invocation context for this command.
param – The parameter that is requesting completion.
incomplete – Value being completed. May be empty.
Added in version 8.0.
- tests.test_carapace.complete_city(ctx, param, incomplete)[source]¶
A param-level
shell_completecallback.
A hidden flag is exported marked, never silently.
Carapace completes what a spec lists, so a hidden option stays reachable like a hidden command does;
&is what keeps a reader able to tell.
- tests.test_carapace.test_required_flag_key_carries_the_modifier(opts, value, repeatable, expected)[source]¶
!before&, the ordercarapace-specwrites them in.
- tests.test_carapace.test_required_boolean_pair_is_left_unmarked()[source]¶
Either spelling satisfies Click, and the spec cannot say “one of these”.
Marking both would demand both; marking the positive alone would hide that the negative answers too.
- tests.test_carapace.test_description_drops_the_no_rewrap_marker()[source]¶
Click’s
marker never reaches the YAML.It is a control character telling Click’s own formatter not to rewrap, not prose: a description carrying it would hand Carapace a stray byte.
- tests.test_carapace.test_command_description_loses_its_backticks_like_a_flag_does()[source]¶
A command’s description and its flags share one normalizer.
A reST inline literal reads the same in both: its text is kept, and the backticks that only HTML docs render are dropped.
- tests.test_carapace.test_operand_help_reaches_the_documentation_block()[source]¶
An operand’s help has one home in the spec, and it is not
completion.completion.positionalholds actions, so the prose rides the siblingdocumentationblock, indexed the same way.
- tests.test_carapace.test_undocumented_operand_leaves_no_documentation_block()[source]¶
Nothing to say means no block at all, rather than a row of blanks.
- tests.test_carapace.test_documentation_stays_aligned_with_its_actions()[source]¶
A documented operand behind an undocumented one keeps its index.
The two lists are read positionally, so a dropped blank would shift the prose onto the wrong operand.
- tests.test_carapace.test_option_computing_its_help_still_describes_itself()[source]¶
An option leaving
helpatNonestill reaches the spec described.Click Extra’s own
-vand-qbuild their text from the resolved base verbosity, so reading the attribute hands back nothing.
- tests.test_carapace.test_enum_choice_completes_by_member_name()[source]¶
An
Enumchoice completes by the member names Click accepts.str()of a member readsFruit.APPLE, which Click rejects as a value: the spec has to carry the spelling the shell can type.
- tests.test_carapace.test_completion_variable_follows_clicks_derivation()[source]¶
The callback exports the variable Click reads for the program name.
Click turns both
-and.into_before upper-casing, so a script run asgarden.pylistens to_GARDEN_PY_COMPLETE. Any other spelling is a variable nothing reads, and the callback silently completes nothing.
- tests.test_carapace.test_no_flag_is_persistent(spec)[source]¶
Click parses an option only at the level of its own command.
A
persistentflagsentry would offer an option after a subcommand, where Click rejects it, so no node of the spec carries one.
- tests.test_carapace.test_spec_agrees_with_click_on_flag_scope(invoke)[source]¶
The spec offers a root option after a subcommand exactly when Click takes it.
- tests.test_carapace.test_dump_requires_pyyaml(monkeypatch)[source]¶
A missing PyYAML surfaces as a pointed error at dump time, not at import.
- tests.test_carapace.test_help_format_carapace_without_pyyaml(monkeypatch)[source]¶
--help-format carapacenames the extra to install, with no traceback.
- tests.test_carapace.test_subcommand_dynamic_completion_resolves_end_to_end(monkeypatch)[source]¶
The COMP_WORDS a subcommand flag’s generated macro builds must let the backend resolve that option’s value, not the root command.
When completing a subcommand flag’s value, Carapace forwards an empty word list to the macro: it strips the parent command names, and keeps the flag being completed in its own state rather than passing it through. So the macro bakes both the command path and the flag spelling, and
$*expands to nothing. This reconstructs the resulting COMP_WORDS from the generated macro and confirms the backend resolves the forecast callback. A root-only, flag-less macro would reconstruct bareweatherand complete the subcommand list instead.
- tests.test_carapace.test_wrap_carapace_install(runner, greet_script, tmp_path, monkeypatch)[source]¶
- tests.test_carapace.test_xdg_dir_resolves_at_call_time(tmp_path, monkeypatch, environ, expected)[source]¶
The variable wins when set and non-empty, else the default under
HOME.
- tests.test_carapace.test_get_cache_dir(monkeypatch, platform_id, environ, expected)[source]¶
An absolute
XDG_CACHE_HOMEcomes first, except on Windows.
- tests.test_carapace.test_install_resolves_home_at_call_time(tmp_path, monkeypatch)[source]¶
The spec lands under the
HOMEin force at the call, not at import.With no
XDG_CONFIG_HOMEset, the spec directory derives from the home directory. A test fixture or a packaging script pointingHOMEelsewhere for one invocation is honored, which a path expanded at import cannot do.
- tests.test_carapace.test_wrap_carapace_mutually_exclusive(runner, greet_script, extra_flags, message)[source]¶
- tests.test_carapace.test_wrap_install_requires_an_installable_format(runner, greet_script)[source]¶
A destination only means something for a rendering someone installs.
- tests.test_carapace.test_spec_drives_real_carapace_engine(tmp_path)[source]¶
Feed a generated spec to the real carapace-spec binary, end-to-end.
The tests above simulate Carapace at the CarapaceComplete level. This one downloads a pinned carapace-spec release and drives it through each dynamic shape: a root option, a subcommand option, and a subcommand argument. It guards the contract between the emitted macros and Carapace’s real traverse/exec/parse behavior, which the simulation cannot see: Carapace strips parent command names from the words it forwards, and withholds the flag being completed entirely, so the macros must bake both back in.
Attention
Downloads the carapace-spec binary from GitHub and executes it, hence the
networkmark (andonce, to run on a single CI runner). The dynamic macro shells out, so the test only runs on POSIX platforms.