tests.test_config moduleΒΆ

tests.test_config.DOCS_CONFIG_PAGE = PosixPath('/home/runner/work/click-extra/click-extra/docs/config-discovery.md')ΒΆ

The documentation page transcribing part of ConfigFormat.

tests.test_config.FULL_SEARCH_FLAGS = 285504ΒΆ

All search flags ConfigOption forces on, used as the baseline in tests.

tests.test_config.NO_DOTGLOB_FLAGS = 285440ΒΆ

FULL_SEARCH_FLAGS minus DOTGLOB, to exercise the dotfile warnings.

tests.test_config.SQLITE_DATA = {'config-cli1': {'default': {'int_param': 3, 'random_stuff': 'will be ignored'}, 'dummy_flag': True, 'my_list': ['pip', 'npm', 'gem']}}ΒΆ

The shared reference configuration, as SQLITE_CONFIG_TABLE rows.

Keys are dotted parameter paths, values are JSON-encoded. This mirrors TOML_DATA, minus the verbosity bump and the sections the other formats use to exercise their own quirks.

tests.test_config.flatten_sqlite_keys(data, prefix='')[source]ΒΆ

Flatten a nested mapping into dotted keys, the SQLite config layout.

Return type:

dict

tests.test_config.make_sqlite_config(path, data=None, *, create_table=True)[source]ΒΆ

Write a nested mapping into a SQLite configuration database.

Skips the calling test on a Python whose SQLite bindings are missing, the same interpreter on which ConfigFormat.SQLITE reports itself disabled.

Return type:

Path

tests.test_config.simple_config_cli()[source]ΒΆ
tests.test_config.test_unset_conf(invoke, simple_config_cli)[source]ΒΆ
tests.test_config.test_unset_conf_debug_message(invoke, simple_config_cli, assert_output_regex)[source]ΒΆ
tests.test_config.test_conf_default_path(invoke, simple_config_cli)[source]ΒΆ
tests.test_config.test_conf_chosen_formats_displayed(invoke, file_format_patterns, expected_pattern)[source]ΒΆ

A format set chosen by the developer is displayed in full.

Only an inherited set collapses to its folder, so the help screen keeps showing the effect of file_format_patterns, which is what docs/config-discovery.md demonstrates.

tests.test_config.test_conf_show_file_patterns(invoke, kwargs, shows_patterns)[source]ΒΆ

show_file_patterns overrides the display in both directions.

tests.test_config.test_conf_default_pathlib_type(invoke, create_config)[source]ΒΆ

Refs https://github.com/kdeldycke/click-extra/issues/1356

tests.test_config.test_conf_default_url_displayed_as_given(invoke, url)[source]ΒΆ

A URL default keeps the double slash after its scheme in the help screen.

tests.test_config.test_conf_not_found(invoke, simple_config_cli, conf_path)[source]ΒΆ
tests.test_config.test_conf_unparsable(invoke, simple_config_cli, create_config)[source]ΒΆ

Explicit –config pointing to a file with garbage content.

tests.test_config.test_conf_blank_source(invoke, simple_config_cli, create_config, filename, content)[source]ΒΆ

Explicit –config with nothing to read loads an empty configuration.

/dev/null (nul on Windows) is the Unix way to point a tool at no configuration. An empty file means the same, even where its format calls it invalid, like JSON, and where its parser reads the file from its path, like plist and SQLite. Every parameter then keeps its default.

tests.test_config.test_conf_parses_to_nothing(invoke, simple_config_cli, create_config, filename, content, label)[source]ΒΆ

Explicit –config parsing to nothing names its format, not a parse error.

tests.test_config.test_conf_blank_file_never_shadows_a_configuration(invoke, tmp_path, explicit)[source]ΒΆ

A blank file loses to a configuration the same pattern matches after it.

tests.test_config.test_conf_named_pipe(invoke, simple_config_cli, tmp_path)[source]ΒΆ

A named pipe is read like a file: its content is the configuration.

tests.test_config.test_no_config_option(invoke, simple_config_cli, create_config)[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, conf_text, expect_error)[source]ΒΆ

Strict mode rejects unknown params but accepts clean configs.

tests.test_config.test_kebab_case_keys(invoke, create_config)[source]ΒΆ

Kebab-case config keys reach the snake_case-named CLI parameters.

tests.test_config.test_kebab_case_spelling_collision(invoke, create_config)[source]ΒΆ

Both spellings of the same key: last one wins, a warning names both.

tests.test_config.test_strict_conf_ignores_foreign_sections(invoke, create_config)[source]ΒΆ

Other tools’ sections in a shared config file do not trip strict mode.

tests.test_config.test_command_forwards_config_strict(invoke, create_config)[source]ΒΆ

@command(config_strict=True) activates strict mode on the default option.

tests.test_config.test_command_forwards_config_cascade(cascade)[source]ΒΆ

@command(config_cascade=…) sets the cascade of the default option.

tests.test_config.test_command_excluded_params_additive(invoke, create_config)[source]ΒΆ

@command(excluded_params=…) extends the default blocklist.

The forwarded exclusion applies on top of the built-in ones, and a blocked parameter found in a config file is reported as blocked, not unknown.

tests.test_config.test_export_config_includes_unset_params(invoke)[source]ΒΆ

Parameters without a default are exported instead of silently dropped.

TOML has no null type so unset parameters are commented out; multi-value parameters read as empty lists; JSON renders unset parameters as null.

tests.test_config.test_export_config_includes_unset_params_of_a_plain_click_command(invoke)[source]ΒΆ

A plain Click command exports a parameter without a default as null too.

Such a command does not capture its raw arguments, so the export reads each parameter’s default instead, which Click leaves as its UNSET sentinel.

tests.test_config.test_serialize_toml_with_unset_layout(tree, expected)[source]ΒΆ

A commented-out key sits under the header of its own table.

A table with no key of its own keeps its header, else its commented-out keys read as keys of the table above.

tests.test_config.test_export_config_reads_a_repeatable_flag_as_a_toggle(invoke)[source]ΒΆ

A repeatable boolean flag exports as the boolean a configuration spells.

It collects occurrences of a toggle rather than values, so dumping an unset one as the empty list of a multi-value parameter advertises a shape no user writes. A repeatable option taking values still reads as a list.

tests.test_config.test_export_config_skips_an_opaque_subtree(invoke)[source]ΒΆ

A subcommand sharing a name with an opaque schema field is not exported.

The loader hands the whole sub-tree to the app’s own validator, so the subcommand’s options cannot be read back from there. Exporting them writes a file the same loader refuses.

tests.test_config.test_export_config_kebab_case_keys(invoke, tmp_path)[source]ΒΆ

Exported keys use the kebab-case spelling, the canonical form for files.

Either spelling loads back to the same parameter, so the kebab-cased export still round-trips through –config.

tests.test_config.test_introspection_flags_load_config_first(invoke, create_config)[source]ΒΆ

–params and –export-config reflect the config file regardless of the order in which Click processes the eager options.

Click processes eager parameters given on the command line ahead of eager parameters left at their defaults, so these flags used to render before the configuration file was discovered and loaded.

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_config_status_line_follows_verbosity(invoke, create_config, before, after, shown)[source]ΒΆ

--config announces the file it loads, unless the command line asks for less than the default verbosity, whatever the position of the verbosity flags.

tests.test_config.test_no_config_status_line_follows_verbosity(invoke, args, shown)[source]ΒΆ

--no-config announces it skips loading, unless asked for quiet output.

tests.test_config.test_conf_metadata(invoke, create_config, httpserver, conf_name, conf_text, conf_data)[source]ΒΆ
tests.test_config.test_conf_metadata_no_config(invoke)[source]ΒΆ

ctx.meta entries are not set when –no-config skips loading.

tests.test_config.test_format_from_mime(media_type, expected)[source]ΒΆ
tests.test_config.test_format_from_mime_restricted_to_candidates()[source]ΒΆ

formats narrows the resolution, like format_from_path does.

tests.test_config.test_jwcc_resolves_to_the_json5_parser(tmp_path)[source]ΒΆ

A *.jwcc file is read by the JSON5 parser, which is a superset of it.

tests.test_config.test_jwcc_conf(invoke, simple_config_cli, tmp_path)[source]ΒΆ

A JWCC document loads: JSON plus comments and trailing commas.

tests.test_config.test_conf_key_reaches_a_case_preserving_param_name(invoke, create_config)[source]ΒΆ

A parameter whose name kept its case is still addressed by that case.

Click takes an identifier declaration verbatim, so this parameter is named Explicit_Name. No fold produces that spelling, so the template has to stay the authority on it.

tests.test_config.test_conf_key_case_folds_onto_the_param_name(invoke, create_config, spelling)[source]ΒΆ

Every spelling Click could have derived foo_bar from reaches it.

tests.test_config.test_conf_key_folding_onto_two_params_is_skipped(invoke, create_config, caplog)[source]ΒΆ

A key folding onto two parameter names picks neither, and warns.

Click allows foo_bar and Foo_Bar on one command, and nothing in the folded spelling says which was meant.

tests.test_config.test_strict_conf_accepts_a_folded_key(invoke, create_config)[source]ΒΆ

Strict mode no longer rejects a spelling the fold resolves.

tests.test_config.test_mime_types_are_unambiguous()[source]ΒΆ

No media type is claimed by two formats.

A duplicate would leave format_from_mime resolving on ConfigFormat declaration order alone, silently handing the media type to whichever format happens to be declared first.

tests.test_config.test_docs_media_types_table_matches_formats()[source]ΒΆ

The media-type table in the docs is ConfigFormat.mime_types, transcribed.

A format gaining or losing a media type otherwise leaves the table stale, and that table is the only place a user reads the mapping from.

tests.test_config.test_remote_conf_typed_by_content_type(invoke, simple_config_cli, httpserver, media_type, conf_text)[source]ΒΆ

An extension-less URL is typed by the media type its server advertises.

tests.test_config.test_remote_conf_falls_back_to_the_url_name(invoke, simple_config_cli, httpserver, media_type)[source]ΒΆ

A generic or plain wrong media type still leaves the URL name to match on.

tests.test_config.test_remote_conf_content_type_never_widens_the_format_set(invoke, httpserver, file_format_patterns, exit_code, stdout)[source]ΒΆ

A media type is resolved against file_format_patterns alone.

The same application/json download feeds the CLI when JSON is accepted, and is rejected outright when the option only declares TOML.

tests.test_config.test_unparsable_conf_message_enumerates_formats(invoke, create_config, caplog, file_format_patterns, expected)[source]ΒΆ

The β€œerror parsing” message never dangles its conjunction.

tests.test_config.test_ini_subcommand_section_is_typed(invoke, create_config)[source]ΒΆ

An INI section addressing a subcommand reads its values as the options’ types.

A list is JSON-encoded in the file, like in the root section.

tests.test_config.test_argfile_conf_file_overrides_defaults(invoke, simple_config_cli, create_config, assert_output_regex)[source]ΒΆ

An argfile feeds CLI tokens into the same default_map pipeline.

tests.test_config.test_argfile_conf_metadata(invoke, create_config)[source]ΒΆ
tests.test_config.test_argfile_cli_overrides_conf(invoke, create_config)[source]ΒΆ

Command-line parameters take precedence over argfile values.

tests.test_config.test_argfile_secondary_flag_and_inline_value(invoke, create_config)[source]ΒΆ
tests.test_config.test_argfile_switches_sharing_a_destination(invoke, create_config, preparation)[source]ΒΆ

Each feature switch of one destination is read from an argfile.

The two options share a name, so the parameter structure lists both under one leaf. Keeping only the last one there leaves --peeled unmatched.

tests.test_config.test_ini_name_shared_by_two_types_rejected(invoke, create_config)[source]ΒΆ

An INI item a name of two option types addresses is refused, not guessed.

tests.test_config.test_argfile_strict_conf(invoke, create_config, conf_text, expected_key)[source]ΒΆ

Strict mode rejects unknown options with the standard error.

An unmatched declaration is named the way Click names a parameter it derives from one, case fold included, so --Unknown-Option is reported as unknown_option.

tests.test_config.test_argfile_unknown_option_ignored_when_not_strict(invoke, create_config)[source]ΒΆ
tests.test_config.test_argfile_unparsable_conf(invoke, create_config, conf_text, message)[source]ΒΆ

An argfile that produces no option is rejected, saying how it was read.

tests.test_config.test_argfile_positional_tokens_skipped(invoke, create_config)[source]ΒΆ
tests.test_config.test_argfile_export_config_rejected(invoke)[source]ΒΆ

Argfile has no serializer, so –export-config rejects it.

tests.test_config.test_sqlite_conf_file_overrides_defaults(invoke, simple_config_cli, tmp_path, ext)[source]ΒΆ
tests.test_config.test_sqlite_conf_metadata(invoke, tmp_path)[source]ΒΆ
tests.test_config.test_sqlite_read_and_parse_conf(tmp_path)[source]ΒΆ

The default format patterns discover SQLite databases by extension.

tests.test_config.test_sqlite_conf_unparsable(invoke, simple_config_cli, tmp_path, make_db, message)[source]ΒΆ

A SQLite file that cannot yield a configuration is rejected.

tests.test_config.SPLITTABLE_STDLIB_MODULES = frozenset({'curses', 'dbm', 'readline', 'sqlite3', 'tkinter'})ΒΆ

Standard library modules a distribution can ship apart from its base Python.

Each wraps a system library, so a packager can leave it out of the interpreter: FreeBSD serves sqlite3 as a separate pyXXX-sqlite3 package, and Debian serves tkinter as python3-tk. A module-level import of any of them kills every CLI built on click_extra at import time, on an interpreter that is otherwise complete, so each one is probed and imported at its point of use.

tests.test_config.eager_imports(tree)[source]ΒΆ

Top-level packages a module imports as soon as it is loaded.

Skips function bodies, which import at call time, and try blocks, which guard against a missing module. Those are the two shapes that survive an interpreter without the module.

Return type:

set[str]

tests.test_config.test_no_splittable_stdlib_module_imported_at_load_time()[source]ΒΆ

No module of the package imports a splittable module unconditionally.

tests.test_config.test_parser_probes_stay_off_the_import()[source]ΒΆ

Importing the package probes no parser: building a ConfigOption does.

tests.test_config.test_sqlite3_not_imported_by_the_package()[source]ΒΆ

Importing the package leaves sqlite3 out of sys.modules.

Covers the whole import graph, dependencies included, where test_no_splittable_stdlib_module_imported_at_load_time only reads the package’s own sources.

tests.test_config.test_sqlite_support_gates_the_format()[source]ΒΆ

SQLITE is enabled exactly when the standard library ships its bindings.

tests.test_config.test_plist_conf_file_overrides_defaults(invoke, simple_config_cli, assert_output_regex, tmp_path, plist_variant)[source]ΒΆ

Both the XML and the binary plist variants load through –config.

tests.test_config.test_plist_read_and_parse_conf(tmp_path)[source]ΒΆ

The default format patterns discover plist files by extension.

tests.test_config.test_validate_config_sqlite_valid(invoke, tmp_path)[source]ΒΆ

–validate-config accepts a valid SQLite configuration database.

tests.test_config.test_default_map_populated(invoke, create_config)[source]ΒΆ

Verify default_map structure when config values match CLI parameters.

Complements test_conf_metadata which only checks the empty default_map case (where no config values match the CLI’s parameter structure).

tests.test_config.test_merge_default_map_standalone(invoke)[source]ΒΆ

merge_default_map filters a config into default_map on its own.

load_conf bypasses this method by installing the merged config the validation pipeline already produced, so it is exercised here directly to cover the standalone entry point external callers rely on.

tests.test_config.test_merge_default_map_keeps_dotted_keys_in_opaque_subtree(invoke, caplog)[source]ΒΆ

merge_default_map leaves a dotted key inside an opaque sub-tree whole.

themes is the extension point every ConfigOption registers. A theme name that ends in a dot is data, so the merge logs no empty-segment warning.

tests.test_config.test_default_map_none_without_config(invoke)[source]ΒΆ

Verify default_map is left alone when –no-config is used.

tests.test_config.test_nested_subcommand_config(invoke, create_config)[source]ΒΆ

Config propagates through group -> subgroup -> leaf command.

tests.test_config.test_multiple_cli_shared_conf(invoke, create_config)[source]ΒΆ

Two CLIs sharing the same configuration file.

Refs: https://github.com/kdeldycke/click-extra/issues/1277

tests.test_config.test_params_template_not_mutated_across_invocations(invoke, create_config)[source]ΒΆ

Back-to-back invocations of the same CLI must not cross-contaminate via ConfigOption.params_template.

params_template is a @cached_property of the ConfigOption instance bound at decoration time, so it lives for the lifetime of the CLI object. _merge_into_template mutates its first argument in place; without a defensive copy, the cached template would accumulate values from earlier --config loads and leak them into default_map on subsequent invocations.

tests.test_config.test_lazy_group_config(invoke, create_config, tmp_path)[source]ΒΆ

Test that lazy groups work with config files.

Refs: https://github.com/kdeldycke/click-extra/issues/1332

tests.test_config.test_lazy_group_config_no_config_flag(invoke, create_config, tmp_path)[source]ΒΆ

Test that –no-config works with lazy groups.

tests.test_config.orchard_modules(tmp_path)[source]ΒΆ

Put the orchard_apple and orchard_banana command modules on sys.path.

Both modules leave sys.modules before and after the test, so the test sees which of them its CLI imports.

tests.test_config.test_lazy_group_included_params_imports(invoke, create_config, orchard_modules, included_params, expected_stdout)[source]ΒΆ

A configuration loads without importing the lazy subcommands the allowlist leaves out.

The walk building the parameter template skips each subcommand no allowed ID lies under. The section of a subcommand the allowlist leaves out does not reach it either, when the invocation imports it later.

tests.test_config.test_lazy_group_empty_allowlist_imports_no_subcommand(invoke, create_config, orchard_modules)[source]ΒΆ

included_params=() loads a configuration without importing any lazy subcommand.

The group runs on its own, so no dispatch imports a subcommand behind the walk’s back: a module in sys.modules is one the configuration load brought in.

tests.test_config.test_lazy_group_included_params_introspection(invoke, create_config, orchard_modules)[source]ΒΆ

--params, --export-config and --validate-config honor an allowlist for the subcommands its template walk skips.

The walk skips banana, so excluded_params lists none of its parameters.

tests.test_config.test_file_pattern(file_format_patterns, expected_pattern)[source]ΒΆ

Test the file_pattern property with different file format configurations.

tests.test_config.test_default_pattern_roaming_force_posix(roaming, force_posix, current_platform, expected_path, monkeypatch)[source]ΒΆ

Test that roaming and force_posix affect the default pattern generation.

tests.test_config.test_default_pattern_xdg_config_home(force_posix, tmp_path, monkeypatch)[source]ΒΆ

Test that default_pattern respects XDG_CONFIG_HOME on Linux.

tests.test_config.cascade_tree(tmp_path, monkeypatch)[source]ΒΆ

Point auto-discovery at a temporary app dir nested inside tmp_path.

Returns (tmp_path, app_dir): a config file dropped in app_dir is the most local source, one in tmp_path sits one level up the parent walk.

tests.test_config.test_cascade_merges_files_local_wins(invoke, cascade_tree)[source]ΒΆ

With cascade=True, local values win and parent values fill the gaps.

tests.test_config.test_cascade_list_local_wins(invoke, cascade_tree)[source]ΒΆ

A list two layers both set resolves to the most local one, like any value.

tests.test_config.test_cascade_merges_subcommand_sections(invoke, cascade_tree)[source]ΒΆ

A section two files both define resolves key by key, at every depth.

The local file wins each key it sets, and the keys only the parent file sets in the same section still apply. A list comes whole from the local file.

tests.test_config.test_no_cascade_first_file_wins(invoke, cascade_tree)[source]ΒΆ

Without cascade, the first parseable file wins entirely.

tests.test_config.test_cascade_single_layer_from_parent(invoke, cascade_tree)[source]ΒΆ

A lone file found up the walk is applied as-is.

tests.test_config.test_cascade_explicit_config_does_not_cascade(invoke, cascade_tree)[source]ΒΆ

An explicit –config pins a single source, even with cascade=True.

tests.test_config.test_cascade_conf_sources_metadata(invoke, cascade_tree)[source]ΒΆ

ctx.meta[CONF_SOURCES] lists every loaded file, highest precedence first.

tests.test_config.test_cascade_params_names_the_file_of_each_key(invoke, tmp_path, monkeypatch)[source]ΒΆ

The config_file column of --params names the file each value comes from.

With three files, the file furthest up the walk is named for the key only it sets: each default_map layer keeps the position of its file in CONF_SOURCES.

tests.test_config.test_cascade_conf_full_is_merged_view(invoke, cascade_tree)[source]ΒΆ

ctx.meta[CONF_FULL] exposes the deep-merged document.

tests.test_config.test_cascade_validation_error_names_file(invoke, cascade_tree, caplog)[source]ΒΆ

A strict-check failure in one layer names that file and exits 1.

tests.test_config.test_cascade_strict_check_skips_extension_points(invoke, cascade_tree)[source]ΒΆ

Each file of a cascade passes the strict check with an extension point in it.

The built-in themes table is one: its keys name themes, not parameters.

tests.test_config.test_read_and_parse_all_conf_orders_local_first(tmp_path)[source]ΒΆ

All parseable files are yielded, deepest first; unparsable ones skip.

tests.test_config.test_read_and_parse_conf_returns_first(tmp_path)[source]ΒΆ

read_and_parse_conf keeps its first-match contract on top of the generator.

tests.test_config.test_sentinel_duplication_preserves_identity(sentinel, duplicate)[source]ΒΆ

Copying or pickling a sentinel hands back the member itself.

A bare object() value cannot survive pickling by value: it unpickles as a new object, which matches no member.

tests.test_config.test_config_option_default_no_config(invoke, create_config)[source]ΒΆ

ConfigOption with default=NO_CONFIG disables autodiscovery.

tests.test_config.test_no_config_explicit_with_default_no_config(invoke)[source]ΒΆ

–no-config still prints the skip message even when NO_CONFIG is the default.

tests.test_config.test_excluded_params(invoke, create_config)[source]ΒΆ

Custom excluded_params prevents config values from being applied.

tests.test_config.test_included_params(invoke, create_config)[source]ΒΆ

Only parameters in included_params are loaded from config.

tests.test_config.test_included_params_empty(invoke, create_config)[source]ΒΆ

An empty included_params excludes all params from config.

tests.test_config.test_included_and_excluded_params_conflict()[source]ΒΆ

Providing both included_params and excluded_params raises ValueError.

tests.test_config.test_multiple_files_matching_glob(invoke, create_config, tmp_path)[source]ΒΆ

When multiple files match a glob, only the first parseable one is used.

tests.test_config.test_forced_flags_warnings(caplog)[source]ΒΆ

Warnings fire when SPLIT, BRACE or NODIR flags are missing.

The flags resolve on first use, not at construction, so reading them is what fires the warnings.

All format extensions are found in the search directory.

Regression test: before BRACE expansion, only the first format in the default pattern got the directory prefix: others were searched in CWD.

tests.test_config.test_root_dir_parent_search_finds_non_toml(invoke, tmp_path)[source]ΒΆ

Parent search with root_dir correctly finds non-TOML config in parents.

Before the root_dir refactoring, SPLIT patterns like *.toml|*.yaml only applied the directory prefix to the first sub-pattern. Now with root_dir, all sub-patterns are scoped to the correct directory.

tests.test_config.test_no_enabled_formats_raises()[source]ΒΆ

ValueError raised when all formats are disabled.

tests.test_config.test_pyproject_toml_in_defaults()[source]ΒΆ

ConfigOption() with default file_format_patterns includes PYPROJECT_TOML.

tests.test_config.test_pyproject_toml_tool_extraction(simple_config_cli)[source]ΒΆ

parse_conf with PYPROJECT_TOML returns the [tool] subsection.

tests.test_config.test_pyproject_toml_no_tool_section(simple_config_cli)[source]ΒΆ

pyproject.toml without [tool] returns empty dict.

tests.test_config.test_file_pattern_with_pyproject_toml()[source]ΒΆ

Explicit file_format_patterns with PYPROJECT_TOML works.

tests.test_config.test_pyproject_toml_overrides_defaults(invoke, create_config)[source]ΒΆ

End-to-end: a CLI with default formats reads from pyproject.toml.

tests.test_config.test_validate_config_valid(invoke, create_config)[source]ΒΆ

–validate-config with a valid config file exits 0.

tests.test_config.test_validate_config_accepts_a_glob(invoke, create_config)[source]ΒΆ

–validate-config takes every location --config takes, glob included.

tests.test_config.test_validate_config_accepts_a_url(invoke, httpserver)[source]ΒΆ

A configuration a CLI can load from a URL is one it can also validate.

tests.test_config.test_validate_config_accepts_the_null_device(invoke)[source]ΒΆ

/dev/null is a valid configuration, as --config loads it.

tests.test_config.test_validate_config_invalid_keys(invoke, create_config)[source]ΒΆ

–validate-config with unrecognized keys exits 1.

tests.test_config.test_extensionless_config(invoke, create_config, default_pattern, expected_help_default)[source]ΒΆ

Both broad and exact default patterns resolve the same .commandrc file.

The default parameter is printed as-is on the help screen, so an exact path is more informative than a broad glob, but both locate the same file.

tests.test_config.test_validate_config_unparsable(invoke, create_config)[source]ΒΆ

–validate-config with garbage content exits 2.

tests.test_config.test_validate_config_parses_to_nothing(invoke, create_config)[source]ΒΆ

–validate-config names the format a file parses to nothing with.

tests.test_config.test_validate_config_missing_file(invoke, tmp_path)[source]ΒΆ

–validate-config reports a nonexistent location from its own callback.

tests.test_config.test_validate_config_requires_config_option(invoke, tmp_path)[source]ΒΆ

–validate-config without @config_option raises RuntimeError.

tests.test_config.test_validate_config_pyproject_toml(invoke, create_config)[source]ΒΆ

–validate-config works with pyproject.toml [tool.*] sections.

tests.test_config.test_export_config_to_stdout(invoke)[source]ΒΆ

–export-config writes the resolved configuration and exits 0.

tests.test_config.test_export_config_captures_overrides(invoke)[source]ΒΆ

Command-line values are reflected in the dump.

tests.test_config.test_export_config_captures_environment(invoke)[source]ΒΆ

Values resolved from environment variables are reflected in the dump.

tests.test_config.test_export_config_numeric_values_keep_their_type(invoke)[source]ΒΆ

A command-line numeric scalar is dumped as a number, not a quoted string.

tests.test_config.test_export_config_round_trip(invoke, tmp_path, fmt)[source]ΒΆ

A dumped configuration reloads to the same values through –config.

tests.test_config.test_export_config_invalid_format(invoke)[source]ΒΆ

An unsupported format token is rejected by the Choice.

tests.test_config.test_export_config_without_its_writer(invoke, monkeypatch)[source]ΒΆ

A format whose writer is not installed fails with the install command.

tests.test_config.test_export_config_requires_config_option(invoke)[source]ΒΆ

–export-config without @config_option raises RuntimeError.

tests.test_config.test_export_config_standalone_falls_back_to_defaults(invoke)[source]ΒΆ

Without a captured command line (vanilla Command), defaults are dumped.

class tests.test_config.PlainGroupSubclass(name=None, commands=None, invoke_without_command=False, no_args_is_help=None, subcommand_metavar=None, chain=False, result_callback=None, **kwargs)[source]ΒΆ

Bases: Group

A bare click.Group subclass, like third-party plugin frameworks produce.

tests.test_config.SUBCOMMAND_GROUP_FACTORIES = (((<function group>,), (), 'click-group'), ((<function group>,), (), 'cloup-group'), ((<function decorator_factory.<locals>.decorator>,), (), 'click-extra-group'), ((functools.partial(<function group>, cls=<class 'tests.test_config.PlainGroupSubclass'>),), (), 'click-group-subclass'))ΒΆ

Every group flavor a --config option can be attached to.

The reserved subcommand keys are declared by config_option, so they must be honored by whichever group class carries that option, not only by click-extra’s own Group.

tests.test_config.make_subcommand_group(group_factory, *, chain, **kwargs)[source]ΒΆ

Build a subcmdcli group of group_factory, carrying --config.

Registers a debug and a sync subcommand, each echoing its own name. click-extra groups already ship --config, so the option is only added to the other flavors. Extra keyword arguments go to group_factory.

tests.test_config.test_default_subcommands_on_any_group_class(invoke, create_config, group_factory)[source]ΒΆ

_default_subcommands fires whatever group class carries --config.

tests.test_config.test_prepend_subcommands_on_any_group_class(invoke, create_config, group_factory)[source]ΒΆ

_prepend_subcommands fires whatever group class carries --config.

tests.test_config.SUBGROUP_CLASSES = (((<class 'click.core.Group'>,), (), 'click-subgroup'), ((<class 'cloup._commands.Group'>,), (), 'cloup-subgroup'), ((<class 'click_extra.commands.Group'>,), (), 'click-extra-subgroup'), ((<class 'tests.test_config.PlainGroupSubclass'>,), (), 'click-subgroup-subclass'))ΒΆ

Every group class a subgroup can be built on.

A subgroup reached through an ancestor’s --config holds no option of its own, so its class is all that could keep it from reading its own section.

tests.test_config.test_subcommands_on_a_subgroup(invoke, create_config, group_factory, subgroup_class, reserved_key, cli_args)[source]ΒΆ

A subgroup applies the reserved keys of its own configuration section.

Only the root group carries --config, so a subgroup is never visited as that option is processed. It reads [parent.subgroup] all the same, whatever classes the root and the subgroup are built on.

tests.test_config.app_dir_conf(tmp_path, monkeypatch)[source]ΒΆ

Point auto-discovery at a temporary app dir, and write a config into it.

Lets a test invoke a CLI with no argument at all, which is the only way to reach Click’s no_args_is_help short-circuit: passing --config would make the invocation non-empty.

tests.test_config.test_subcommands_beat_no_args_is_help(invoke, app_dir_conf, group_factory, reserved_key, chain)[source]ΒΆ

A configured subcommand outranks Click’s no-args help screen.

Click raises that screen before it runs any parameter, so --config alone never sees a bare invocation, whatever group class carries it.

tests.test_config.test_no_args_is_help_survives_a_silent_config(invoke, app_dir_conf, group_factory)[source]ΒΆ

The help screen stays when the configuration names no subcommand.

tests.test_config.test_bare_invocation_loads_the_configuration_once(invoke, create_config, group_factory)[source]ΒΆ

A bare invocation running a configured subcommand reads its document once.

--config is processed ahead of the no-args help screen, then again by Click’s parameter loop. A location set on purpose, here through the environment, makes each load print its status line.

tests.test_config.test_no_args_is_help_stays_without_a_config_option(invoke, app_dir_conf)[source]ΒΆ

A group carrying no --config never reads a configuration to dispatch on.

tests.test_config.test_group_parse_args_is_wrapped_once()[source]ΒΆ

Each new ConfigOption leaves the wrapper of click.Group as it found it.

tests.test_config.test_default_subcommand_selection(invoke, create_config, cli_subcmd, expected, unexpected)[source]ΒΆ

Config default is used when no subcommand given; CLI wins otherwise.

tests.test_config.test_default_subcommand_chained(invoke, create_config)[source]ΒΆ

chain=True group runs multiple config-listed subcommands in order.

tests.test_config.test_default_subcommand_config_errors(invoke, create_config, conf_value, error_fragment)[source]ΒΆ

Bad _default_subcommands values produce clear errors.

tests.test_config.test_default_subcommand_strict_mode_tolerance(invoke, create_config)[source]ΒΆ

strict=True config with _default_subcommands doesn’t raise.

tests.test_config.test_default_subcommand_validate_config_tolerance(invoke, create_config)[source]ΒΆ

–validate-config with _default_subcommands reports valid.

tests.test_config.test_default_subcommand_with_options(invoke, create_config)[source]ΒΆ

Default subcommand receives its config-provided options.

tests.test_config.test_default_subcommand_no_config(invoke)[source]ΒΆ

Normal behavior when no config file is loaded.

tests.test_config.test_default_subcommand_duplicates_warning(invoke, create_config)[source]ΒΆ

Duplicate entries in _default_subcommands are deduplicated with a warning.

tests.test_config.test_default_subcommand_cli_override_debug_log(invoke, create_config)[source]ΒΆ

Debug log emitted when CLI subcommands override config defaults.

tests.test_config.test_prepend_subcommand_selection(invoke, create_config, cli_subcmd, expected, unexpected)[source]ΒΆ

Prepend fires regardless of whether a CLI subcommand is given.

tests.test_config.test_prepend_subcommand_with_defaults(invoke, create_config, cli_subcmd, expect_backup)[source]ΒΆ

Prepend always applies; defaults only fire when no CLI subcommand given.

tests.test_config.test_prepend_subcommand_non_chained_error(invoke, create_config)[source]ΒΆ

Error on non-chained group.

tests.test_config.test_prepend_subcommand_config_errors(invoke, create_config, conf_value, error_fragment)[source]ΒΆ

Bad _prepend_subcommands values produce clear errors.

tests.test_config.test_prepend_subcommand_strict_mode_tolerance(invoke, create_config)[source]ΒΆ

strict=True config with _prepend_subcommands doesn’t raise.

tests.test_config.test_prepend_subcommand_validate_config_tolerance(invoke, create_config)[source]ΒΆ

–validate-config with _prepend_subcommands reports valid.

tests.test_config.test_prepend_subcommand_duplicates_warning(invoke, create_config)[source]ΒΆ

Duplicate entries in _prepend_subcommands are deduplicated with a warning.

tests.test_config.test_prepend_subcommand_info_log(invoke, create_config)[source]ΒΆ

INFO log emitted when _prepend_subcommands are injected.

tests.test_config.test_prepend_subcommand_multiple(invoke, create_config)[source]ΒΆ

Multiple prepend subcommands run in order.

tests.test_config.test_sanity_checks(caplog, default, file_format_patterns, flags, present, absent)[source]ΒΆ

_check_pattern_sanity emits (or suppresses) debug logs per pattern config.

tests.test_config.test_expand_dotted_keys(input_conf, expected)[source]ΒΆ
tests.test_config.test_dotted_keys_in_config(invoke, simple_config_cli, create_config, conf_name, conf_text)[source]ΒΆ

Dotted keys in config files are expanded into nested structures.

tests.test_config.test_expand_dotted_keys_conflict_warning(caplog, input_conf, warning_fragment)[source]ΒΆ

Scalar/dict conflicts on the same key emit a warning.

tests.test_config.test_expand_dotted_keys_empty_segments(caplog, input_conf)[source]ΒΆ

Dotted keys with empty segments are skipped with a warning.

tests.test_config.test_expand_dotted_keys_edge_cases(input_conf, expected)[source]ΒΆ
tests.test_config.test_expand_dotted_keys_strict_conflict(input_conf, error_fragment)[source]ΒΆ

Strict mode raises ValueError on type conflicts.

tests.test_config.test_expand_dotted_keys_strict_empty_segments(input_conf)[source]ΒΆ

Strict mode raises ValueError on dotted keys with empty segments.

tests.test_config.test_strict_conf_dotted_key_conflict(invoke, create_config, flag)[source]ΒΆ

Strict mode rejects a dotted-key type conflict with a validation error.

The error is reported like an unknown key, not raised as a traceback.

tests.test_config.test_expand_dotted_keys_keeps_a_key_that_is_not_a_string()[source]ΒΆ

YAML reads 1: as a number: such a key holds no dot to expand.

tests.test_config.test_conf_key_that_is_not_a_string(invoke, create_config, strict, flag, exit_code, message)[source]ΒΆ

A YAML key that reads as a number is a configuration error, not a traceback.

Strict mode and --validate-config reject it, and lax mode skips it.

tests.test_config.test_parse_jsonc(content, expected)[source]ΒΆ
tests.test_config.test_parse_jsonc_reports_the_line_of_an_error()[source]ΒΆ

A blanked block comment keeps its newlines, so the line numbers hold.

tests.test_config.test_parse_xml_conventions()[source]ΒΆ

Attributes, text, repeated tags and empty elements read as xmltodict read them.

tests.test_config.test_xml_single_element_reads_as_one_item_list(invoke, simple_config_cli, create_config, elements, my_list)[source]ΒΆ

A lone element naming a multi-value option reads as a one-item list.

XML has no other way to spell a list of one. An element naming a single-value parameter keeps its text.

tests.test_config.test_parse_xml_rejects_a_malformed_document()[source]ΒΆ
tests.test_config.test_serialize_xml_conventions()[source]ΒΆ
tests.test_config.test_xml_round_trip()[source]ΒΆ
tests.test_config.test_serialize_xml_respells_invalid_names()[source]ΒΆ

A key XML does not accept as a name is respelled, and reads back so.

A name starting with a digit gets a leading underscore, and a space becomes an underscore, in an element as in an attribute. A namespace prefix stays.