Skip to content

Commit c203565

Browse files
committed
Fix JuliaInfo.load for Python 2
1 parent f1829f2 commit c203565

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

julia/core.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,15 @@ def load(cls, julia="julia", **popen_kwargs):
384384
stdout, stderr = proc.communicate()
385385
retcode = proc.wait()
386386
if retcode != 0:
387-
raise subprocess.CalledProcessError(
388-
retcode,
389-
[julia, "-e", "..."],
390-
stdout,
391-
stderr,
392-
)
387+
if sys.version_info[0] < 3:
388+
output = "\n".join(["STDOUT:", stdout, "STDERR:", stderr])
389+
raise subprocess.CalledProcessError(
390+
retcode, [julia, "-e", "..."], output
391+
)
392+
else:
393+
raise subprocess.CalledProcessError(
394+
retcode, [julia, "-e", "..."], stdout, stderr
395+
)
393396

394397
stderr = stderr.strip()
395398
if stderr:

test/test_juliainfo.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import os
22
import subprocess
33

4-
from julia.core import JuliaInfo, _enviorn
4+
import pytest
5+
6+
from julia.core import JuliaInfo, _enviorn, which
57

68

79
def check_core_juliainfo(jlinfo):
@@ -47,3 +49,14 @@ def test_juliainfo_without_pycall(tmpdir):
4749
check_core_juliainfo(jlinfo)
4850
assert jlinfo.python is None
4951
assert jlinfo.libpython_path is None
52+
53+
54+
@pytest.mark.skipif(
55+
not which("false"),
56+
reason="false command not found")
57+
def test_juliainfo_failure():
58+
with pytest.raises(subprocess.CalledProcessError) as excinfo:
59+
JuliaInfo.load(julia="false")
60+
assert excinfo.value.cmd[0] == "false"
61+
assert excinfo.value.returncode == 1
62+
assert isinstance(excinfo.value.output, str)

0 commit comments

Comments
 (0)