tests.test_context moduleΒΆ

Tests for click_extra.context, and the context class that carries it.

Covers four surfaces:

tests.test_context.KEY_CONSTANTS: tuple[tuple[str, str], ...] = (('RAW_ARGS', 'click_extra.raw_args'), ('INVOCATION_NAME', 'click_extra.invocation_name'), ('CONF_SOURCE', 'click_extra.conf_source'), ('CONF_FULL', 'click_extra.conf_full'), ('CONF_SOURCES', 'click_extra.conf_sources'), ('TOOL_CONFIG', 'click_extra.tool_config'), ('SUBCOMMANDS_APPLIED', 'click_extra.subcommands_applied'), ('VERBOSITY_LEVEL', 'click_extra.verbosity_level'), ('VERBOSITY', 'click_extra.verbosity'), ('DEBUG', 'click_extra.debug'), ('VERBOSE', 'click_extra.verbose'), ('QUIET', 'click_extra.quiet'), ('START_TIME', 'click_extra.start_time'), ('JOBS', 'click_extra.jobs'), ('TABLE_FORMAT', 'click_extra.table_format'), ('SORT_BY', 'click_extra.sort_by'), ('TABLE_SORT_KEY', 'click_extra.table_sort_key'), ('COLUMNS', 'click_extra.columns'), ('THEME', 'click_extra.theme.active'), ('THEME_OVERRIDES', 'click_extra.theme.overrides'), ('TELEMETRY', 'click_extra.telemetry'), ('PROGRESS', 'click_extra.progress'), ('ACCESSIBLE', 'click_extra.accessible'), ('ZERO_EXIT', 'click_extra.zero_exit'))ΒΆ

Pairs of (attribute name, raw string key) for every registered ctx.meta entry. Single source of truth used by every parametrized registry test below.

tests.test_context.test_key_constant_value(attr, expected)[source]ΒΆ

Each registered constant binds to its documented string value.

Pins the spelling of every key so a rename of the literal does not silently break downstream code that reads ctx.meta["click_extra.X"].

Return type:

None

tests.test_context.test_key_uses_namespace_prefix(key)[source]ΒΆ

Every registered key sits under META_NAMESPACE.

Return type:

None

tests.test_context.test_keys_are_unique()[source]ΒΆ

No two registry constants share a string value.

Return type:

None

tests.test_context.test_registry_covers_all_module_constants()[source]ΒΆ

KEY_CONSTANTS lists every public namespace-prefixed constant.

Drift detector: when a new ctx.meta key is added to click_extra.context but not to KEY_CONSTANTS, this test fails so the maintainer remembers to update both sides.

Return type:

None

tests.test_context.NON_META_KEYS = frozenset({'click_extra.config_docstring_heading', 'click_extra.config_path', 'click_extra.extension', 'click_extra.normalize_keys', 'click_extra.tabs_vertical', 'click_extra.todo_unrendered'})ΒΆ

Literals sharing META_NAMESPACE that name no ctx.meta key.

tests.test_context.test_meta_keys_are_spelled_in_context_only()[source]ΒΆ

No module but click_extra.context spells a ctx.meta key.

Every other module reads its keys from there: none builds one from META_NAMESPACE, or writes one as a literal.

Return type:

None

tests.test_context.test_internal_keys_are_private_and_unique()[source]ΒΆ

The keys only Click Extra reads sit under click_extra._, apart from the public ones.

Return type:

None

tests.test_context.test_get_returns_default_for_missing_key()[source]ΒΆ

get() mirrors dict.get semantics.

Return type:

None

tests.test_context.test_set_then_get_round_trip()[source]ΒΆ

set() is observable through get().

Return type:

None

tests.test_context.test_setdefault_stores_the_factory_value_once()[source]ΒΆ

setdefault() creates a missing value, then keeps it.

Return type:

None

tests.test_context.test_context_uses_help_formatter()[source]ΒΆ

Context installs Click Extra’s colorized formatter.

Return type:

None

tests.test_context.test_context_meta_kwarg_seeds_ctx_meta()[source]ΒΆ

The meta= kwarg populates ctx.meta at construction time.

Return type:

None

tests.test_context.test_context_meta_kwarg_omitted_leaves_meta_empty()[source]ΒΆ

Without meta=, ctx.meta is an empty dict, not None.

Return type:

None

tests.test_context.test_context_color(monkeypatch, parent_color, child_color, expected)[source]ΒΆ

Context color resolution covers every parent/child path.

Root contexts without an explicit color= resolve the GNU auto default: with no color environment variable they stay at None (TTY detection). Child contexts inherit the parent’s color unless they override it explicitly.

Return type:

None

tests.test_context.test_context_posixly_correct(monkeypatch, env_present, expected)[source]ΒΆ

POSIXLY_CORRECT flips allow_interspersed_args off when present.

A plain click.Command defaults the flag to True, so the unset case leaves interspersing enabled and the set case disables it.

Return type:

None

tests.test_context.test_posixly_correct_presence_overrides_explicit_true(monkeypatch)[source]ΒΆ

An empty POSIXLY_CORRECT still wins over an explicit True.

Presence alone triggers POSIX parsing (matching GNU getopt), regardless of value, and it takes precedence over a developer-supplied allow_interspersed_args=True.

Return type:

None

tests.test_context.test_posixly_correct_stops_option_parsing_at_first_argument()[source]ΒΆ

End-to-end: parsing stops at the first positional under POSIXLY_CORRECT.

Without the variable, the option interleaves with arguments (GNU style). With it set, the first positional ends option parsing, so the option keeps its default and the remaining tokens fall into the variadic argument.

Return type:

None

tests.test_context.test_lazy_meta_dict_resolves_on_first_access()[source]ΒΆ

Reading a lazy key triggers exactly one source attribute access.

Return type:

None

tests.test_context.test_lazy_meta_dict_caches_after_resolution()[source]ΒΆ

Subsequent reads of the same lazy key do not re-hit the source.

Return type:

None

tests.test_context.test_lazy_meta_dict_get_resolves_lazy_key()[source]ΒΆ

.get(lazy_key) triggers resolution like __getitem__.

Return type:

None

tests.test_context.test_lazy_meta_dict_get_returns_default_for_unknown_key()[source]ΒΆ

.get(unknown, default) returns the default without touching source.

Return type:

None

tests.test_context.test_lazy_meta_dict_contains_includes_lazy_keys_without_resolving()[source]ΒΆ

in returns True for declared lazy keys before any resolution.

Return type:

None

tests.test_context.test_lazy_meta_dict_preserves_base_entries()[source]ΒΆ

Entries from the wrapped base dict remain accessible.

Return type:

None

tests.test_context.test_lazy_meta_dict_independent_keys_resolve_independently()[source]ΒΆ

Resolving one lazy key does not resolve sibling lazy keys.

Return type:

None

tests.test_context.LAZY_ENTRIES = {'click_extra.alpha': 'alpha-value', 'click_extra.beta': 'beta-value', 'existing.key': 'existing-value'}ΒΆ

Every entry of the lazy dicts below once resolved, in iteration order.

tests.test_context.test_lazy_meta_dict_lists_pending_keys_without_resolving()[source]ΒΆ

len(), iteration and keys() count the keys in claims.

Listing a key does not read its value, so nothing resolves.

Return type:

None

tests.test_context.test_lazy_meta_dict_reads_pending_values(read)[source]ΒΆ

Whatever reads every value resolves the pending keys, and sees them all.

Return type:

None

tests.test_context.test_lazy_meta_dict_equality_reads_pending_values()[source]ΒΆ

Equality compares every entry, pending ones included, on both sides.

Return type:

None

tests.test_context.test_lazy_meta_dict_copy_keeps_pending_keys_pending()[source]ΒΆ

A copy lists the pending keys, and resolves them only when read.

Return type:

None

tests.test_context.test_lazy_meta_dict_removed_key_stays_removed(remove, removed)[source]ΒΆ

A pending key removed from the mapping does not come back.

Return type:

None

tests.test_context.test_lazy_meta_dict_pop_returns_pending_values()[source]ΒΆ

pop() and popitem() resolve the pending key they remove.

Return type:

None

tests.test_context.test_lazy_meta_dict_setdefault_resolves_pending_key()[source]ΒΆ

setdefault() keeps the value of a pending key rather than the default.

Return type:

None

tests.test_context.test_lazy_meta_dict_wraps_another_without_resolving()[source]ΒΆ

Wrapping a lazy dict keeps its pending keys pending.

The new dict copies only the entries the wrapped one stores.

Return type:

None

tests.test_context.test_lazy_meta_dict_added_source_takes_over_its_fields()[source]ΒΆ

A source added later resolves the fields it declares, resolved ones too.

A copy keeps the source of each pending key.

Return type:

None

tests.test_context.test_pass_context_typed_for_enhanced_context(invoke)[source]ΒΆ

@pass_context accepts a handler typed with the enhanced Context.

Click’s own pass_context is typed for the base click.Context, so annotating the handler with click-extra’s Context (to reach its extra helpers) would fail static type checks by parameter contravariance. This must both type-check (mypy covers this file) and forward the active enhanced Context at runtime.