Skip to content

Commit ea2cffa

Browse files
committed
test_basic: (tmp) add test_choice_option_normalization
1 parent 3a10de8 commit ea2cffa

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/test_basic.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,32 @@ def cli(method):
382382
assert "--method [foo|bar|baz]" in result.output
383383

384384

385+
def test_choice_option_normalization(runner):
386+
@click.command()
387+
@click.option(
388+
"--method",
389+
type=click.Choice(
390+
["SCREAMING_SNAKE_CASE", "snake_case", "PascalCase", "kebab-case"]
391+
),
392+
)
393+
def cli(method):
394+
click.echo(method)
395+
396+
result = runner.invoke(cli, ["--method=foo"])
397+
assert not result.exception
398+
assert result.output == "foo\n"
399+
400+
result = runner.invoke(cli, ["--method=meh"])
401+
assert result.exit_code == 2
402+
assert (
403+
"Invalid value for '--method': 'meh' is not one of "
404+
"'screaming-snake-case', 'snake-case', 'pascalcase', 'kebab-case'."
405+
) in result.output
406+
407+
result = runner.invoke(cli, ["--help"])
408+
assert "--method [foo|bar|baz]" in result.output
409+
410+
385411
def test_choice_argument(runner):
386412
@click.command()
387413
@click.argument("method", type=click.Choice(["foo", "bar", "baz"]))

0 commit comments

Comments
 (0)