@@ -20,13 +20,35 @@ def make_dict(**kwargs):
20
20
("-m ipykernel_launcher -f FILE" ,
21
21
make_dict (module = "ipykernel_launcher" ,
22
22
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" ])),
23
27
])
24
- def test_parse_args (args , desired ):
28
+ def test_valid_args (args , desired ):
25
29
ns = parse_args (shlex .split (args ))
26
30
actual = vars (ns )
27
31
assert actual == desired
28
32
29
33
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
+
30
52
@pytest .mark .parametrize ("cli_args" , [
31
53
["-h" ],
32
54
["-i" , "--help" ],
0 commit comments