-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -667,3 +667,4 @@ def try_call(f): | |
end | ||
|
||
include("test_pyfncall.jl") | ||
include("test_venv.jl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using PyCall, Compat, Compat.Test | ||
using Compat: @info | ||
|
||
|
||
@testset "fuzz PyCall._leak" begin | ||
N = 10000 | ||
|
||
@testset "_leak(Cstring, ...)" begin | ||
for i in 1:N | ||
x = String(rand('A':'z', rand(1:1000))) | ||
y = Base.unsafe_string(PyCall._leak(Cstring, x)) | ||
@test x == y | ||
end | ||
end | ||
|
||
@testset "_leak(Cwstring, ...)" begin | ||
for i in 1:N | ||
x = String(rand('A':'z', rand(1:1000))) | ||
a = Base.cconvert(Cwstring, x) | ||
ptr = PyCall._leak(a) | ||
z = unsafe_wrap(Array, ptr, size(a)) | ||
@test z[end] == 0 | ||
y = transcode(String, z)[1:end-1] | ||
@test x == y | ||
end | ||
end | ||
end | ||
|
||
|
||
@testset "venv activation" begin | ||
if PyCall.conda | ||
@info "Skip venv test with conda." | ||
elseif !success(PyCall.python_cmd(`-c "import venv"`)) | ||
@info "Skip venv test since venv package is missing." | ||
else | ||
mktempdir() do path | ||
# Create a new virtualenv | ||
run(PyCall.python_cmd(`-m venv $path`)) | ||
newpython = joinpath(path, "bin", "python") | ||
if Sys.iswindows() | ||
newpython *= ".exe" | ||
end | ||
@test isfile(newpython) | ||
|
||
# Run a fresh Julia process with new Python environment | ||
if VERSION < v"0.7.0-" | ||
setup_code = "" | ||
else | ||
setup_code = Base.load_path_setup_code() | ||
end | ||
code = """ | ||
$setup_code | ||
using PyCall | ||
print(PyCall.pyimport("sys")[:executable]) | ||
""" | ||
env = copy(ENV) | ||
env["PYCALL_JL_RUNTIME_PYTHON"] = newpython | ||
jlcmd = setenv(`$(Base.julia_cmd()) -e $code`, env) | ||
output = read(jlcmd, String) | ||
@test newpython == output | ||
end | ||
end | ||
end |