tests.test_parameters module¶
- tests.test_parameters.CLICK_HELP_PARAM_NAME = '_click_default_help'¶
Click’s internal
.namefor its built-in--helpoption.Detected at runtime instead of hard-coded:
_click_default_helpis an internal identifier of Click, which Click Extra does not control.
- class tests.test_parameters.Custom[source]¶
Bases:
ParamTypeA dummy custom type.
- convert(value, param, ctx)[source]¶
Convert the value to the correct type. This is not called if the value is
None(the missing value).This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.
The
paramandctxarguments may beNonein certain situations, such as when converting prompt input.If the value cannot be converted, call
fail()with a descriptive message.- Parameters:
value – The value to convert.
param – The parameter that is using this type to convert its value. May be
None.ctx – The current context that arrived at this value. May be
None.
- tests.test_parameters.test_canonical_param_name_matches_click(decl)[source]¶
The fold answers what Click names a parameter declared that way.
Click derives the name in
Option._parse_decls, which splits the prefix then applies this same fold. Pinning the two together is what keeps the helper honest when Click moves.
- tests.test_parameters.test_canonical_param_name_is_many_to_one()[source]¶
The fold identifies a name, and cannot reconstruct a spelling.
- tests.test_parameters.test_canonical_param_name_never_answers_an_identifier_decl()[source]¶
Click takes an identifier declaration verbatim, so no fold produces it.
This is why a resolved spelling has to come back from the names a CLI declares, rather than from what the fold returns.
- class tests.test_parameters.FruitOption(param_decls=None, show_default=None, prompt=False, confirmation_prompt=False, prompt_required=True, hide_input=False, is_flag=None, flag_value=Sentinel.UNSET, multiple=False, count=False, allow_from_autoenv=True, type=None, help=None, hidden=False, show_choices=True, show_envvar=False, deprecated=False, **attrs)[source]¶
Bases:
OptionAn option class to search for.
- class tests.test_parameters.AppleOption(param_decls=None, show_default=None, prompt=False, confirmation_prompt=False, prompt_required=True, hide_input=False, is_flag=None, flag_value=Sentinel.UNSET, multiple=False, count=False, allow_from_autoenv=True, type=None, help=None, hidden=False, show_choices=True, show_envvar=False, deprecated=False, **attrs)[source]¶
Bases:
FruitOptionA subclass of it, to tell subclass matching apart.
- tests.test_parameters.test_search_params_returns_the_one_match()[source]¶
A single match comes back as itself, a subclass matching by default.
- tests.test_parameters.test_last_param_keeps_the_last_exact_match()[source]¶
Duplicates resolve to the last one, and a subclass never matches.
- tests.test_parameters.test_factory_decorators_expose_option_signature()[source]¶
Factory-built option decorators expose their option class’s real signature.
Guards the signature propagation in
click_extra.decorators.decorator_factory(), which lets editors,help()and Sphinx see the actual parameters instead of an opaque(*args, **kwargs).
- tests.test_parameters.test_params_auto_types(invoke, option_decorator)[source]¶
Check parameters types and structure are properly derived from CLI.
- tests.test_parameters.assert_table_content(output, expected_table, table_format=None)[source]¶
Helper to assert the content of a rendered table in the output.
- Return type:
- tests.test_parameters.test_standalone_show_params_option(invoke, cmd_decorator, option_decorator, assert_output_regex)[source]¶
- tests.test_parameters.test_show_params_table_format_ordering(invoke, args_order)[source]¶
--paramsrespects--table-formatregardless of CLI order.
- tests.test_parameters.test_show_params_native_types(invoke, table_format)[source]¶
Serialization formats emit native types instead of styled glyphs.
- tests.test_parameters.test_show_params_no_default_renders_none(invoke)[source]¶
A parameter with no default renders as None, not the UNSET sentinel.
Regression guard for Click’s
UNSETsentinel leaking into the value and default columns through the--paramsre-parse path. See the RAW_ARGS notes inclick_extra.context.
- tests.test_parameters.test_show_params_config_file_cascade(invoke, tmp_path, monkeypatch)[source]¶
The config_file column names the cascade layer a value resolved from.
The local file wins the root-level parameter; the parent file owns the
[sub]section the local file does not define. A parameter overridden on the command line keeps an empty column: the file did not supply the effective value.
The config_file column names the file of each key of a shared section.
Both files define the
[sub]section and its[sub.leaf]sub-section: at each depth, the local file is named for the key both set, and the parent file for the key only it sets.
- tests.test_parameters.test_show_params_config_file_single_file(invoke, create_config)[source]¶
A single loaded file is attributed to every config-sourced parameter.
- tests.test_parameters.test_show_params_config_file_url(invoke, httpserver, table_format, load_rows)[source]¶
A remote configuration is named by its exact URL, in text and JSON tables.
A text table shrinks a local path to
~, but a URL is not a path: normalized as one, it loses a slash after its scheme. The JSON table, which never shrinks, is the control.
- tests.test_parameters.test_show_params_config_file_column_is_opt_in(invoke)[source]¶
config_file is addressable by ID but stays out of the default table.
- tests.test_parameters.test_show_params_config_file_column_drawn_when_cascading(invoke)[source]¶
A cascading
--configdraws theconfig_filecolumn without being asked.Several files can then take part, so
Sourcealone no longer tells which one a value came from.
- tests.test_parameters.test_show_params_projection_overrides_the_cascade_column(invoke)[source]¶
An explicit
--columnsprojection is honored as given, cascade or not.
- tests.test_parameters.test_show_params_subclass_widens_the_default_columns(invoke)[source]¶
A subclass widening
default_columns()draws the column it added.That hook is the only way to reach an opt-in column on a CLI exposing no
--columnsoption of its own, or one whose--columnsbelongs to its subcommands and carries a different vocabulary.
- tests.test_parameters.test_column_registry_is_consistent()[source]¶
TABLE_HEADERS exposes parallel
column_labels()/column_ids().
- tests.test_parameters.test_render_doc_table_emits_markdown()[source]¶
render_doc_tablereturns a 2-column Markdown table covering every column.
- tests.test_parameters.test_columns_option_projects_and_orders(invoke)[source]¶
--columnskeeps only selected columns and preserves the user order.
- tests.test_parameters.test_columns_option_rejects_unknown_id(invoke)[source]¶
An unknown column ID raises a UsageError with available IDs listed.
- tests.test_parameters.test_params_rows_keep_path_order_under_projection(invoke, columns)[source]¶
Rows follow their parameter path, whichever column comes first.
--zuluis declared under thealphaname: ordered by its spec, its row would follow the one of--beta.
- tests.test_parameters.test_params_never_prompts(invoke)[source]¶
Introspecting an option that declares a prompt does not ask for its value.
The value of a parameter is replayed from the command line, which leaves the one a user would type at the prompt missing.
- tests.test_parameters.test_params_confirmation_prompt_string_reads_as_set(invoke)[source]¶
A custom confirmation prompt asks for confirmation, like
Truedoes.
- tests.test_parameters.test_subcommand_conflicts_with_parent_param(invoke)[source]¶
A subcommand whose name matches its direct parent’s param is skipped in the parameter tree (the config key would be ambiguous), but does not crash the CLI.
[root.alpha] # "foo" is ambiguous: is it the --foo param or the [root.alpha.foo] subcommand? foo = "apple"
- tests.test_parameters.test_nested_subcommand_no_false_conflict_with_root_param(invoke)[source]¶
A nested subcommand can share a name with a root-level param without conflict.
The config paths are distinct (
root.verbosevsroot.alpha.verbose), so there is no ambiguity.
- tests.test_parameters.test_standalone_table_rendering(invoke, opt1, opt2, table_format)[source]¶
Check all rendering styles of the table with standalone
--paramsand--table-formatoption.
- tests.test_parameters.test_standalone_no_color_rendering(invoke, opt1, opt2, opt3, table_format)[source]¶
Check that all rendering styles are responding to the
--coloroption.
- tests.test_parameters.test_iter_params_for_display_follows_the_help_screen()[source]¶
Presentation order, not the processing order carried by
params.
- tests.test_parameters.test_iter_params_for_display_keeps_option_groups_together()[source]¶
Options declared in a Cloup group are yielded under that group.
- tests.test_parameters.test_iter_params_for_display_falls_back_to_get_params()[source]¶
A plain Click command holds a single order, and it is the one to yield.
- tests.test_parameters.test_iter_params_for_display_yields_late_additions_last()[source]¶
A parameter attached after construction is missing from the cached groups.
- tests.test_parameters.test_help_column_is_opt_in(invoke)[source]¶
The Help column exists, stays out of the way, and answers to its ID.
- tests.test_parameters.test_help_column_paints_the_deprecation_marker(invoke)[source]¶
The marker takes the slot the help screen paints it with.
Every other column of the rendered table is themed, and the marker is the one part of this one Click Extra writes rather than the CLI author.
- tests.test_parameters.PARAMETER_SPEC_CLICK_VERSION = (8, 6)¶
Click release naming a parameter by
Parameter.specin a deprecation notice.From that release on, Click prints the flag with the longest prefix:
--apt-cygfor--apt-cyg/--no-apt-cyg. Below it Click prints theapt_cygidentifier, which Click Extra replaces with every spelling.
- tests.test_parameters.DEPRECATED_FLAG_NAME = '--apt-cyg / --no-apt-cyg'¶
How a notice names
--apt-cyg/--no-apt-cygon the installed Click.
- tests.test_parameters.test_option_deprecation_notice_names_its_flags(invoke)[source]¶
The notice names a flag a user types, not the identifier Click derived.
Below
PARAMETER_SPEC_CLICK_VERSION, Click reportshuman_readable_name, which for an option isself.name: the one spelling that appears nowhere on the command line.
- tests.test_parameters.test_option_error_hint_names_each_environment_variable(invoke, envvar, hint)[source]¶
The hint of a failing option quotes each variable that feeds it.
Click Extra stores every
envvaras a tuple, which the hint must not print as itsrepr.
- tests.test_parameters.test_deprecation_notice_reaches_a_configuration_file(invoke, create_config)[source]¶
A file switching a deprecated parameter on gets the notice too.
Click stops one rank short of the configuration, so the one place a selection outlives the project it names said nothing.
- tests.test_parameters.test_deprecation_notice_stays_silent_on_the_default(invoke)[source]¶
Nobody asked for the parameter, so nothing announces it.
- tests.test_parameters.test_deprecation_notice_is_emitted_once(invoke, create_config)[source]¶
A parameter named on both the command line and in a file warns once.
- tests.test_parameters.test_help_column_is_documented()[source]¶
The auto-generated column reference covers the opt-in column too.
- tests.test_parameters.POSITIONAL_DEFINITIONS = frozenset({'SortByOption'})¶
Option classes taking positional definitions ahead of
param_decls.SortByOptionreads its column definitions positionally, which is why itsparam_declsis keyword-only (seeclick_extra.decorators.sort_by_option).
param_declsfirst, then annotated keyword-only arguments, then**kwargs.One shape across every option class: a caller never has to look up the positional order of a passthrough, and an unannotated one cannot slip in.
- tests.test_parameters.test_option_constructors_leave_the_root_logger_alone(option_class)[source]¶
Building an option changes neither the handlers nor the level of
root.An option is built when its command is decorated, so when the module of the command is imported. The root logger belongs to the whole process by then: an application importing the CLI, or pytest collecting it, has its handlers there.
- tests.test_parameters.test_options_lend_the_root_logger_a_handler_for_the_run(option_class)[source]¶
Each option gives
rootthe handler of Click Extra when Click prepares to parse a command line, and takes it back when the context closes.Any of these options may report through log records: none may count on another option of the command to bring the handler that prints them.
- tests.test_parameters.test_params_lists_the_envvars_a_subcommand_reads(invoke)[source]¶
A subcommand setting its own
auto_envvar_prefixis listed under it.The walk behind
--paramsbuilds each subcommand’s context the way Click does for a real invocation, context settings included. A prefix derived from the parent’s would listGARDEN_PLANT_CROP, a variable the CLI never reads.