Skip to content
Myr

test_parser.py

This file

Path

tests/test_parser.py

32 lines · 915 bytes · Python

Last changed by

deprecate `OptionParser` (#2592)David Lordbefore adoption988c683

History of this file

Take it

1import pytest23import click4from click.parser import _OptionParser5from click.shell_completion import split_arg_string678@pytest.mark.parametrize(9    ("value", "expect"),10    [11        ("cli a b c", ["cli", "a", "b", "c"]),12        ("cli 'my file", ["cli", "my file"]),13        ("cli 'my file'", ["cli", "my file"]),14        ("cli my\\", ["cli", "my"]),15        ("cli my\\ file", ["cli", "my file"]),16    ],17)18def test_split_arg_string(value, expect):19    assert split_arg_string(value) == expect202122def test_parser_default_prefixes():23    parser = _OptionParser()24    assert parser._opt_prefixes == {"-", "--"}252627def test_parser_collects_prefixes():28    ctx = click.Context(click.Command("test"))29    parser = _OptionParser(ctx)30    click.Option("+p", is_flag=True).add_to_parser(parser, ctx)31    click.Option("!e", is_flag=True).add_to_parser(parser, ctx)32    assert parser._opt_prefixes == {"-", "--", "+", "!"}