diff --git a/click_params/miscellaneous.py b/click_params/miscellaneous.py index b3a27d4..4d868ca 100644 --- a/click_params/miscellaneous.py +++ b/click_params/miscellaneous.py @@ -58,8 +58,18 @@ def __init__(self, separator: str = ',', ignore_empty: bool = False): class ChoiceListParamType(ListParamType): name = 'choice list' - def __init__(self, choices: Sequence[str], separator: str = ',', case_sensitive: bool = True): - super().__init__(click.Choice(choices, case_sensitive=case_sensitive), separator) + def __init__( + self, + choices: Sequence[str], + separator: str = ',', + case_sensitive: bool = True, + ignore_empty: bool = False + ): + super().__init__( + click.Choice(choices, case_sensitive=case_sensitive), + separator=separator, + ignore_empty=ignore_empty + ) class UUIDListParamType(ListParamType): diff --git a/docs/usage/miscellaneous.md b/docs/usage/miscellaneous.md index d06b7a8..dc5a2d0 100644 --- a/docs/usage/miscellaneous.md +++ b/docs/usage/miscellaneous.md @@ -115,7 +115,7 @@ Your list of preferred fruits: ## ChoiceListParamType -Signature: `ChoiceListParamType(choices: Sequence[str], separator: str = ',', case_sensitive: bool = True)` +Signature: `ChoiceListParamType(choices: Sequence[str], separator: str = ',', case_sensitive: bool = True, ignore_empty: bool = False)` Converts given string to a list of choices. diff --git a/tests/test_miscellaneous.py b/tests/test_miscellaneous.py index 6b13f20..aa631bb 100644 --- a/tests/test_miscellaneous.py +++ b/tests/test_miscellaneous.py @@ -111,11 +111,15 @@ def cli(values): assert_equals_output(0, expected_output, result) -@pytest.mark.parametrize("param_type", [ - StringListParamType, MacAddressListParamType, UUIDListParamType, DateTimeListParamType +@pytest.mark.parametrize(("param_type", "extra_args"), [ + (StringListParamType, []), + (ChoiceListParamType, [click.Choice(["a", "b", "c"])]), + (MacAddressListParamType, []), + (UUIDListParamType, []), + (DateTimeListParamType, []) ]) -def test_miscellaneous_list_param_types_ignore_empty_string(param_type): - misc_list_type = param_type(ignore_empty=True) +def test_miscellaneous_list_param_types_ignore_empty_string(param_type, extra_args): + misc_list_type = param_type(*extra_args, ignore_empty=True) assert misc_list_type.convert("", None, None) == []