test_parser.py 902 B

1234567891011121314151617181920212223242526272829303132
  1. import pytest
  2. import click
  3. from click.parser import OptionParser
  4. from click.parser import split_arg_string
  5. @pytest.mark.parametrize(
  6. ("value", "expect"),
  7. [
  8. ("cli a b c", ["cli", "a", "b", "c"]),
  9. ("cli 'my file", ["cli", "my file"]),
  10. ("cli 'my file'", ["cli", "my file"]),
  11. ("cli my\\", ["cli", "my"]),
  12. ("cli my\\ file", ["cli", "my file"]),
  13. ],
  14. )
  15. def test_split_arg_string(value, expect):
  16. assert split_arg_string(value) == expect
  17. def test_parser_default_prefixes():
  18. parser = OptionParser()
  19. assert parser._opt_prefixes == {"-", "--"}
  20. def test_parser_collects_prefixes():
  21. ctx = click.Context(click.Command("test"))
  22. parser = OptionParser(ctx)
  23. click.Option("+p", is_flag=True).add_to_parser(parser, ctx)
  24. click.Option("!e", is_flag=True).add_to_parser(parser, ctx)
  25. assert parser._opt_prefixes == {"-", "--", "+", "!"}