tests packageΒΆ
SubmodulesΒΆ
tests.conftest moduleΒΆ
Fixtures, configuration and helpers for tests.
- tests.conftest.skip_windows_colors(*args, **kwargs) = MarkDecorator(mark=Mark(name='skipif', args=(<extra_platforms.pytest.DeferredCondition object>,), kwargs={'reason': 'Click overstrip colors on Windows'}))ΒΆ
Skips color tests on Windows as
click.testing.invokeoverzealously strips colors.See: - https://github.com/pallets/click/issues/2111 - https://github.com/pallets/click/issues/2110
- class tests.conftest.FormatType(*values)[source]ΒΆ
Bases:
EnumSphinx document format types and their file extensions.
- RST = '.rst'ΒΆ
- MYST = '.md'ΒΆ
- class tests.conftest.SphinxAppWrapper(app, format_type)[source]ΒΆ
Bases:
objectWrapper around Sphinx application with additional testing methods.
- classmethod create(format_type, tmp_path, return_srcdir=False)[source]ΒΆ
Factory method to create a SphinxAppWrapper with given format.
- Return type:
Generator[SphinxAppWrapper|tuple[SphinxAppWrapper,Path],None,None]
- tests.conftest.sphinx_app_rst(tmp_path)[source]ΒΆ
Create a Sphinx application for testing RST format only.
- tests.conftest.sphinx_app_myst(tmp_path)[source]ΒΆ
Create a Sphinx application for testing MyST format only.
- tests.conftest.sphinx_app_myst_with_include(tmp_path)[source]ΒΆ
Create a Sphinx application for testing MyST format with include files.
- class tests.conftest.DirectiveTestCase(name, format_type=None, source_block=None, run_block=None, document=None, html_matches=None)[source]ΒΆ
Bases:
objectTest case data for directive tests.
-
format_type:
FormatType|None= NoneΒΆ
-
format_type:
tests.test_colorize moduleΒΆ
- tests.test_colorize.test_theme_definition()[source]ΒΆ
Ensure we do not leave any property we would have inherited from cloup and logging primitives.
- tests.test_colorize.test_option_highlight(opt, expected_outputs)[source]ΒΆ
Test highlighting of all optionβs variations.
Ensure hidden options are not highlighted.
- tests.test_colorize.test_standalone_color_option(invoke, option_decorator, param, expecting_colors, assert_output_regex)[source]ΒΆ
Check color option values, defaults and effects on all things colored, including verbosity option.
- tests.test_colorize.test_no_color_env_convention(invoke, env, env_expect_colors, param, param_expect_colors)[source]ΒΆ
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.
- tests.test_commands.all_command_cli()[source]ΒΆ
A CLI that is mixing all variations and flavors of subcommands.
- tests.test_commands.test_group_help(invoke, all_command_cli, param, exit_code, assert_output_regex)[source]ΒΆ
- tests.test_commands.test_help_eagerness(invoke, all_command_cli, params, exit_code, expect_help, expect_empty_stderr, assert_output_regex)[source]ΒΆ
See: https://click.palletsprojects.com/en/stable/advanced/#callback-evaluation-order
- tests.test_commands.test_help_custom_name(invoke)[source]ΒΆ
Removes the
-hshort option as we reserve it for a custom-h/--headeroption.See: https://github.com/kdeldycke/mail-deduplicate/issues/762
- tests.test_commands.test_subcommand_help(invoke, all_command_cli, cmd_id, param, assert_output_regex)[source]ΒΆ
- 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
- tests.test_commands.test_duplicate_option(invoke)[source]ΒΆ
See: - https://kdeldycke.github.io/click-extra/commands.html#change-default-options - https://github.com/kdeldycke/click-extra/issues/232
- tests.test_commands.test_no_option_leaks_between_subcommands(invoke, assert_output_regex)[source]ΒΆ
As reported in https://github.com/kdeldycke/click-extra/issues/489.
- tests.test_commands.test_show_envvar_parameter(invoke, cmd_decorator, ctx_settings, expected_help)[source]ΒΆ
- tests.test_commands.test_raw_args(invoke)[source]ΒΆ
Raw args are expected to be scoped in subcommands.
- tests.test_commands.test_lazy_group(invoke, tmp_path, lazy_cmd_decorator)[source]ΒΆ
Test extends the snippet from Click documentation.
tests.test_config moduleΒΆ
- tests.test_config.test_unset_conf_debug_message(invoke, simple_config_cli, assert_output_regex)[source]ΒΆ
- tests.test_config.test_standalone_no_config_option(invoke)[source]ΒΆ
@no_config_option cannot work without @config_option.
- tests.test_config.test_strict_conf(invoke, create_config)[source]ΒΆ
Same test as the one shown in the readme, but in strict validation mode.
- tests.test_config.test_conf_file_overrides_defaults(invoke, simple_config_cli, create_config, httpserver, conf_name, conf_text, conf_data, assert_output_regex)[source]ΒΆ
- tests.test_config.test_auto_envvar_conf(invoke, simple_config_cli, create_config, httpserver, conf_name, conf_text, conf_data)[source]ΒΆ
- tests.test_config.test_conf_file_overridden_by_cli_param(invoke, simple_config_cli, create_config, httpserver, conf_name, conf_text, conf_data)[source]ΒΆ
- tests.test_config.test_conf_metadata(invoke, create_config, httpserver, conf_name, conf_text, conf_data)[source]ΒΆ
Two CLIs sharing the same configuration file.
tests.test_envvar moduleΒΆ
- tests.test_envvar.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.
tests.test_logging moduleΒΆ
- tests.test_logging.test_root_logger_defaults()[source]ΒΆ
Check our internal default is aligned to Pythonβs root logger.
- tests.test_logging.test_integrated_verbosity_options(invoke, args, expected_level, assert_output_regex)[source]ΒΆ
- tests.test_logging.test_standalone_option_default_logger(invoke, cmd_decorator, option_decorator, args, expected_level, assert_output_regex)[source]ΒΆ
Checks: - option affect log level - the default logger is
root- the default logger message format - level names are colored - log level is propagated to all other loggers
- tests.test_logging.test_default_logger_param(invoke, logger_param, params)[source]ΒΆ
Passing a logger instance or name to the
default_loggerparameter works.
- tests.test_logging.test_new_extra_logger_name_passing(invoke)[source]ΒΆ
Test extra logger with custom format, passed to the option by its name.
- tests.test_logging.test_new_extra_logger_object_passing(invoke)[source]ΒΆ
Test extra logger with custom format, passed as an object to the option.
tests.test_parameters moduleΒΆ
- class tests.test_parameters.Custom[source]ΒΆ
Bases:
ParamTypeA 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
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_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_pygments moduleΒΆ
- 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.Outputtokens, 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.
- tests.test_pygments.collect_classes(klass, prefix='Ansi')[source]ΒΆ
Returns all classes defined in
click_extra.pygmentsthat are a subclass ofklass, and whose name starts with the providedprefix.
tests.test_pytest moduleΒΆ
Test the Pytest helpers.
tests.test_sphinx moduleΒΆ
Fixtures and utilities for Sphinx testing.
tests.test_sphinx_alerts moduleΒΆ
Tests for GitHub alert syntax conversion in Sphinx with MyST parser.
- tests.test_sphinx_alerts.test_all_alert_types(alert_type)[source]ΒΆ
Test all supported alert types are converted correctly.
- tests.test_sphinx_alerts.test_alert_conversion(text, expected)[source]ΒΆ
Test GitHub alerts are converted to MyST admonitions.
When expected is None, no conversion should occur.
- tests.test_sphinx_alerts.test_sphinx_integration(sphinx_app, test_case)[source]ΒΆ
Integration-critical tests that verify Sphinx rendering behavior.
tests.test_sphinx_click moduleΒΆ
Tests for Sphinx directives click:source and click:run in rST and MyST formats.
- tests.test_sphinx_click.test_directive_functionality(sphinx_app, test_case)[source]ΒΆ
Test standard directive functionalities in both rST and MyST.
- tests.test_sphinx_click.test_directive_option_format(sphinx_app_rst)[source]ΒΆ
rST will fail to render if an
:option:is not followed by an empty line.
- tests.test_sphinx_click.test_directive_option_language_override(sphinx_app)[source]ΒΆ
Test that language override works for click:run directive.
- tests.test_sphinx_click.test_sphinx_directive_state_persistence(sphinx_app)[source]ΒΆ
Test that state persists between declare and run directives in real Sphinx.
tests.test_table moduleΒΆ
- tests.test_table.test_table_formats_definition()[source]ΒΆ
Check all table formats are accounted for and properly named.
tests.test_telemetry moduleΒΆ
tests.test_testing moduleΒΆ
Test the testing utilities and the simulation of CLI execution.
- 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.
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.
tests.test_types moduleΒΆ
- tests.test_types.test_click_choice_behavior()[source]ΒΆ
Lockdown the behavior of method inherited from Clickβs Choice type.
- Return type:
- tests.test_types.test_enum_string_choices(enum_definition, choice_source, result)[source]ΒΆ
- Return type:
- tests.test_types.test_enum_choice_show_aliases(enum_definition, choice_source, show_aliases, result)[source]ΒΆ
Test that EnumChoice correctly handles Enum with aliases.
- Return type:
- class tests.test_types.MyEnum(*values)[source]ΒΆ
Bases:
EnumProduce different strings for keys/names, values and str().
- FIRST_VALUE = 'first-value'ΒΆ
- SECOND_VALUE = 'second-value'ΒΆ
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.
- tests.test_version.test_standalone_version_option(invoke, cmd_decorator, option_decorator)[source]ΒΆ
- tests.test_version.test_debug_output(invoke, cmd_decorator, option_decorator, assert_output_regex)[source]ΒΆ
- tests.test_version.test_custom_message(invoke, cmd_decorator, message, regex_stdout, assert_output_regex)[source]ΒΆ
- 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
--versionoutput.