Skip to content

Commit 80427c7

Browse files
committed
Test argument parser more
1 parent 927b0aa commit 80427c7

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

test/test_pseudo_python_cli.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,35 @@ def make_dict(**kwargs):
2020
("-m ipykernel_launcher -f FILE",
2121
make_dict(module="ipykernel_launcher",
2222
args=shlex.split("-f FILE"))),
23+
("-", make_dict(script="-")),
24+
("- a", make_dict(script="-", args=["a"])),
25+
("script", make_dict(script="script")),
26+
("script a", make_dict(script="script", args=["a"])),
2327
])
24-
def test_parse_args(args, desired):
28+
def test_valid_args(args, desired):
2529
ns = parse_args(shlex.split(args))
2630
actual = vars(ns)
2731
assert actual == desired
2832

2933

34+
@pytest.mark.parametrize("args", [
35+
"-m",
36+
"-c",
37+
"-i -m",
38+
# They are invalid in python CLI but works in argparse (which is
39+
# probably OK):
40+
pytest.mark.xfail("-V -m"),
41+
pytest.mark.xfail("-h -m"),
42+
])
43+
def test_invalid_args(args, capsys):
44+
with pytest.raises(SystemExit) as exc_info:
45+
parse_args(shlex.split(args))
46+
assert exc_info.value.code != 0
47+
48+
captured = capsys.readouterr()
49+
assert "usage:" in captured.err
50+
51+
3052
@pytest.mark.parametrize("cli_args", [
3153
["-h"],
3254
["-i", "--help"],

0 commit comments

Comments
 (0)