From b88ae7e81f5bb3d5e72b55b4e621c81ea721ab74 Mon Sep 17 00:00:00 2001 From: Lilith Hafner Date: Mon, 9 Oct 2023 21:45:02 -0500 Subject: [PATCH 1/4] strip whitespace before parsing in seval --- src/jlwrap/module.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jlwrap/module.jl b/src/jlwrap/module.jl index 8d9832fa..b0b0a403 100644 --- a/src/jlwrap/module.jl +++ b/src/jlwrap/module.jl @@ -10,7 +10,7 @@ function pyjlmodule_dir(self::Module) end function pyjlmodule_seval(self::Module, expr::Py) - Py(Base.eval(self, Meta.parse(pyconvert(String, expr)))) + Py(Base.eval(self, Meta.parse(strip(pyconvert(String, expr))))) end function init_jlwrap_module() From 2ee2bb52cfbde8dcd606f1192c930992dab61dd1 Mon Sep 17 00:00:00 2001 From: Lilith Hafner Date: Tue, 10 Oct 2023 07:28:36 -0500 Subject: [PATCH 2/4] add seval tests --- test/utils.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/utils.jl b/test/utils.jl index a0d38492..8b0ff799 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -11,3 +11,9 @@ end @test s[1:2] == "ab" @test s[1:2:end] == "aaaab" end + +@testitem "seval" begin + m = Py(Main) + @test m.seval("1 + 1") === 2 # Basic behavior + @test m.seval("1 + 1\n ") === 2 # Trailing whitespace +end From bef8c6a5bd85daa771b01759409bc4cfccffcf4b Mon Sep 17 00:00:00 2001 From: Lilith Hafner Date: Tue, 10 Oct 2023 07:52:34 -0500 Subject: [PATCH 3/4] move tests to python --- pytest/test_all.py | 9 +++++++++ test/utils.jl | 6 ------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pytest/test_all.py b/pytest/test_all.py index e57bf514..fea675cb 100644 --- a/pytest/test_all.py +++ b/pytest/test_all.py @@ -1,2 +1,11 @@ def test_import(): import juliacall + +def test_seval(): + from juliacall import Main + + Main.seval(""" + function f(x) + return x^2 + end + """) diff --git a/test/utils.jl b/test/utils.jl index 8b0ff799..a0d38492 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -11,9 +11,3 @@ end @test s[1:2] == "ab" @test s[1:2:end] == "aaaab" end - -@testitem "seval" begin - m = Py(Main) - @test m.seval("1 + 1") === 2 # Basic behavior - @test m.seval("1 + 1\n ") === 2 # Trailing whitespace -end From 902b0339880f4506a7f8b011c98f60c91ce9e25f Mon Sep 17 00:00:00 2001 From: Lilith Hafner Date: Tue, 10 Oct 2023 16:36:43 -0500 Subject: [PATCH 4/4] move back to Julia side :( --- pytest/test_all.py | 9 --------- test/jlwrap.jl | 13 +++++++++---- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/pytest/test_all.py b/pytest/test_all.py index fea675cb..e57bf514 100644 --- a/pytest/test_all.py +++ b/pytest/test_all.py @@ -1,11 +1,2 @@ def test_import(): import juliacall - -def test_seval(): - from juliacall import Main - - Main.seval(""" - function f(x) - return x^2 - end - """) diff --git a/test/jlwrap.jl b/test/jlwrap.jl index 44f7d7ca..1310054b 100644 --- a/test/jlwrap.jl +++ b/test/jlwrap.jl @@ -149,11 +149,11 @@ end end @testitem "base" begin - + end @testitem "callback" begin - + end @testitem "dict" begin @@ -193,6 +193,11 @@ end @testset "bool" begin @test pytruth(pyjl(PythonCall)) end + @testset "seval" begin + m = Py(Main) + @test pyconvert(Any, m.seval("1 + 1")) === 2 # Basic behavior + @test pyconvert(Any, m.seval("1 + 1\n ")) === 2 # Trailing whitespace + end end @testitem "number" begin @@ -218,11 +223,11 @@ end end @testitem "objectarray" begin - + end @testitem "raw" begin - + end @testitem "set" begin