tests.test_parameters module

tests.test_parameters.CLICK_HELP_PARAM_NAME = '_click_default_help'

Click’s internal .name for its built-in --help option.

Detected at runtime instead of hard-coded: _click_default_help is an internal identifier of Click, which Click Extra does not control.

class tests.test_parameters.Custom[source]

Bases: ParamType

A dummy custom type.

name: str = 'Custom'

the descriptive name of this 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 param and ctx arguments may be None in 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: Option

An 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: FruitOption

A 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:

None

tests.test_parameters.test_standalone_show_params_option(invoke, cmd_decorator, option_decorator, assert_output_regex)[source]
tests.test_parameters.test_integrated_show_params_option(invoke, create_config)[source]
tests.test_parameters.test_show_params_table_format_ordering(invoke, args_order)[source]

--params respects --table-format regardless 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 UNSET sentinel leaking into the value and default columns through the --params re-parse path. See the RAW_ARGS notes in click_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.

tests.test_parameters.test_show_params_config_file_cascade_shared_sections(invoke, tmp_path, monkeypatch)[source]

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 --config draws the config_file column without being asked.

Several files can then take part, so Source alone no longer tells which one a value came from.

tests.test_parameters.test_show_params_projection_overrides_the_cascade_column(invoke)[source]

An explicit --columns projection 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 --columns option of its own, or one whose --columns belongs 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_find_column_known_and_unknown()[source]
tests.test_parameters.test_render_doc_table_emits_markdown()[source]

render_doc_table returns a 2-column Markdown table covering every column.

tests.test_parameters.test_columns_option_projects_and_orders(invoke)[source]

--columns keeps 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.

--zulu is declared under the alpha name: 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 True does.

tests.test_parameters.test_recurse_subcommands(invoke)[source]
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"

See: https://github.com/kdeldycke/click-extra/pull/1286

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.verbose vs root.alpha.verbose), so there is no ambiguity.

See: https://github.com/kdeldycke/click-extra/pull/1286

tests.test_parameters.test_standalone_table_rendering(invoke, opt1, opt2, table_format)[source]

Check all rendering styles of the table with standalone --params and --table-format option.

tests.test_parameters.test_standalone_no_color_rendering(invoke, opt1, opt2, opt3, table_format)[source]

Check that all rendering styles are responding to the --color option.

tests.test_parameters.test_option_value_kind(opt, expected)[source]
tests.test_parameters.test_iter_subcommands_hidden_handling()[source]
tests.test_parameters.test_iter_subcommands_empty_for_non_group()[source]
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.spec in a deprecation notice.

From that release on, Click prints the flag with the longest prefix: --apt-cyg for --apt-cyg/--no-apt-cyg. Below it Click prints the apt_cyg identifier, 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-cyg on 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 reports human_readable_name, which for an option is self.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 envvar as a tuple, which the hint must not print as its repr.

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.

SortByOption reads its column definitions positionally, which is why its param_decls is keyword-only (see click_extra.decorators.sort_by_option).

tests.test_parameters.test_option_constructors_share_one_shape(option_class)[source]

param_decls first, 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 root the 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_prefix is listed under it.

The walk behind --params builds each subcommand’s context the way Click does for a real invocation, context settings included. A prefix derived from the parent’s would list GARDEN_PLANT_CROP, a variable the CLI never reads.