test_normalization.py
This file
Path
tests/test_normalization.py
63 lines · 1.8 KiB · Python
Last changed by
Expand `Choice` token normalization + make generic (#2796)Andreas Backxbefore adoption4ece17a
History of this fileTake it
The walk stopped after 200 commits: lines older than 27d12bd point at it.
start version 8.1.0.dev0David Lordbefore adoption27d12bd
lines 1–19why, one step back1import click23CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())456def test_option_normalization(runner):7 @click.command(context_settings=CONTEXT_SETTINGS)8 @click.option("--foo")9 @click.option("-x")10 def cli(foo, x):11 click.echo(foo)12 click.echo(x)1314 result = runner.invoke(cli, ["--FOO", "42", "-X", 23])15 assert result.output == "42\n23\n"161718def test_choice_normalization(runner):19 @click.command(context_settings=CONTEXT_SETTINGS)Expand `Choice` token normalization + make generic (#2796)Andreas Backxbefore adoption4ece17a
lines 20–28why, one step back20 @click.option(21 "--method",22 type=click.Choice(23 ["SCREAMING_SNAKE_CASE", "snake_case", "PascalCase", "kebab-case"],24 case_sensitive=False,25 ),26 )27 def cli(method):28 click.echo(method)start version 8.1.0.dev0David Lordbefore adoption27d12bd
line 29why, one step back29Expand `Choice` token normalization + make generic (#2796)Andreas Backxbefore adoption4ece17a
lines 30–50why, one step back30 result = runner.invoke(cli, ["--METHOD=snake_case"])31 assert not result.exception, result.output32 assert result.output == "snake_case\n"3334 # Even though it's case sensitive, the choice's original value is preserved35 result = runner.invoke(cli, ["--method=pascalcase"])36 assert not result.exception, result.output37 assert result.output == "PascalCase\n"3839 result = runner.invoke(cli, ["--method=meh"])40 assert result.exit_code == 241 assert (42 "Invalid value for '--method': 'meh' is not one of "43 "'screaming_snake_case', 'snake_case', 'pascalcase', 'kebab-case'."44 ) in result.output4546 result = runner.invoke(cli, ["--help"])47 assert (48 "--method [screaming_snake_case|snake_case|pascalcase|kebab-case]"49 in result.output50 )start version 8.1.0.dev0David Lordbefore adoption27d12bd
lines 51–63why, one step back515253def test_command_normalization(runner):54 @click.group(context_settings=CONTEXT_SETTINGS)55 def cli():56 pass5758 @cli.command()59 def foo():60 click.echo("here!")6162 result = runner.invoke(cli, ["FOO"])63 assert result.output == "here!\n"