click_extra.tests package#

Submodules#

click_extra.tests.conftest module#

Fixtures, configuration and helpers for tests.

click_extra.tests.conftest.skip_linux(*args, **kwargs) = MarkDecorator(mark=Mark(name='skipif', args=(True,), kwargs={'reason': 'Skip Linux'}))#

Pytest mark to skip a test if run on a Linux system.

click_extra.tests.conftest.skip_macos(*args, **kwargs) = MarkDecorator(mark=Mark(name='skipif', args=(False,), kwargs={'reason': 'Skip macOS'}))#

Pytest mark to skip a test if run on a macOS system.

click_extra.tests.conftest.skip_windows(*args, **kwargs) = MarkDecorator(mark=Mark(name='skipif', args=(False,), kwargs={'reason': 'Skip Windows'}))#

Pytest mark to skip a test if run on a Windows system.

click_extra.tests.conftest.unless_linux(*args, **kwargs) = MarkDecorator(mark=Mark(name='skipif', args=(False,), kwargs={'reason': 'Linux required'}))#

Pytest mark to skip a test unless it is run on a Linux system.

click_extra.tests.conftest.unless_macos(*args, **kwargs) = MarkDecorator(mark=Mark(name='skipif', args=(True,), kwargs={'reason': 'macOS required'}))#

Pytest mark to skip a test unless it is run on a macOS system.

click_extra.tests.conftest.unless_windows(*args, **kwargs) = MarkDecorator(mark=Mark(name='skipif', args=(True,), kwargs={'reason': 'Windows required'}))#

Pytest mark to skip a test unless it is run on a Windows system.

click_extra.tests.conftest.skip_windows_colors(*args, **kwargs) = MarkDecorator(mark=Mark(name='skipif', args=(False,), kwargs={'reason': 'Click overstrip colors on Windows'}))#

Skips color tests on Windows as click.testing.invoke overzealously strips colors.

See: - https://github.com/pallets/click/issues/2111 - https://github.com/pallets/click/issues/2110

click_extra.tests.conftest.extra_runner()[source]#

Runner fixture for click.testing.ExtraCliRunner.

click_extra.tests.conftest.invoke(extra_runner)[source]#

Invoke fixture shorthand for click.testing.ExtraCliRunner.invoke.

click_extra.tests.conftest.command_decorators(no_commands=False, no_groups=False, no_click=False, no_cloup=False, no_redefined=False, no_extra=False, with_parenthesis=True, with_types=False)[source]#

Returns collection of Pytest parameters to test all forms of click/cloup/click- extra command-like decorators.

Return type:

tuple[ParameterSet, ...]

click_extra.tests.conftest.create_config(tmp_path)[source]#

A generic fixture to produce a temporary configuration file.

click_extra.tests.test_colorize module#

click_extra.tests.test_colorize.test_theme_definition()[source]#

Ensure we do not leave any property we would have inherited from cloup and logging primitives.

click_extra.tests.test_colorize.test_extra_theme()[source]#
click_extra.tests.test_colorize.test_option_highlight(opt, expected_outputs)[source]#

Test highlighting of all option’s variations.

click_extra.tests.test_colorize.test_only_full_word_highlight()[source]#
click_extra.tests.test_colorize.test_keyword_collection(invoke)[source]#
click_extra.tests.test_colorize.test_standalone_color_option(invoke, option_decorator, param, expecting_colors)[source]#

Check color option values, defaults and effects on all things colored, including verbosity option.

click_extra.tests.test_colorize.test_no_color_env_convention(invoke, env, env_expect_colors, param, param_expect_colors)[source]#
click_extra.tests.test_colorize.test_integrated_color_option(invoke, param, expecting_colors)[source]#

Check effect of color option on all things colored, including verbosity option.

Also checks the color option in subcommands is inherited from parent context.

click_extra.tests.test_colorize.test_substring_highlighting(substrings, expected, ignore_case)[source]#
click_extra.tests.test_colorize.test_standalone_help_option(invoke, cmd_decorator, cmd_type, option_decorator)[source]#

click_extra.tests.test_commands module#

Test defaults of our custom commands, as well as their customizations and attached options, and how they interact with each others.

click_extra.tests.test_commands.test_module_root_declarations()[source]#
click_extra.tests.test_commands.all_command_cli(request)[source]#

A CLI that is mixing all variations and flavors of subcommands.

click_extra.tests.test_commands.test_unknown_option(invoke, all_command_cli)[source]#
click_extra.tests.test_commands.test_unknown_command(invoke, all_command_cli)[source]#
click_extra.tests.test_commands.test_required_command(invoke, all_command_cli)[source]#
click_extra.tests.test_commands.test_group_help(invoke, all_command_cli, param)[source]#
click_extra.tests.test_commands.test_help_eagerness(invoke, all_command_cli, params)[source]#

See: https://click.palletsprojects.com/en/8.0.x/advanced/#callback-evaluation- order.

click_extra.tests.test_commands.test_subcommand_help(invoke, all_command_cli, cmd_id, param)[source]#
click_extra.tests.test_commands.test_subcommand_execution(invoke, all_command_cli, cmd_id)[source]#
click_extra.tests.test_commands.test_integrated_version_value(invoke, all_command_cli)[source]#
click_extra.tests.test_commands.test_colored_bare_help(invoke, cmd_decorator, param)[source]#

Extra decorators are always colored.

Even when stripped of their default parameters, as reported in: https://github.com/kdeldycke/click-extra/issues/534 https://github.com/kdeldycke/click-extra/pull/543

click_extra.tests.test_commands.test_no_option_leaks_between_subcommands(invoke)[source]#

As reported in https://github.com/kdeldycke/click-extra/issues/489.

click_extra.tests.test_commands.test_option_group_integration(invoke)[source]#
click_extra.tests.test_commands.test_show_envvar_parameter(invoke, cmd_decorator, ctx_settings, expected_help)[source]#
click_extra.tests.test_commands.test_raw_args(invoke)[source]#

Raw args are expected to be scoped in subcommands.

click_extra.tests.test_config module#

click_extra.tests.test_config.simple_config_cli(request)[source]#
click_extra.tests.test_config.test_unset_conf_no_message(invoke, simple_config_cli)[source]#
click_extra.tests.test_config.test_unset_conf_debug_message(invoke, simple_config_cli)[source]#
click_extra.tests.test_config.test_conf_default_path(invoke, simple_config_cli)[source]#
click_extra.tests.test_config.test_conf_not_exist(invoke, simple_config_cli)[source]#
click_extra.tests.test_config.test_conf_not_file(invoke, simple_config_cli)[source]#
click_extra.tests.test_config.test_strict_conf(invoke, create_config)[source]#

Same test as the one shown in the readme, but in strict validation mode.

click_extra.tests.test_config.test_conf_file_overrides_defaults(invoke, simple_config_cli, create_config, httpserver, conf_name, conf_text, conf_data)[source]#
click_extra.tests.test_config.test_auto_env_var_conf(invoke, simple_config_cli, create_config, httpserver, conf_name, conf_text, conf_data)[source]#
click_extra.tests.test_config.test_conf_file_overridden_by_cli_param(invoke, simple_config_cli, create_config, httpserver, conf_name, conf_text, conf_data)[source]#
click_extra.tests.test_config.test_conf_metadata(invoke, create_config, httpserver, conf_name, conf_text, conf_data)[source]#

click_extra.tests.test_logging module#

click_extra.tests.test_logging.test_level_default_order()[source]#
click_extra.tests.test_logging.test_root_logger_defaults()[source]#

Check our internal default is aligned to Python’s root logger.

click_extra.tests.test_logging.test_unrecognized_verbosity(invoke, cmd_decorator, cmd_type)[source]#
click_extra.tests.test_logging.test_default_root_logger(invoke, cmd_decorator, option_decorator, level)[source]#

Checks: - the default logger is <root> - the default logger message format - level names are colored - log level is propagated to all other loggers.

click_extra.tests.test_logging.test_integrated_verbosity_option(invoke, level)[source]#
click_extra.tests.test_logging.test_custom_logger_param(invoke, logger_param, params)[source]#

Passing a logger instance or name to the default_logger parameter works.

click_extra.tests.test_logging.test_custom_option_name(invoke)[source]#

click_extra.tests.test_parameters module#

click_extra.tests.test_parameters.test_extend_envvars(envvars_1, envvars_2, result)[source]#
click_extra.tests.test_parameters.test_normalize_envvar(env_name, normalized_env)[source]#
click_extra.tests.test_parameters.test_show_auto_envvar_help(invoke, cmd_decorator, option_help)[source]#

Check that the auto-generated envvar appears in the help screen with the extra variants.

Checks that https://github.com/pallets/click/issues/2483 is addressed.

click_extra.tests.test_parameters.envvars_test_cases()[source]#
click_extra.tests.test_parameters.test_auto_envvar_parsing(invoke, cmd_decorator, envvars, expected_flag)[source]#

This test highlights the way Click recognize and parse envvars.

It shows that the default behavior is not ideal, and covers how extra_command improves the situation by normalizing the envvar name.

class click_extra.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.

click_extra.tests.test_parameters.test_params_auto_types(invoke, option_decorator)[source]#

Check parameters types and structure are properly derived from CLI.

click_extra.tests.test_parameters.test_standalone_show_params_option(invoke, cmd_decorator, option_decorator)[source]#
click_extra.tests.test_parameters.test_integrated_show_params_option(invoke, create_config)[source]#
click_extra.tests.test_parameters.test_recurse_subcommands(invoke)[source]#

click_extra.tests.test_platforms module#

click_extra.tests.test_platforms.test_mutual_exclusion()[source]#

Only directly tests OSes on which the test suite is running via GitHub actions.

click_extra.tests.test_platforms.test_platform_definitions()[source]#
click_extra.tests.test_platforms.test_unique_ids()[source]#

Platform and group IDs must be unique.

click_extra.tests.test_platforms.test_group_constants()[source]#

Group constants and IDs must be aligned.

click_extra.tests.test_platforms.test_groups_content()[source]#
click_extra.tests.test_platforms.test_logical_grouping()[source]#

Test logical grouping of platforms.

click_extra.tests.test_platforms.test_group_no_missing_platform()[source]#

Check all platform are attached to at least one group.

click_extra.tests.test_platforms.test_non_overlapping_groups()[source]#

Check non-overlapping groups are mutually exclusive.

click_extra.tests.test_platforms.test_overlapping_groups()[source]#

Check all extra groups overlaps with at least one non-overlapping.

click_extra.tests.test_platforms.test_reduction(items, expected)[source]#
click_extra.tests.test_platforms.test_current_os_func()[source]#
click_extra.tests.test_platforms.test_os_labels()[source]#
click_extra.tests.test_platforms.test_skip_linux()[source]#
click_extra.tests.test_platforms.test_skip_macos()[source]#
click_extra.tests.test_platforms.test_skip_windows()[source]#
click_extra.tests.test_platforms.test_unless_linux()[source]#
click_extra.tests.test_platforms.test_unless_macos()[source]#
click_extra.tests.test_platforms.test_unless_windows()[source]#

click_extra.tests.test_pygments module#

click_extra.tests.test_pygments.is_relative_to(path, *other)[source]#

Return True if the path is relative to another path or False.

This is a backport of pathlib.Path.is_relative_to from Python 3.9.

Return type:

bool

click_extra.tests.test_pygments.test_ansi_lexers_candidates(tmp_path)[source]#

Look into Pygments test suite to find all ANSI lexers candidates.

Good candidates for ANSI colorization are lexers that are producing Generic.Output tokens, which are often used by REPL-like and scripting terminal to render text in a console.

The list is manually maintained in Click Extra code, and this test is here to detect new candidates from new releases of Pygments.

Attention

The Pygments source code is downloaded from GitHub in the form of an archive, and extracted in a temporary folder.

The version of Pygments used for this test is the one installed in the current environment.

Danger

Security check While extracting the archive, we double check we are not fed an archive exploiting relative .. or . path attacks.

click_extra.tests.test_pygments.collect_classes(klass, prefix='Ansi')[source]#

Returns all classes defined in click_extra.pygments that are a subclass of klass, and whose name starts with the provided prefix.

click_extra.tests.test_pygments.get_pyproject_section(*section_path)[source]#

Descends into the TOML tree of pyproject.toml to reach the value specified by section_path.

Return type:

dict[str, str]

click_extra.tests.test_pygments.check_entry_points(entry_points, *section_path)[source]#
Return type:

None

click_extra.tests.test_pygments.test_formatter_entry_points()[source]#
click_extra.tests.test_pygments.test_filter_entry_points()[source]#
click_extra.tests.test_pygments.test_lexer_entry_points()[source]#
click_extra.tests.test_pygments.test_registered_formatters()[source]#
click_extra.tests.test_pygments.test_registered_filters()[source]#
click_extra.tests.test_pygments.test_registered_lexers()[source]#
click_extra.tests.test_pygments.test_ansi_lexers_doc()[source]#

click_extra.tests.test_tabulate module#

click_extra.tests.test_tabulate.test_unrecognized_format(invoke, cmd_decorator, cmd_type)[source]#
click_extra.tests.test_tabulate.test_recognized_modes()[source]#

Check all rendering modes proposed by the table module are accounted for and there is no duplicates.

click_extra.tests.test_tabulate.table_cli(request)[source]#
click_extra.tests.test_tabulate.test_all_table_rendering(invoke, table_cli, format_name, expected)[source]#

click_extra.tests.test_telemetry module#

click_extra.tests.test_telemetry.test_standalone_telemetry_option(invoke, cmd_decorator, option_decorator)[source]#
click_extra.tests.test_telemetry.test_multiple_envvars(invoke)[source]#

click_extra.tests.test_testing module#

Test the testing utilities and the simulation of CLI execution.

click_extra.tests.test_testing.test_real_fs()[source]#

Check a simple test is not caught into the CLI runner fixture which is encapsulating all filesystem access into temporary directory structure.

click_extra.tests.test_testing.test_temporary_fs(extra_runner)[source]#

Check the CLI runner fixture properly encapsulated the filesystem in temporary directory.

click_extra.tests.test_testing.test_env_copy()[source]#
click_extra.tests.test_testing.test_runner_output()[source]#
click_extra.tests.test_testing.test_runner_empty_stderr(mix_stderr)[source]#
click_extra.tests.test_testing.color_cli(request)[source]#
click_extra.tests.test_testing.check_default_colored_rendering(result)[source]#
click_extra.tests.test_testing.check_default_uncolored_rendering(result)[source]#
click_extra.tests.test_testing.check_forced_uncolored_rendering(result)[source]#
click_extra.tests.test_testing.test_invoke_optional_color(invoke)[source]#
click_extra.tests.test_testing.test_invoke_default_color(invoke)[source]#
click_extra.tests.test_testing.test_invoke_forced_color_stripping(invoke)[source]#
click_extra.tests.test_testing.test_invoke_color_keep(invoke)[source]#

On Windows Click ends up deciding it is not running in an interactive terminal and forces the stripping of all colors.

click_extra.tests.test_testing.test_invoke_color_forced(invoke)[source]#

Test colors are preserved while invoking, and forced to be rendered on Windows.

click_extra.tests.test_timer module#

Test defaults of our custom commands, as well as their customizations and attached options, and how they interact with each others.

click_extra.tests.test_timer.test_integrated_time_option(invoke, subcommand_id, time_min, time_max)[source]#
click_extra.tests.test_timer.test_integrated_notime_option(invoke, subcommand_id)[source]#
click_extra.tests.test_timer.test_standalone_timer_option(invoke, cmd_decorator, option_decorator)[source]#

click_extra.tests.test_version module#

Test the --version option.

Todo

Test standalone scripts setting package name to filename and version to None.

Todo

Test standalone script fetching version from __version__ variable.

click_extra.tests.test_version.test_standalone_version_option(invoke, cmd_decorator, option_decorator)[source]#
click_extra.tests.test_version.test_debug_output(invoke, cmd_decorator, option_decorator)[source]#
click_extra.tests.test_version.test_set_version(invoke)[source]#
click_extra.tests.test_version.test_custom_message(invoke, cmd_decorator, message, regex_stdout)[source]#
click_extra.tests.test_version.test_style_reset(invoke, cmd_decorator)[source]#
click_extra.tests.test_version.test_custom_message_style(invoke, cmd_decorator)[source]#
click_extra.tests.test_version.test_context_meta(invoke, cmd_decorator)[source]#
click_extra.tests.test_version.test_integrated_version_option_precedence(invoke, params)[source]#
click_extra.tests.test_version.test_color_option_precedence(invoke)[source]#

–no-color has an effect on –version, if placed in the right order.

Eager parameters are evaluated in the order as they were provided on the command line by the user as expleined in: https://click.palletsprojects.com/en/8.0.x/advanced/#callback-evaluation-order

Todo

Maybe have the possibility to tweak CLI callback evaluation order so we can let the user to have the NO_COLOR env set to allow for color-less --version output.