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
ConfigOptionforces on, used as the baseline in tests.
- tests.test_config.NO_DOTGLOB_FLAGS = 285440ΒΆ
FULL_SEARCH_FLAGSminusDOTGLOB, 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_TABLErows.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:
- 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.SQLITEreports itself disabled.- Return type:
- tests.test_config.test_unset_conf_debug_message(invoke, simple_config_cli, assert_output_regex)[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 whatdocs/config-discovery.mddemonstrates.
- tests.test_config.test_conf_show_file_patterns(invoke, kwargs, shows_patterns)[source]ΒΆ
show_file_patternsoverrides the display in both directions.
- 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_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(nulon 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_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
UNSETsentinel.
- 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]ΒΆ
--configannounces 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-configannounces 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_restricted_to_candidates()[source]ΒΆ
formatsnarrows the resolution, likeformat_from_pathdoes.
- tests.test_config.test_jwcc_resolves_to_the_json5_parser(tmp_path)[source]ΒΆ
A
*.jwccfile is read by theJSON5parser, 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_barfrom 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_barandFoo_Baron 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_mimeresolving onConfigFormatdeclaration 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_patternsalone.The same
application/jsondownload feeds the CLI whenJSONis accepted, and is rejected outright when the option only declaresTOML.
- 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_cli_overrides_conf(invoke, create_config)[source]ΒΆ
Command-line parameters take precedence over argfile values.
- 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
--peeledunmatched.
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-Optionis reported asunknown_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_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_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
sqlite3as a separatepyXXX-sqlite3package, and Debian servestkinteraspython3-tk. A module-level import of any of them kills every CLI built onclick_extraat 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
tryblocks, which guard against a missing module. Those are the two shapes that survive an interpreter without the module.
- 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
ConfigOptiondoes.
- tests.test_config.test_sqlite3_not_imported_by_the_package()[source]ΒΆ
Importing the package leaves
sqlite3out ofsys.modules.Covers the whole import graph, dependencies included, where
test_no_splittable_stdlib_module_imported_at_load_timeonly reads the packageβs own sources.
- tests.test_config.test_sqlite_support_gates_the_format()[source]ΒΆ
SQLITEis 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.
themesis the extension point everyConfigOptionregisters. 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.
Two CLIs sharing the same configuration file.
- 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_templateis a@cached_propertyof theConfigOptioninstance bound at decoration time, so it lives for the lifetime of the CLI object._merge_into_templatemutates its first argument in place; without a defensive copy, the cached template would accumulate values from earlier--configloads and leak them intodefault_mapon subsequent invocations.
- tests.test_config.test_lazy_group_config(invoke, create_config, tmp_path)[source]ΒΆ
Test that lazy groups work with config files.
- 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_appleandorchard_bananacommand modules onsys.path.Both modules leave
sys.modulesbefore 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.modulesis one the configuration load brought in.
- tests.test_config.test_lazy_group_included_params_introspection(invoke, create_config, orchard_modules)[source]ΒΆ
--params,--export-configand--validate-confighonor an allowlist for the subcommands its template walk skips.The walk skips
banana, soexcluded_paramslists 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 inapp_diris the most local source, one intmp_pathsits 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_filecolumn of--paramsnames 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_maplayer keeps the position of its file inCONF_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
themestable 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.
- tests.test_config.test_brace_multi_format_search(invoke, tmp_path, ext)[source]ΒΆ
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|*.yamlonly 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
--configtakes, 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/nullis a valid configuration, as--configloads 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
defaultparameter 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:
GroupA bare
click.Groupsubclass, 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
--configoption 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 ownGroup.
- tests.test_config.make_subcommand_group(group_factory, *, chain, **kwargs)[source]ΒΆ
Build a
subcmdcligroup of group_factory, carrying--config.Registers a
debugand asyncsubcommand, 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_subcommandsfires whatever group class carries--config.
- tests.test_config.test_prepend_subcommands_on_any_group_class(invoke, create_config, group_factory)[source]ΒΆ
_prepend_subcommandsfires 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
--configholds 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_helpshort-circuit: passing--configwould 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
--configalone 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.
--configis 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
--confignever reads a configuration to dispatch on.
- tests.test_config.test_group_parse_args_is_wrapped_once()[source]ΒΆ
Each new
ConfigOptionleaves the wrapper ofclick.Groupas 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_sanityemits (or suppresses) debug logs per pattern config.
- 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_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-configreject it, and lax mode skips it.
- 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
xmltodictread 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.