mirror of
https://github.com/httpie/cli.git
synced 2025-08-16 16:41:32 +02:00
Decouple parser definition from argparse (#1293)
This commit is contained in:
60
tests/test_parser_schema.py
Normal file
60
tests/test_parser_schema.py
Normal file
@ -0,0 +1,60 @@
|
||||
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")
|
||||
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: ", ".join(state),
|
||||
)
|
||||
|
||||
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",
|
||||
},
|
||||
{
|
||||
"options": ["variadic_arg"],
|
||||
"is_optional": True,
|
||||
"is_variadic": True,
|
||||
"metavar": "META",
|
||||
},
|
||||
{
|
||||
"options": ["-O", "--opt-arg"],
|
||||
"description": "opt_1, opt_2",
|
||||
"choices": ["opt_1", "opt_2"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "group_2",
|
||||
"description": None,
|
||||
"is_mutually_exclusive": False,
|
||||
"args": [{"options": ["--typed"], "python_type_name": "int"}],
|
||||
},
|
||||
],
|
||||
}
|
Reference in New Issue
Block a user