File: test_parser_schema.py

package info (click to toggle)
httpie 3.2.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,904 kB
  • sloc: python: 13,760; xml: 162; makefile: 141; ruby: 79; sh: 32
file content (63 lines) | stat: -rw-r--r-- 2,085 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from httpie.cli.options import ParserSpec, Qualifiers


def test_parser_serialization():
    small_parser = ParserSpec("test_parser")

    group_1 = small_parser.add_group("group_1")
    group_1.add_argument("regular_arg", help="regular arg", short_help="short")
    group_1.add_argument(
        "variadic_arg",
        metavar="META",
        help=Qualifiers.SUPPRESS,
        nargs=Qualifiers.ZERO_OR_MORE
    )
    group_1.add_argument(
        "-O",
        "--opt-arg",
        action="lazy_choices",
        getter=lambda: ["opt_1", "opt_2"],
        help_formatter=lambda state, *, isolation_mode: ", ".join(state),
        short_help="short_help",
    )

    group_2 = small_parser.add_group("group_2")
    group_2.add_argument("--typed", action="store_true", type=int)

    definition = small_parser.finalize()
    assert definition.serialize() == {
        "name": "test_parser",
        "description": None,
        "groups": [
            {
                "name": "group_1",
                "description": None,
                "is_mutually_exclusive": False,
                "args": [
                    {
                        "options": ["regular_arg"],
                        "description": "regular arg",
                        "short_description": "short",
                    },
                    {
                        "options": ["variadic_arg"],
                        "is_optional": True,
                        "is_variadic": True,
                        "metavar": "META",
                    },
                    {
                        "options": ["-O", "--opt-arg"],
                        "description": "opt_1, opt_2",
                        "short_description": "short_help",
                        "choices": ["opt_1", "opt_2"],
                    },
                ],
            },
            {
                "name": "group_2",
                "description": None,
                "is_mutually_exclusive": False,
                "args": [{"options": ["--typed"], "python_type_name": "int"}],
            },
        ],
    }