Skip to content

Commit

Permalink
Use shlex in test_python_jl.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Oct 24, 2018
1 parent 3df1716 commit e9ce328
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions test/test_python_jl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from textwrap import dedent
import os
import shlex
import subprocess

import pytest
Expand All @@ -13,43 +14,43 @@
JULIA = os.environ.get("JULIA_EXE")


@pytest.mark.parametrize("cli_args", [
["-h"],
["-i", "--help"],
["--julia", "false", "-h"],
["--julia", "false", "-i", "--help"],
@pytest.mark.parametrize("args", [
"-h",
"-i --help",
"--julia false -h",
"--julia false -i --help",
])
def test_help_option(cli_args, capsys):
def test_help_option(args, capsys):
with pytest.raises(SystemExit) as exc_info:
parse_pyjl_args(cli_args)
parse_pyjl_args(shlex.split(args))
assert exc_info.value.code == 0

captured = capsys.readouterr()
assert "usage:" in captured.out


quick_pass_cli_args = [
["-h"],
["-i", "--help"],
["-V"],
["--version", "-c", "1/0"],
"-h",
"-i --help",
"-V",
"--version -c 1/0",
]


@pytest.mark.parametrize("cli_args", quick_pass_cli_args)
def test_cli_quick_pass(cli_args):
@pytest.mark.parametrize("args", quick_pass_cli_args)
def test_cli_quick_pass(args):
subprocess.check_output(
["python-jl"] + cli_args,
["python-jl"] + shlex.split(args),
)


@pytest.mark.skipif(
not which("false"),
reason="false command not found")
@pytest.mark.parametrize("cli_args", quick_pass_cli_args)
def test_cli_quick_pass_no_julia(cli_args):
@pytest.mark.parametrize("args", quick_pass_cli_args)
def test_cli_quick_pass_no_julia(args):
subprocess.check_output(
["python-jl", "--julia", "false"] + cli_args,
["python-jl", "--julia", "false"] + shlex.split(args),
)


Expand All @@ -60,17 +61,17 @@ def test_cli_quick_pass_no_julia(cli_args):
not PYJULIA_TEST_REBUILD,
reason="PYJULIA_TEST_REBUILD=yes is not set")
def test_cli_import():
cli_args = ["-c", dedent("""
args = ["-c", dedent("""
from julia import Base
Base.banner()
from julia import Main
Main.x = 1
assert Main.x == 1
""")]
if JULIA:
cli_args = ["--julia", JULIA] + cli_args
args = ["--julia", JULIA] + args
output = subprocess.check_output(
["python-jl"] + cli_args,
["python-jl"] + args,
universal_newlines=True)
assert "julialang.org" in output

Expand Down

0 comments on commit e9ce328

Please sign in to comment.