MCPcopy Index your code
hub / github.com/httpie/cli / test_parser_serialization

Function test_parser_serialization

tests/test_parser_schema.py:4–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2
3
4def test_parser_serialization():
5 small_parser = ParserSpec("test_parser")
6
7 group_1 = small_parser.add_group("group_1")
8 group_1.add_argument("regular_arg", help="regular arg", short_help="short")
9 group_1.add_argument(
10 "variadic_arg",
11 metavar="META",
12 help=Qualifiers.SUPPRESS,
13 nargs=Qualifiers.ZERO_OR_MORE
14 )
15 group_1.add_argument(
16 "-O",
17 "--opt-arg",
18 action="lazy_choices",
19 getter=lambda: ["opt_1", "opt_2"],
20 help_formatter=lambda state, *, isolation_mode: ", ".join(state),
21 short_help="short_help",
22 )
23
24 group_2 = small_parser.add_group("group_2")
25 group_2.add_argument("--typed", action="store_true", type=int)
26
27 definition = small_parser.finalize()
28 assert definition.serialize() == {
29 "name": "test_parser",
30 "description": None,
31 "groups": [
32 {
33 "name": "group_1",
34 "description": None,
35 "is_mutually_exclusive": False,
36 "args": [
37 {
38 "options": ["regular_arg"],
39 "description": "regular arg",
40 "short_description": "short",
41 },
42 {
43 "options": ["variadic_arg"],
44 "is_optional": True,
45 "is_variadic": True,
46 "metavar": "META",
47 },
48 {
49 "options": ["-O", "--opt-arg"],
50 "description": "opt_1, opt_2",
51 "short_description": "short_help",
52 "choices": ["opt_1", "opt_2"],
53 },
54 ],
55 },
56 {
57 "name": "group_2",
58 "description": None,
59 "is_mutually_exclusive": False,
60 "args": [{"options": ["--typed"], "python_type_name": "int"}],
61 },

Callers

nothing calls this directly

Calls 5

add_groupMethod · 0.95
finalizeMethod · 0.95
ParserSpecClass · 0.90
add_argumentMethod · 0.80
serializeMethod · 0.45

Tested by

no test coverage detected