test_normalization.py 956 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import click
  2. CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())
  3. def test_option_normalization(runner):
  4. @click.command(context_settings=CONTEXT_SETTINGS)
  5. @click.option("--foo")
  6. @click.option("-x")
  7. def cli(foo, x):
  8. click.echo(foo)
  9. click.echo(x)
  10. result = runner.invoke(cli, ["--FOO", "42", "-X", 23])
  11. assert result.output == "42\n23\n"
  12. def test_choice_normalization(runner):
  13. @click.command(context_settings=CONTEXT_SETTINGS)
  14. @click.option("--choice", type=click.Choice(["Foo", "Bar"]))
  15. def cli(choice):
  16. click.echo(choice)
  17. result = runner.invoke(cli, ["--CHOICE", "FOO"])
  18. assert result.output == "Foo\n"
  19. def test_command_normalization(runner):
  20. @click.group(context_settings=CONTEXT_SETTINGS)
  21. def cli():
  22. pass
  23. @cli.command()
  24. def foo():
  25. click.echo("here!")
  26. result = runner.invoke(cli, ["FOO"])
  27. assert result.output == "here!\n"