-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathCompat.jl
110 lines (104 loc) · 2.94 KB
/
Compat.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
@testitem "gui" begin
@testset "fix_qt_plugin_path" begin
@test PythonCall.fix_qt_plugin_path() isa Bool
# second time is a no-op
@test PythonCall.fix_qt_plugin_path() === false
end
@testset "event_loop_on/off" begin
for g in [:pyqt4, :pyqt5, :pyside, :pyside2, :gtk, :gtk3, :wx]
# TODO: actually test the various GUIs somehow?
@show g
@test_throws PyException PythonCall.event_loop_on(g)
@test PythonCall.event_loop_off(g) === nothing
end
end
end
@testitem "ipython" begin
@testset "PythonDisplay" begin
sys = pyimport("sys")
io = pyimport("io")
pystdout = sys.stdout
fp = sys.stdout = io.StringIO()
try
d = PythonCall.Compat.PythonDisplay()
@test display(d, 123) === nothing
fp.seek(0)
@test pyconvert(String, fp.read()) == "123\n"
finally
sys.stdout = pystdout
end
end
@testset "IPythonDisplay" begin
# TODO
end
end
@testitem "multimedia" begin
# TODO
end
@testitem "PyCall.jl" begin
# TODO
end
@testitem "Serialization.jl" begin
using Serialization
@testset "Py" begin
for x in Py[
Py(123),
Py(1.23),
Py("hello"),
pylist([1, 2, 3]),
pytuple([1, 2, 3]),
Py(nothing),
Py([1, 2, 3]),
Py(:hello),
]
io = IOBuffer()
serialize(io, x)
seekstart(io)
y = deserialize(io)
@test y isa Py
@test pyis(pytype(x), pytype(y))
@test pyeq(Bool, x, y)
end
end
@testset "PyException" begin
for e in Py[pybuiltins.ValueError("hello")]
io = IOBuffer()
x = PyException(e)
serialize(io, x)
seekstart(io)
y = deserialize(io)
@test y isa PyException
@test pyeq(Bool, y.t, x.t)
@test pyeq(Bool, y.v.args, x.v.args)
end
end
end
@testitem "Tables.jl" begin
using CondaPkg
CondaPkg.add("pandas")
@testset "pytable" begin
x = (x = [1, 2, 3], y = ["a", "b", "c"])
# pandas
t = pytable(x, :pandas)
@test pyconvert.(Int, Tuple(t.shape)) == (3, 2)
# columns
y = pytable(x, :columns)
@test pyeq(Bool, y, pydict(x = [1, 2, 3], y = ["a", "b", "c"]))
# rows
y = pytable(x, :rows)
@test pyeq(Bool, y, pylist([(1, "a"), (2, "b"), (3, "c")]))
@test all(pyisinstance(y.x, pybuiltins.int) for y in y)
@test all(pyisinstance(y.y, pybuiltins.str) for y in y)
# rowdicts
y = pytable(x, :rowdicts)
@test pyeq(
Bool,
y,
pylist([
pydict(x = 1, y = "a"),
pydict(x = 2, y = "b"),
pydict(x = 3, y = "c"),
]),
)
end
end