You've already forked httpie-cli
mirror of
https://github.com/httpie/cli.git
synced 2025-08-10 22:42:05 +02:00
Decouple parser definition from argparse (#1293)
This commit is contained in:
@@ -3,6 +3,7 @@ import shutil
|
||||
import json
|
||||
from httpie.sessions import SESSIONS_DIR_NAME
|
||||
from httpie.status import ExitStatus
|
||||
from httpie.cli.options import PARSER_SPEC_VERSION
|
||||
from tests.utils import DUMMY_HOST, httpie
|
||||
from tests.fixtures import SESSION_FILES_PATH, SESSION_FILES_NEW, SESSION_FILES_OLD, read_session_file
|
||||
|
||||
@@ -123,3 +124,15 @@ def test_httpie_sessions_upgrade_all(tmp_path, mock_env, extra_args, extra_varia
|
||||
assert read_session_file(refactored_session_file) == read_session_file(
|
||||
expected_session_file, extra_variables=extra_variables
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'load_func, extra_options', [
|
||||
(json.loads, []),
|
||||
(json.loads, ['--format=json'])
|
||||
]
|
||||
)
|
||||
def test_cli_export(load_func, extra_options):
|
||||
response = httpie('cli', 'export-args', *extra_options)
|
||||
assert response.exit_status == ExitStatus.SUCCESS
|
||||
assert load_func(response)['version'] == PARSER_SPEC_VERSION
|
||||
|
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