tests.test_highlight module¶
- tests.test_highlight.test_theme_definition()[source]¶
Ensure we do not leave any property we would have inherited from cloup and logging primitives.
- tests.test_highlight.test_cloup_theme_lends_its_slots_to_the_active_theme(invoke)[source]¶
A plain
cloup.HelpThemein the formatter settings renders a help screen.Cloup’s slots come from it, and the slots click-extra adds from the active theme.
- class tests.test_highlight.Priority(*values)[source]¶
Bases:
Enum- LOW = 'low-priority'¶
- HIGH = 'high-priority'¶
- tests.test_highlight.test_option_highlight(opt, expected_outputs)[source]¶
Test highlighting of all option variations: types, defaults, ranges, envvars, choices, flags, metavars, deprecated messages.
- tests.test_highlight.test_extra_deprecated_markers_are_painted()[source]¶
A CLI’s own marker takes the
deprecatedslot, beside Click’s spelling.DEPRECATED_REis the worddeprecatedand nothing else, so a project marking a parameter in its own vocabulary gets no color for it until it declares the marker.
- tests.test_highlight.test_extra_deprecated_marker_overlapping_click_is_painted_once()[source]¶
A declared marker Click also writes is styled by one pass, not two.
- tests.test_highlight.test_deprecation_marker_stays_painted_around_a_keyword(category, keyword)[source]¶
A keyword quoted in a deprecation reason keeps the marker painted.
Cross-reference passes run over text the deprecation pass already painted, and the style each one applies closes with a reset. Unless the surrounding style is re-opened after it, the marker renders plain from the keyword to its closing parenthesis. One case per keyword category: the passes run in sequence, so a hole one of them punches says nothing about the others.
- tests.test_highlight.test_bracket_field_full_combination_styling()[source]¶
Document the runtime styling of a fully-loaded bracket field.
Covers the canonical
[env var: NAME; default: VAL; required]block that combines all three trailing-field labels. The bracket slot styles only the structural tokens: the outer[/], theenv var: `` / ``default: `` labels, and the ``; `` separators, while the value tokens (``NAME,VAL) and therequiredlabel get their own slot styling layered on top. This is the contract referenced inbracket’s docstring.
- tests.test_highlight.test_range_field_does_not_leak_into_following_choice()[source]¶
A range field must not bleed its bracket styling into the next option.
Regression guard: the
[x>=1]field emitted for anIntRange(min=1)option is immediately followed by aChoiceoption whose[apple|mango]metavar supplies a closing]. When the range bound matched\S+it absorbed the field’s own], letting the bracket regex run past the field and dim everything up to the choice metavar’s]. Assert the range field is self-contained and closed, and the following choice keeps its own styling.
- tests.test_highlight.test_bracket_field_inner_slot_fallback_to_bracket()[source]¶
Inner bracket-field slots fall back to
bracketwhen at identity.Contract: a theme that styles only
bracketand leavesenvvar/default/required/range_labelatidentityshould still render the whole bracket field with the bracket styling: value tokens inherit it rather than rendering plain. Specific inner slots override piecemeal.
- tests.test_highlight.test_bracket_field_inner_slot_override_takes_precedence()[source]¶
When a theme sets one inner slot, only that token uses it.
Complements
test_bracket_field_inner_slot_fallback_to_bracket(): a theme that stylesbracket+ onlyrequired(leavingenvvaranddefaultat identity) should render therequiredlabel with the dedicated style and fall back tobracketfor the envvar and default values.
Ensure hidden options are not highlighted.
- tests.test_highlight.test_cross_ref_highlight_disabled()[source]¶
When
cross_ref_highlightisFalse, only structural elements are styled (bracket fields, deprecated messages, subcommands, choice metavars). Options, choices in free-form text, metavars, arguments, and CLI names are left plain.
- tests.test_highlight.NO_HYPHEN_BREAK_CLICK_VERSION = (8, 6)¶
Click release whose help screens no longer break a line after a hyphen.
Below it, Click wraps a
rounded-outlinedefault asrounded-andoutline, so the second word starts a line of its own.
- tests.test_highlight.test_choice_does_not_override_default_style()[source]¶
Choice cross-ref highlighting must not restyle text inside bracket fields.
When a default value contains a substring that matches a choice keyword (like
outlinefromrounded-outline), the choice style must not override the default value style. Regression test for the case where line-wrapping splits a hyphenated default so the second word starts a new line and passes the lookbehind.
- tests.test_highlight.test_keyword_wrapped_at_its_dash_is_highlighted_whole()[source]¶
A keyword broken after its dash is painted as one run.
Click 8.6 no longer wraps a line after a hyphen, so the help text holds the break itself, in a paragraph Click prints as written.
- tests.test_highlight.test_choice_collection_case(params, expected, forbidden)[source]¶
Choice keywords must use the original-case strings from the type definition, not the normalized (lowercased) forms produced by
normalize_choice().
- tests.test_highlight.test_argument_highlight(params, expected, forbidden)[source]¶
Argument metavars get the
argumentstyle, distinct from option metavars.
- tests.test_highlight.test_no_false_positive_highlight(params, help_text, expected_present, expected_absent)[source]¶
Verify that highlighting does not leak into compound words, URLs, dotted names, already-styled regions, or partial-word matches.
- tests.test_highlight.test_parent_keywords_highlighted_in_subcommand_help()[source]¶
Parent group names, options, and choices must be highlighted in subcommand help text.
- tests.test_highlight.test_parent_choice_case_with_custom_metavar()[source]¶
Parent choices with custom metavar must use original-case strings in subcommand help, not normalized (lowercased) forms.
- tests.test_highlight.test_command_aliases_collected()[source]¶
Command aliases are collected as keywords for highlighting.
- tests.test_highlight.test_command_aliases_highlighted(invoke)[source]¶
Aliases inside parenthetical groups take the alias slot, and the parentheses and separators the alias_secondary slot.
- tests.test_highlight.test_single_alias_highlighted(invoke)[source]¶
A command with exactly one alias still gets highlighted.
- tests.test_highlight.test_alias_no_false_positive_in_description(invoke)[source]¶
An alias name appearing in a description must not be highlighted when it does not sit inside alias parentheses.
- tests.test_highlight.test_alias_substring_not_highlighted(invoke)[source]¶
An alias that is a substring of the subcommand name must not cause double-highlighting or partial matches.
- tests.test_highlight.test_help_keywords_merge(base_kwargs, other_kwargs, checks)[source]¶
HelpKeywords.merge() unions every field.
- tests.test_highlight.test_help_keywords_subtract(base_kwargs, removals_kwargs, checks)[source]¶
HelpKeywords.subtract() removes matching entries per field.
- tests.test_highlight.test_extra_keywords_merged()[source]¶
extra_keywords injects additional strings into the collected set.
- tests.test_highlight.test_excluded_keywords_preserved_in_collection()[source]¶
excluded_keywords does not remove from collect_keywords().
Exclusion is deferred to highlight_extra_keywords() so that choice metavars can be styled with the full choices set before the excluded choices are removed for cross-ref passes.
- tests.test_highlight.test_excluded_keywords_via_constructor()[source]¶
excluded_keywords can be passed through the Command constructor.
- tests.test_highlight.test_excluded_keywords_suppresses_highlighting()[source]¶
Excluded keywords do not appear styled in the rendered help text.
- tests.test_highlight.test_style_choice_metavar(metavar, choices, expected)[source]¶
style_choice_metavar styles known choices inside bracket-delimited metavar strings, styles non-choice parts (type placeholders) as metavars, and returns None for non-bracket strings.
- tests.test_highlight.test_multiple_choice_options_metavar_styled()[source]¶
Each choice option gets its metavar individually styled.
- tests.test_highlight.test_jobs_hybrid_metavar_highlights_keywords_and_placeholder()[source]¶
The hybrid
--jobs [auto|max|INTEGER]metavar highlights every part.Regression guard:
JobCountis a customParamType, not aclick.Choice, so the keyword collector learns itsauto/maxkeywords only through thechoicesattribute it exposes. With no other option contributing these tokens (a bareJobsOptioncommand pulls in no--color),auto/maxcan only be styled viaJobCount, and theINTEGERplaceholder renders as a metavar rather than staying plain.
- tests.test_highlight.test_excluded_multiple_choices_styled_in_metavar_only()[source]¶
Multiple excluded choices appear styled in their own metavar but not in free-text descriptions.
- tests.test_highlight.test_excluded_keywords_inheritance(parent_excluded, child_excluded, word, expect_styled)[source]¶
excluded_keywords propagate from parent groups to subcommands.
Parent choices are collected for subcommand help screens (cross-ref highlighting). The parent’s excluded_keywords must follow, otherwise excluded choices bleed into subcommand descriptions.
- tests.test_highlight.test_excluded_keywords_grandparent_propagation()[source]¶
excluded_keywords propagate through multiple nesting levels.
- tests.test_highlight.test_excluded_keywords_plain_click_group_parent()[source]¶
A plain click.Group parent without excluded_keywords does not crash.
- tests.test_highlight.test_excluded_keywords_not_mutated()[source]¶
Calling format_help must not mutate the command’s excluded_keywords.
- tests.test_highlight.test_standalone_help_option(invoke, cmd_decorator, cmd_type, option_decorator)[source]¶
- tests.test_highlight.test_invoked_subcommand_is_highlighted_and_prose_is_not()[source]¶
An example line running the CLI paints the subcommands it names.
The same word in the prose describing that subcommand stays unpainted: a subcommand often carries the name of what it does, and reading a whole help screen for it colors plain English.
- tests.test_highlight.test_subcommand_options_are_highlighted_on_the_group_screen()[source]¶
A group screen knows the options of the subcommands it lists.
An example invoking one names options the group itself never declares.
- tests.test_highlight.test_end_of_options_separator_is_styled()[source]¶
A lone
--takes the separator slot; an option name keeps its own.
- tests.test_highlight.test_bracket_field_closes_on_a_bracketed_default()[source]¶
A default value that is itself bracketed closes its own field.
A content pattern stopping at the first
]on screen would leave the field’s real closing bracket outside the styled run.
- tests.test_highlight.test_enumerated_metavar_is_styled_part_by_part()[source]¶
A hand-written metavar that enumerates its parts is painted as one.
Click renders nothing structured for a hybrid type, so
INTEGER|autois a plain string: the value takes the choice slot and the type placeholder beside it the metavar slot.