python-click/tests/test_normalization.py

40 lines
956 B
Python
Raw Normal View History

2014-10-16 20:40:34 +02:00
import click
CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())
def test_option_normalization(runner):
@click.command(context_settings=CONTEXT_SETTINGS)
2020-07-21 08:23:42 +02:00
@click.option("--foo")
@click.option("-x")
2014-10-16 20:40:34 +02:00
def cli(foo, x):
click.echo(foo)
click.echo(x)
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--FOO", "42", "-X", 23])
assert result.output == "42\n23\n"
2014-10-16 20:40:34 +02:00
def test_choice_normalization(runner):
@click.command(context_settings=CONTEXT_SETTINGS)
2020-07-21 08:23:42 +02:00
@click.option("--choice", type=click.Choice(["Foo", "Bar"]))
2014-10-16 20:40:34 +02:00
def cli(choice):
2020-07-21 08:23:42 +02:00
click.echo(choice)
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--CHOICE", "FOO"])
assert result.output == "Foo\n"
2014-10-16 20:40:34 +02:00
def test_command_normalization(runner):
@click.group(context_settings=CONTEXT_SETTINGS)
def cli():
pass
@cli.command()
def foo():
2020-07-21 08:23:42 +02:00
click.echo("here!")
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["FOO"])
assert result.output == "here!\n"