tests.test_color module¶
- tests.test_color.test_standalone_color_option(invoke, option_decorator, param, expecting_colors, assert_output_regex)[source]¶
Check color option values, defaults and effects on all things colored, including verbosity option.
- tests.test_color.test_no_color_env_convention(invoke, env, env_vote, tty, param, param_expect_colors)[source]¶
Each color variable is read by its own convention, on a terminal and in a pipe.
A vote of
Nonemust leave the decision to the output stream: colored on a terminal, plain in a pipe. The pipe case is what tells a variable casting no vote apart from one forcing color.
- tests.test_color.test_resolve_color_env_term(monkeypatch, term, expected)[source]¶
A dumb/unknown TERM votes color-off, while any other value stays neutral.
- tests.test_color.test_is_dumb_terminal(monkeypatch, term, expected)[source]¶
Case does not matter, and an unset
TERMis no dumb terminal.
- tests.test_color.test_renamed_color_option_reads_the_color_envvars(invoke)[source]¶
The color variables reach a color option under another name.
- tests.test_color.test_resolve_color_env_force_color_beats_dumb_term(monkeypatch, term)[source]¶
An explicit FORCE_COLOR stays authoritative over a dumb/unknown TERM.
- tests.test_color.test_color_synonym_cli_resolution(invoke, when, ctx_color)[source]¶
Every canonical value and GNU synonym resolves –color to the right state.
- tests.test_color.test_color_synonym_invalid_value(invoke, when)[source]¶
Unknown values, including the git-style true/false, still error. The message lists only the canonical choices, never the hidden synonyms.
The GNU synonyms are accepted but never advertised: –help shows only the canonical metavar.
- tests.test_color.test_color_synonym_cli_beats_env(invoke, when, env_var, ctx_color)[source]¶
A synonym on the command line keeps the same env precedence as its canonical twin: a command-line choice outranks the color environment variables.
- tests.test_color.test_color_synonym_config_string(invoke, create_config, when, ctx_color)[source]¶
A configuration file accepts the GNU synonyms as strings, normalized exactly like on the command line.
- tests.test_color.test_color_synonym_config_boolean(invoke, create_config, filename, raw, ctx_color)[source]¶
A configuration boolean maps true -> always and false -> never, including YAML’s coercion of yes/no/on/off, so a value means the same across formats.
- tests.test_color.test_color_synonym_config_beats_env(invoke, create_config, rhs, env_var, ctx_color)[source]¶
A config synonym or boolean beats the color environment variables, matching the documented precedence of canonical config values.
- tests.test_color.test_integrated_color_option(invoke, param, expecting_colors, ctx_color, assert_output_regex)[source]¶
Check effect of color option on all things colored, including verbosity option.
Also checks the color option in subcommands is inherited from parent context.
- tests.test_color.test_color_settles_before_eager_help_and_version(invoke, args, expecting_colors)[source]¶
–color / –no-color colorize the eager –help and –version screens whatever their position on the command line.
Click processes eager options in command-line order, so a –color sitting after –help or –version would otherwise pin
ctx.coloronly once the screen had already printed and exited.Command.parse_argssettles the color options in a pre-pass to close that gap. SeeCommand._resolve_presentation_eagerly.
- tests.test_color.test_cli_color_envvars_reach_eager_screens(invoke, screen, env, tty, expecting_colors)[source]¶
<CLI>_COLORand<CLI>_NO_COLORcolor the--helpand--versionscreens.Neither puts a flag on the command line, so the presentation pre-pass has to be triggered by the variables themselves, as it is for
<CLI>_THEME.
- tests.test_color.test_forced_color_sets_and_restores_env(monkeypatch)[source]¶
forced_colorforcesFORCE_COLORand clears Click Extra’s disabling vars.Inside the context the capture sees
FORCE_COLOR=1with every flag that would disable color (NO_COLOR,LLM, …) removed; on exit the prior environment, including any pre-existing values, is restored untouched.
- tests.test_color.test_resolve_background(monkeypatch, env, expected)[source]¶
Environment-variable precedence for the dark/light background decision.
- tests.test_color.test_terminal_background_names_the_theme_of_its_shade()[source]¶
A shade selects the built-in theme of the same name, as a plain string does.
- tests.test_color.test_resolve_background_query_is_opt_in(monkeypatch)[source]¶
The OSC 11 query runs only when
query_backgroundis set, below env vars.
- tests.test_color.test_resolve_background_query_below_explicit_env(monkeypatch)[source]¶
An explicit env signal outranks the live query even when querying is allowed.
- tests.test_color.test_parse_osc_rgb(response, expected)[source]¶
An OSC 11 reply is parsed into an 8-bit RGB tuple, or None when malformed.
- tests.test_color.test_is_dark_rgb(rgb, is_dark)[source]¶
Perceived-lightness classification of background colors.
- tests.test_color.test_is_a_tty()[source]¶
The probe reads
isatty, guarding streams that do not expose it.- Return type:
- tests.test_color.test_query_osc_background_without_tty(monkeypatch)[source]¶
The OSC query is a no-op when stdin or stdout is not a terminal.
- tests.test_color.test_query_osc_background_without_streams(monkeypatch)[source]¶
A detached process (no __stdin__/__stdout__) cannot query the terminal.
- tests.test_color.test_query_osc_background_pty(monkeypatch)[source]¶
A full OSC 11 round-trip over a pseudo-terminal yields the parsed color.
- tests.test_color.test_invocation_color_reaches_background_threads(invoke, args, expected)[source]¶
The resolved color tri-state is mirrored process-wide, so a background thread (which has no reachable Click context) can still honor it; the mirror resets once the invocation closes.
- tests.test_color.test_resilient_context_does_not_publish_invocation_color(monkeypatch)[source]¶
Building an introspection context must leave the color mirror untouched.
A resilient context is never closed, so publishing from one would pin the process-wide mirror to the build environment’s NO_COLOR, stripping ANSI from the output of any later CLI carrying no color option of its own.
- tests.test_color.test_invocation_color_never_outlives_its_invocation(invoke, args)[source]¶
However an invocation ends, it must leave the color mirror on auto.
publish_invocation_color()queues its reset as a context-close callback, so an option callback raising during parameter processing aborts before the context is entered and the reset never fires. The mirror then stays pinned to that run’s--no-colorfor the rest of the process, stripping ANSI from any later CLI carrying no color option of its own.
- tests.test_color.test_invocation_color_expires_with_a_plain_click_command(invoke)[source]¶
A plain
click.commandborrowing the color options must not leak either.It has no
ExtraCommand.main()to reset the mirror in afinally, so the cleanup rides the context finalizer. Click’sUsageErrorholds that context inside a reference cycle, so the collection is forced here rather than waited on: in a running program ordinary allocation churn reaches it on its own.
- tests.test_color.test_a_stale_finalizer_does_not_clobber_a_live_invocation()[source]¶
The finalizer of a dead context must leave a newer invocation’s value alone.
Tying the reset to the context’s lifetime introduces this hazard: a context collected after the next invocation published would otherwise wipe a value that is still in use. The token comparison is what prevents it.