tests.test_types moduleΒΆ
- tests.test_types.test_click_choice_behavior()[source]ΒΆ
Lockdown the behavior of method inherited from Clickβs Choice type.
- Return type:
- tests.test_types.test_enum_string_choices(enum_definition, choice_source, result)[source]ΒΆ
- Return type:
- tests.test_types.test_enum_choice_show_aliases(enum_definition, choice_source, show_aliases, result)[source]ΒΆ
Test that EnumChoice correctly handles Enum with aliases.
- Return type:
- tests.test_types.kebab_case(choice)[source]ΒΆ
Reshape a Python identifier into a CLI-friendly choice string.
- Return type:
- class tests.test_types.AliasedStrategy(*values)[source]ΒΆ
Bases:
EnumAliases declared in the class body, which every supported Python handles.
Unlike
_add_alias_(), this needs no Python 3.13.- SELECT_OLDER = 1ΒΆ
- SELECT_NEWEST = 2ΒΆ
- DISCARD_NEWEST = 1ΒΆ
- DISCARD_OLDER = 2ΒΆ
- class tests.test_types.TransformedFormat(*values)[source]ΒΆ
Bases:
Enum- PLAIN_TEXT = 'plain_text'ΒΆ
- RICH_HTML = 'rich_html'ΒΆ
- tests.test_types.test_enum_choice_transform(choice_source, transform, expected)[source]ΒΆ
transformreshapes the choice string produced by any source.- Return type:
- tests.test_types.test_enum_choice_transform_with_aliases(choice_source)[source]ΒΆ
transformis what makesshow_aliasesusable with non-identifier choices.- Return type:
- tests.test_types.test_enum_choice_transform_collision(show_aliases)[source]ΒΆ
A
transformcollapsing two spellings into one is rejected.- Return type:
- tests.test_types.test_enum_choice_transform_non_string()[source]ΒΆ
A
transformreturning a non-string blames itself, not the choice source.- Return type:
- tests.test_types.test_enum_choice_transform_raising()[source]ΒΆ
A
transformblowing up is reported with the string it choked on.- Return type:
- class tests.test_types.MyEnum(*values)[source]ΒΆ
Bases:
EnumProduce different strings for keys/names, values and str().
- FIRST_VALUE = 'first-value'ΒΆ
- SECOND_VALUE = 'second-value'ΒΆ
- tests.test_types.test_enum_choice_shell_complete(source, expected)[source]ΒΆ
Completion offers normalized choice strings, never the
Enum.memberform.Completion routes through
Choice.normalize_choice(), so anEnumChoicesuggests parseable strings (case-folded, as it is case-insensitive by default) instead ofMyEnum.FIRST_VALUE.- Return type:
- tests.test_types.test_enum_choice_rejects_non_enum_choices(choices)[source]ΒΆ
Anything but an
Enumclass is refused with aTypeError.- Return type:
- tests.test_types.test_enum_choice_rejects_unknown_choice_source()[source]ΒΆ
A string naming no
ChoiceSourcemember is refused with aValueError.- Return type:
- tests.test_types.test_enum_choice_command(invoke, cmd_decorator, opt_decorator, case_sensitive, valid_args, invalid_args)[source]ΒΆ
Test EnumChoice used within an option.
- Return type:
- tests.test_types.test_enum_choice_default_value(invoke, cmd_decorator, opt_decorator, opt_type, default_value)[source]ΒΆ
Test EnumChoice used within an option with a default value.
- Return type:
- tests.test_types.test_enum_choice_multiple_default_value(invoke, cmd_decorator, opt_decorator, default_value, expected)[source]ΒΆ
A
multiple=TrueEnumChoice resolves each member of its tuple default.Regression test for the
get_default()override stringifying the whole default tuple (str((MyEnum.FOO,))) instead of mapping each member, which made the default trip ClickβsValue must be an iterablecheck.- Return type:
- tests.test_types.test_enum_choice_none_default(invoke, cmd_decorator, opt_decorator)[source]ΒΆ
A single-value EnumChoice option defaulting to
Nonestays unset.Regression test for the
get_default()override turning aNonedefault into the choice string"None", which then failed its own validation.- Return type:
- tests.test_types.test_enum_choice_variadic_default_value(invoke, cmd_decorator, opt_decorator, default_value, expected)[source]ΒΆ
A variadic (nargs=-1) EnumChoice argument resolves each member of its default.
Companion to test_enum_choice_multiple_default_value covering the other branch of the get_default() override: the nargs == -1 path taken by arguments rather than the multiple path taken by options. Both map get_choice_string() over the members of a tuple default instead of stringifying the whole tuple.
- Return type:
- tests.test_types.test_enum_choice_callback(invoke, cmd_decorator, opt_decorator, choice_source, cli_value)[source]ΒΆ
Test that option callbacks receive properly converted Enum members.
- Return type:
- tests.test_types.test_multi_choice_parses_input(raw, expected)[source]ΒΆ
convert()splits on the separator, strips whitespace, drops empties.- Return type:
- tests.test_types.test_multi_choice_validates_against_choices()[source]ΒΆ
Unknown tokens raise
BadParameterviaself.fail().- Return type:
- tests.test_types.test_multi_choice_validates_an_already_parsed_sequence()[source]ΒΆ
A list is checked like a raw token, not waved through as pre-parsed.
A configuration file hands the option a list where the command line hands it one string, so skipping the check on a sequence lets an unknown value travel to whatever consumes the selection.
- Return type:
- tests.test_types.test_multi_choice_case_insensitive_normalizes()[source]ΒΆ
The default matches case-insensitively and returns the canonical case.
- Return type:
- tests.test_types.test_multi_choice_case_sensitive_matches_exactly()[source]ΒΆ
case_sensitive=Truerejects a token differing only in case.- Return type:
- tests.test_types.test_choice_types_default_to_case_insensitive(choice_type)[source]ΒΆ
Every choice type click-extra defines matches regardless of case by default.
- Return type:
- tests.test_types.test_multi_choice_in_click_option()[source]ΒΆ
End-to-end:
MultiChoiceplugs into a Click option likeChoicedoes.- Return type:
- tests.test_types.test_duration_passthrough_timedelta()[source]ΒΆ
An already-parsed timedelta is returned unchanged (idempotent conversion).
- Return type:
- tests.test_types.test_duration_rejects_calendar_units(value)[source]ΒΆ
Months and years are explicitly rejected because their length is ambiguous.
- Return type:
- tests.test_types.test_duration_absolute_timestamp(value)[source]ΒΆ
An RFC 3339 timestamp is converted to
now - timestampat parse time.- Return type:
- tests.test_types.test_duration_future_timestamp_parses_to_none()[source]ΒΆ
A timestamp in the future parses to
None, read as βno cutoffβ.- Return type:
- tests.test_types.test_duration_in_click_option()[source]ΒΆ
End-to-end:
Durationplugs into a Click option.- Return type:
- tests.test_types.test_parse_duration_passthrough_timedelta()[source]ΒΆ
An existing timedelta is returned unchanged, like Duration.convert.
- Return type: