Skip to content

Commit

Permalink
more tests for pyexec and pyeval macros
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Doris committed Mar 18, 2024
1 parent 8fc0421 commit 758ed89
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion test/Core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -743,12 +743,21 @@ end
@test pyeq(Bool, l["x"], 4)
# check global code runs in global scope
pyexec("global y; y=x+1", g, l)
@test_throws PythonCall.PyException PythonCall.@pyexec (err = PythonCall.Core.pybuiltins.ValueError) => `raise err`
@test pyeq(Bool, g["y"], 5)
@test !pycontains(l, "y")
# check pyeval converts types correctly
@test pyeval(Int, "1+1", g) === 2
@test pyeval(Nothing, "None", g) === nothing
# @pyexec
@test_throws PyException @pyexec(`raise ValueError`)
@test @pyexec(`1 + 2`) === nothing
@test @pyexec(`ans = 1 + 2` => (ans::Int,)) === (ans=3,)
@test @pyexec((x=1, y=2) => `ans = x + y` => (ans::Int,)) === (ans=3,)
# @pyeval
@test_throws PyException @pyeval(`import sys`) # not an expression
@test_throws PyException @pyeval(`None + None`)
@test @pyeval(`1 + 2` => Int) === 3
@test @pyeval((x=1, y=2) => `x + y` => Int) === 3
end

@testitem "@pyconst" begin
Expand Down

0 comments on commit 758ed89

Please sign in to comment.