1
1
from textwrap import dedent
2
2
import os
3
+ import shlex
3
4
import subprocess
4
5
5
6
import pytest
13
14
JULIA = os .environ .get ("JULIA_EXE" )
14
15
15
16
16
- @pytest .mark .parametrize ("cli_args " , [
17
- [ "-h" ] ,
18
- [ "-i" , " --help"] ,
19
- [ "--julia" , " false" , " -h"] ,
20
- [ "--julia" , " false" , "-i" , " --help"] ,
17
+ @pytest .mark .parametrize ("args " , [
18
+ "-h" ,
19
+ "-i --help" ,
20
+ "--julia false -h" ,
21
+ "--julia false -i --help" ,
21
22
])
22
- def test_help_option (cli_args , capsys ):
23
+ def test_help_option (args , capsys ):
23
24
with pytest .raises (SystemExit ) as exc_info :
24
- parse_pyjl_args (cli_args )
25
+ parse_pyjl_args (shlex . split ( args ) )
25
26
assert exc_info .value .code == 0
26
27
27
28
captured = capsys .readouterr ()
28
29
assert "usage:" in captured .out
29
30
30
31
31
32
quick_pass_cli_args = [
32
- [ "-h" ] ,
33
- [ "-i" , " --help"] ,
34
- [ "-V" ] ,
35
- [ "--version" , "-c" , " 1/0"] ,
33
+ "-h" ,
34
+ "-i --help" ,
35
+ "-V" ,
36
+ "--version -c 1/0" ,
36
37
]
37
38
38
39
39
- @pytest .mark .parametrize ("cli_args " , quick_pass_cli_args )
40
- def test_cli_quick_pass (cli_args ):
40
+ @pytest .mark .parametrize ("args " , quick_pass_cli_args )
41
+ def test_cli_quick_pass (args ):
41
42
subprocess .check_output (
42
- ["python-jl" ] + cli_args ,
43
+ ["python-jl" ] + shlex . split ( args ) ,
43
44
)
44
45
45
46
46
47
@pytest .mark .skipif (
47
48
not which ("false" ),
48
49
reason = "false command not found" )
49
- @pytest .mark .parametrize ("cli_args " , quick_pass_cli_args )
50
- def test_cli_quick_pass_no_julia (cli_args ):
50
+ @pytest .mark .parametrize ("args " , quick_pass_cli_args )
51
+ def test_cli_quick_pass_no_julia (args ):
51
52
subprocess .check_output (
52
- ["python-jl" , "--julia" , "false" ] + cli_args ,
53
+ ["python-jl" , "--julia" , "false" ] + shlex . split ( args ) ,
53
54
)
54
55
55
56
@@ -60,17 +61,17 @@ def test_cli_quick_pass_no_julia(cli_args):
60
61
not PYJULIA_TEST_REBUILD ,
61
62
reason = "PYJULIA_TEST_REBUILD=yes is not set" )
62
63
def test_cli_import ():
63
- cli_args = ["-c" , dedent ("""
64
+ args = ["-c" , dedent ("""
64
65
from julia import Base
65
66
Base.banner()
66
67
from julia import Main
67
68
Main.x = 1
68
69
assert Main.x == 1
69
70
""" )]
70
71
if JULIA :
71
- cli_args = ["--julia" , JULIA ] + cli_args
72
+ args = ["--julia" , JULIA ] + args
72
73
output = subprocess .check_output (
73
- ["python-jl" ] + cli_args ,
74
+ ["python-jl" ] + args ,
74
75
universal_newlines = True )
75
76
assert "julialang.org" in output
76
77
0 commit comments