tests.test_theme module¶
Tests for click_extra.theme: in-process isolation, built-in themes and
[tool.<cli>.themes.<name>] config integration.
- tests.test_theme.test_theme_does_not_leak_across_invocations()[source]¶
A
--theme lightinvocation must not bleed into a later--helprender.Two back-to-back invocations of the same CLI in the same process:
--theme light --help– selects the light palette for this call only.--help– no--themeargument, must fall back to the dark default.
The dark theme renders headings with
\x1b[94m(bright blue); the light theme uses\x1b[35m(magenta, chosen to stay distinct from its blue options). If the second invocation picks up the first’s choice via process-wide state, it leaks the light palette and the assertion below fails.
- tests.test_theme.test_theme_default_unchanged_after_invocation()[source]¶
An invocation with
--theme lightmust not mutate the process-wide default.
- tests.test_theme.test_demo_themes_renders_each_builtin_palette()[source]¶
click-extra themesrenders the sample help once per built-in theme, each in its own palette.Guards against the whole gallery collapsing onto the default palette: the
themescommand drivesget_current_themethrough the contextTHEMEmeta, so a regression there would render all seven screens identically.
- tests.test_theme.test_demo_themes_renders_only_the_named_palettes()[source]¶
Named theme IDs narrow the gallery down, and keep the order they were given.
- tests.test_theme.test_demo_themes_resolves_auto_to_a_palette_name()[source]¶
autois a directive, so the gallery labels the palette it lands on.Which palette that is depends on the background detected from the environment, so the expectation is read back from the same resolver rather than pinned to
dark.
- tests.test_theme.test_demo_themes_rejects_an_unknown_palette()[source]¶
An unknown ID fails, and the error lists every name that would have worked.
- tests.test_theme.test_theme_meta_key_matches_registry()[source]¶
get_current_theme()reads from the same keyThemeOptionwrites.
- tests.test_theme.test_font_role_slots_are_known_and_disjoint()[source]¶
LITERAL_STYLES/REPLACEABLE_STYLESmust classify real, distinct slots.The two frozensets encode the man-pages(7) bold/italic font roles by slot name and are maintained by hand, so guard against drift: every name must be a real
HelpThemefield, the two roles must not overlap, and the representative slots must keep their expected role.
- tests.test_theme.test_builtin_themes_alphabetical()[source]¶
Built-in themes are declared alphabetically (matters for
--themechoices).
- tests.test_theme.test_builtin_themes_build_on_first_lookup()[source]¶
Importing the package builds no theme, and a
--helpbuildsdarkonly.Reading the theme names, which
--themedoes to list its choices, builds nothing either. Checked in a pristine interpreter, since the other tests have built every theme already.
- tests.test_theme.test_builtin_themes_resolve_to_one_instance()[source]¶
A built-in theme is the same instance in every mapping that holds it.
- tests.test_theme.test_theme_registry_takes_dict_mutations(monkeypatch)[source]¶
Registering, replacing and removing entries work on built-in names too.
- tests.test_theme.test_builtin_themes_are_helptheme_instances()[source]¶
Every
BUILTIN_THEMESentry is aHelpThemeinstance.
- tests.test_theme.test_cloup_constructors_keep_the_subclass(palette)[source]¶
dark()andlight()return a click-extra theme carrying cloup’s palette.Cloup builds both palettes from
cloup.Style, whichto_dictandcascadereject, so each style is widened to click-extra’s.
- tests.test_theme.test_with_rejects_unknown_slots()[source]¶
Every argument naming no slot is listed, in a stable order.
- tests.test_theme.test_with_takes_none_as_a_value()[source]¶
Noneresets a slot, where cloup’s version reads it as no change.
- tests.test_theme.test_builtin_themes_follow_manpage_font_convention(theme_name)[source]¶
Every built-in theme bolds literal slots and italicizes replaceable ones.
Encodes the man-pages(7) typographic convention (
LITERAL_STYLESbold,REPLACEABLE_STYLESitalic) as an invariant across all palettes, so adding a theme or tweaking a slot can’t silently drop the literal/replaceable distinction. Themanpagetheme renders it with no color at all.
- tests.test_theme.test_theme_round_trips_through_dict(theme_name)[source]¶
HelpTheme.to_dict/from_dictround-trips every built-in theme.
- tests.test_theme.test_builtin_theme_definition_matches_to_dict(theme_name)[source]¶
Each built-in definition equals what
to_dictemits for its theme.So a definition sets no slot to its default value, which
to_dictleaves out.
- tests.test_theme.test_to_dict_omits_identity_slots()[source]¶
Slots left at the
identitydefault do not appear into_dictoutput.
- tests.test_theme.test_to_dict_emits_cross_ref_highlight_only_when_overridden()[source]¶
cross_ref_highlightis emitted only when it differs from the default.
- tests.test_theme.test_from_dict_rejects_unknown_keys()[source]¶
Typos like
optoinraiseTypeErrorinstead of being silently dropped.
- tests.test_theme.test_cascade_overrides_only_set_slots()[source]¶
cascadekeeps base’s slots wherever the overlay leaves them at default.
- tests.test_theme.test_cascade_returns_new_instance_when_overlay_changes_anything()[source]¶
Even a single-slot overlay produces a distinct theme instance.
- tests.test_theme.test_cascade_round_trips_through_dict()[source]¶
self.to_dict()wins overbase.to_dict()slot-by-slot.
- tests.test_theme.test_cascade_rejects_non_theme_base()[source]¶
cascaderejects anything that is not aHelpTheme.
- tests.test_theme.test_themechoice_choices_track_global_registry()[source]¶
Outside any context,
choicesreflects the module-level registry.Plus the reserved
autodirective, which every CLI takes and no registry holds.
- tests.test_theme.test_themechoice_choices_pick_up_context_overrides()[source]¶
A theme stashed under
THEME_OVERRIDESshows up inchoices.
- tests.test_theme.test_branded_themes_meet_wcag_aa_large(theme_name, slot)[source]¶
Branded themes’ readable-text slots clear WCAG AA Large (3.0+).
Branded palettes are deliberate 24-bit RGB choices, so we can hold them to a real WCAG threshold. AA Large is the realistic floor: full AA (4.5+) is unattainable for some published themes (like Solarized’s accent blue on its base03 background sits at ~4.08).
A regression that drops one of these slots below 3.0 means the theme is less readable than what currently ships and warrants a deliberate palette tweak rather than a silent slip.
- tests.test_theme.test_themes_meet_legibility_floor(theme_name)[source]¶
Every styled slot in every theme stays above the legibility floor.
Subdued slots (
debug,bracket,default, …) are allowed to fall below WCAG AA Large by design, but no slot should be effectively invisible against the theme’s assumed background. Catches accidental palette tweaks like setting an attribute to nearly the background color.
- tests.test_theme.test_themechoice_inert_when_registry_empty(monkeypatch)[source]¶
With no themes available, ThemeChoice ignores any value instead of failing.
A program can empty the registry: then even the built-in
darkdefault cannot resolve, soconvertreturns None rather than aborting the invocation.
- tests.test_theme.test_cli_runs_with_empty_theme_registry(invoke, monkeypatch)[source]¶
A CLI still runs when no themes are available.
The built-in –theme option defaults to
dark; with an empty registry that default must stay inert instead of crashing the whole command.
- tests.test_theme.test_themes_from_config_overrides_existing_theme()[source]¶
Known theme names cascade on top of the matching built-in palette.
- tests.test_theme.test_themes_from_config_creates_standalone_theme()[source]¶
Unknown theme names build a stand-alone theme with unset slots at default.
- tests.test_theme.test_themes_from_config_does_not_mutate_global_registry()[source]¶
themes_from_configis pure: the module-level registry is untouched.
- tests.test_theme.test_get_theme_registry_falls_back_to_global_without_ctx()[source]¶
get_theme_registry(None)returns a copy of the module-level registry.
- tests.test_theme.test_config_loads_new_theme(invoke, create_config)[source]¶
A
[tool.<cli>.themes.<name>]table registers a new theme for the invocation.
- tests.test_theme.test_config_overrides_existing_theme_palette(invoke, create_config)[source]¶
A
[tool.<cli>.themes.dark]table cascades onto the built-in dark palette.
- tests.test_theme.test_config_theme_appears_in_help_metavar(invoke, create_config)[source]¶
--helplists config-defined themes alongside the built-ins.
- tests.test_theme.test_config_theme_validation_error(invoke, create_config)[source]¶
A malformed
[tool.<cli>.themes.<name>]table is rejected with a rooted path.
- tests.test_theme.test_validate_themes_config_codes(themes, code)[source]¶
A malformed themes table is reported under a snake-case code, like every other configuration error.
- tests.test_theme.test_command_validators_keep_the_theme_validator(invoke, create_config)[source]¶
Validators a command declares join the built-in themes validator.
@command(config_validators=...)forwards them to the default--configoption, which keeps the built-in validator beside them: a malformed[tool.<cli>.themes.<name>]table is reported as a configuration validation error, not aTypeError.
- tests.test_theme.test_config_theme_does_not_leak_across_invocations(invoke, create_config)[source]¶
Themes defined in invocation N are not visible in invocation N+1.
- tests.test_theme.test_validate_config_catches_bad_theme(invoke, create_config)[source]¶
--validate-configsurfaces the same ValidationError as the runtime path.
- tests.test_theme.test_theme_auto_resolves_to_detected_palette(invoke, monkeypatch, env, expected_name)[source]¶
--theme=autopicks the built-in palette implied by the terminal background.
- tests.test_theme.test_theme_auto_from_config(invoke, create_config, monkeypatch)[source]¶
theme = "auto"in the config file makes detection the effective default.
- tests.test_theme.test_theme_auto_advertised_in_help_metavar(invoke)[source]¶
The reserved ‘auto’ directive is listed among the values –theme takes.
It resolves to a palette rather than being one, but it works on every Click Extra CLI, and a value named nowhere is a value nobody finds.
- tests.test_theme.test_themechoice_accepts_auto_directive()[source]¶
‘auto’ converts to itself though it is not a registered palette.
- tests.test_theme.test_theme_option_query_background_opt_in()[source]¶
The live OSC 11 query is off unless a CLI explicitly opts in.
- tests.test_theme.test_resolve_auto_theme_forwards_query_flag(monkeypatch)[source]¶
query_backgroundgates the live query that env-var detection ignores.
- tests.test_theme.test_theme_envvar_picks_palette(invoke, monkeypatch, env_value, expected_name)[source]¶
CLICK_EXTRA_THEMEthemes a CLI invoked without--theme.
- tests.test_theme.test_theme_envvar_accepts_auto_directive(invoke, monkeypatch)[source]¶
The reserved ‘auto’ directive resolves from the variable too.
- tests.test_theme.test_theme_flag_outranks_envvar(invoke, monkeypatch)[source]¶
An explicit
--themebeats the machine-wide variable.
- tests.test_theme.test_cli_envvar_outranks_theme_envvar(invoke, monkeypatch)[source]¶
The
<CLI>_THEMEvariable is more specific than the machine-wide one.
- tests.test_theme.test_config_outranks_theme_envvar(invoke, create_config, monkeypatch)[source]¶
A palette pinned in the CLI’s own config file is more specific.
- tests.test_theme.test_unknown_theme_envvar_warns_and_keeps_default(invoke, monkeypatch)[source]¶
A typo in a shell profile must not break every Click Extra CLI at once.
- tests.test_theme.test_theme_from_env_reaches_the_help_screen(invoke, monkeypatch, envvar)[source]¶
A palette named by the environment paints the screen it exists to paint.
Click processes a typed
--helpbefore an untyped--theme, so the palette only reaches the help screen through the pre-pass inCommand._resolve_presentation_eagerly.