Skip to content

Commit 38deefe

Browse files
author
Christopher Doris
committed
use new testitem functionality
1 parent 1962dcf commit 38deefe

File tree

9 files changed

+73
-83
lines changed

9 files changed

+73
-83
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ julia = "1.6.1"
2626
[extras]
2727
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
2828
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
29+
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
2930

3031
[targets]
31-
test = ["Aqua", "Test"]
32+
test = ["Aqua", "Test", "TestItemRunner"]

test/abstract.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@testset "object" begin
1+
@testitem "object" begin
2+
import Markdown
23
@testset "pyis" begin
34
x = pylist()
45
y = PythonCall.pynew(x)
@@ -215,7 +216,7 @@
215216
end
216217
end
217218

218-
@testset "iter" begin
219+
@testitem "iter" begin
219220
@test_throws PyException pyiter(pybuiltins.None)
220221
@test_throws PyException pyiter(pybuiltins.True)
221222
# unsafe_pynext
@@ -237,7 +238,7 @@ end
237238
@test_throws PyException pynext(it)
238239
end
239240

240-
@testset "number" begin
241+
@testitem "number" begin
241242
@testset "pyneg" begin
242243
for n in -2:2
243244
@test pyeq(Bool, pyneg(pyint(n)), pyint(-n))
@@ -370,7 +371,7 @@ end
370371
# TODO: in-place operators
371372
end
372373

373-
@testset "builtins" begin
374+
@testitem "builtins" begin
374375
@testset "pyprint" begin
375376
buf = pyimport("io").StringIO()
376377
ans = pyprint("hello", 12, file=buf)

test/aqua.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@testitem "Aqua" begin
2+
# The unbound_args test fails on methods with signature like foo(::Type{Tuple{Vararg{V}}}) where V
3+
# Seems like a bug.
4+
import Aqua
5+
Aqua.test_all(PythonCall, unbound_args=false)
6+
end

test/concrete.jl

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@testset "import" begin
1+
@testitem "import" begin
22
sys = pyimport("sys")
33
os = pyimport("os")
44
@test pyeq(Bool, sys.__name__, "sys")
@@ -17,12 +17,12 @@
1717
@test pyis(verpath[2], path)
1818
end
1919

20-
@testset "consts" begin
20+
@testitem "consts" begin
2121
@test pybuiltins.None isa Py
2222
@test pystr(String, pybuiltins.None) == "None"
2323
end
2424

25-
@testset "str" begin
25+
@testitem "str" begin
2626
@test pyisinstance(pystr("foo"), pybuiltins.str)
2727
@test pyeq(Bool, pystr(pystr("foo")), pystr("foo"))
2828
@test pyeq(Bool, pystr(SubString("foobarbaz", 4:6)), pystr("bar"))
@@ -32,7 +32,7 @@ end
3232
@test pystr(String, pystr("foo")) === "foo"
3333
end
3434

35-
@testset "bytes" begin
35+
@testitem "bytes" begin
3636
@test pyisinstance(pybytes(UInt8[1,2,3]), pybuiltins.bytes)
3737
@test pyeq(Bool, pybytes(pylist([1,2,3])), pybytes(UInt8[1,2,3]))
3838
@test pyeq(Bool, pybytes(b"foo"), pystr("foo").encode("ascii"))
@@ -43,7 +43,7 @@ end
4343
@test pybytes(Base.CodeUnits{UInt8,String}, pystr("bar").encode("ascii")) == b"bar"
4444
end
4545

46-
@testset "tuple" begin
46+
@testitem "tuple" begin
4747
z = pytuple()
4848
@test pyisinstance(z, pybuiltins.tuple)
4949
@test pylen(z) == 0
@@ -59,7 +59,7 @@ end
5959
@test pyeq(Bool, pytuple(pylist([1,2,3])), x)
6060
end
6161

62-
@testset "list" begin
62+
@testitem "list" begin
6363
z = pylist()
6464
@test pyisinstance(z, pybuiltins.list)
6565
@test pylen(z) == 0
@@ -79,7 +79,7 @@ end
7979
@test pyeq(Bool, pyrowlist([1 2; 3 4]), pylist((pylist([1,2]), pylist([3,4]))))
8080
end
8181

82-
@testset "dict" begin
82+
@testitem "dict" begin
8383
z = pydict()
8484
@test pyisinstance(z, pybuiltins.dict)
8585
@test pylen(z) == 0
@@ -95,7 +95,7 @@ end
9595
@test pyeq(Bool, pydict(x), x)
9696
end
9797

98-
@testset "bool" begin
98+
@testitem "bool" begin
9999
@test pyis(pybool(), pybuiltins.False)
100100
@test pyis(pybool(false), pybuiltins.False)
101101
@test pyis(pybool(true), pybuiltins.True)
@@ -106,7 +106,7 @@ end
106106
@test pyis(pybool(pylist([1,2,3])), pybuiltins.True)
107107
end
108108

109-
@testset "int" begin
109+
@testitem "int" begin
110110
@test pyisinstance(pyint(), pybuiltins.int)
111111
@test pystr(String, pyint()) == "0"
112112
x = 123
@@ -129,7 +129,7 @@ end
129129
@test pyeq(Bool, pyint(pyfloat(12.3)), pyint(12))
130130
end
131131

132-
@testset "float" begin
132+
@testitem "float" begin
133133
y = pyfloat()
134134
@test pyisinstance(y, pybuiltins.float)
135135
@test pyeq(Bool, y, pyint(0))
@@ -149,7 +149,7 @@ end
149149
@test pyeq(Bool, pyfloat(pyint(123)), pyfloat(123))
150150
end
151151

152-
@testset "complex" begin
152+
@testitem "complex" begin
153153
y = pycomplex()
154154
@test pyisinstance(y, pybuiltins.complex)
155155
@test pyeq(Bool, y, pyint(0))
@@ -171,7 +171,7 @@ end
171171
@test pyeq(Bool, pycomplex(pyint(12), pyint(34)), y)
172172
end
173173

174-
@testset "set" begin
174+
@testitem "set" begin
175175
y = pyset()
176176
yf = pyfrozenset()
177177
@test pyisinstance(y, pybuiltins.set)
@@ -197,7 +197,7 @@ end
197197
@test pyeq(Bool, y, yf)
198198
end
199199

200-
@testset "slice" begin
200+
@testitem "slice" begin
201201
x = pyslice(12)
202202
@test pyisinstance(x, pybuiltins.slice)
203203
@test pyeq(Bool, x.start, pybuiltins.None)
@@ -215,7 +215,7 @@ end
215215
@test pyeq(Bool, x.step, 56)
216216
end
217217

218-
@testset "range" begin
218+
@testitem "range" begin
219219
x = pyrange(123)
220220
@test pyisinstance(x, pybuiltins.range)
221221
@test pyeq(Bool, x.start, 0)
@@ -233,10 +233,11 @@ end
233233
@test pyeq(Bool, x.step, 3)
234234
end
235235

236-
@testset "none" begin
236+
@testitem "none" begin
237+
# TODO
237238
end
238239

239-
@testset "type" begin
240+
@testitem "type" begin
240241
x = pytype(pyint())
241242
@test pyisinstance(x, pybuiltins.type)
242243
@test pyis(x, pybuiltins.int)
@@ -250,15 +251,16 @@ end
250251
@test pyeq(Bool, x.bar, 2)
251252
end
252253

253-
@testset "fraction" begin
254+
@testitem "fraction" begin
254255
# TODO
255256
end
256257

257-
@testset "method" begin
258+
@testitem "method" begin
258259
# TODO
259260
end
260261

261-
@testset "datetime" begin
262+
@testitem "datetime" begin
263+
using Dates
262264
dt = pyimport("datetime")
263265
x1 = pydate(2001, 2, 3)
264266
@test pyisinstance(x1, dt.date)
@@ -283,6 +285,6 @@ end
283285
@test pyeq(Bool, x7, dt.datetime(2001, 2, 3, 4, 5, 6, 7000))
284286
end
285287

286-
@testset "code" begin
288+
@testitem "code" begin
287289
# TODO
288290
end

test/convert.jl

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
@testset "bool -> Bool" begin
1+
@testitem "bool Bool" begin
22
@test pyconvert(Bool, true) === true
33
@test pyconvert(Bool, false) === false
44
@test_throws Exception pyconvert(Bool, "hello")
55
end
66

7-
@testset "bool -> Integer" begin
7+
@testitem "bool Integer" begin
88
@test pyconvert(Int, true) === 1
99
@test pyconvert(Int, false) === 0
1010
end
1111

12-
@testset "bytes -> Vector" begin
12+
@testitem "bytes Vector" begin
1313
x1 = pyconvert(Vector{UInt8}, pybytes(pylist([1, 2, 3])))
1414
@test x1 isa Vector{UInt8}
1515
@test x1 == [0x01, 0x02, 0x03]
@@ -18,33 +18,33 @@ end
1818
@test x2 == b"foo"
1919
end
2020

21-
@testset "complex -> Complex" begin
21+
@testitem "complex Complex" begin
2222
x1 = pyconvert(ComplexF32, pycomplex(1, 2))
2323
@test x1 === ComplexF32(1, 2)
2424
x2 = pyconvert(Complex, pycomplex(3, 4))
2525
@test x2 === ComplexF64(3, 4)
2626
end
2727

28-
@testset "float -> Float" begin
28+
@testitem "float Float" begin
2929
x1 = pyconvert(Float32, 12)
3030
@test x1 === Float32(12)
3131
x2 = pyconvert(Float64, 3.5)
3232
@test x2 === 3.5
3333
end
3434

35-
@testset "float -> Nothing" begin
35+
@testitem "float Nothing" begin
3636
@test_throws Exception pyconvert(Nothing, pyfloat(1.2))
3737
x1 = pyconvert(Nothing, pyfloat(NaN))
3838
@test x1 === nothing
3939
end
4040

41-
@testset "float -> Missing" begin
41+
@testitem "float Missing" begin
4242
@test_throws Exception pyconvert(Missing, pyfloat(1.2))
4343
x1 = pyconvert(Missing, pyfloat(NaN))
4444
@test x1 === missing
4545
end
4646

47-
@testset "int -> Integer" begin
47+
@testitem "int Integer" begin
4848
@test_throws Exception pyconvert(Int8, 300)
4949
@test_throws Exception pyconvert(UInt, -3)
5050
x1 = pyconvert(Int, 34)
@@ -58,17 +58,17 @@ end
5858
@test x4 == big(3)^1000
5959
end
6060

61-
@testset "None -> Nothing" begin
61+
@testitem "None Nothing" begin
6262
x1 = pyconvert(Nothing, pybuiltins.None)
6363
@test x1 === nothing
6464
end
6565

66-
@testset "None -> Missing" begin
66+
@testitem "None Missing" begin
6767
x1 = pyconvert(Missing, pybuiltins.None)
6868
@test x1 === missing
6969
end
7070

71-
@testset "range -> StepRange" begin
71+
@testitem "range StepRange" begin
7272
x1 = pyconvert(StepRange, pyrange(10))
7373
@test x1 === (0:1:9)
7474
x2 = pyconvert(StepRange, pyrange(3, 9, 2))
@@ -79,26 +79,26 @@ end
7979
@test x4 === (30:-3:-9)
8080
end
8181

82-
@testset "range -> UnitRange" begin
82+
@testitem "range UnitRange" begin
8383
x1 = pyconvert(UnitRange, pyrange(10))
8484
@test x1 === (0:9)
8585
x2 = pyconvert(UnitRange, pyrange(3, 9, 1))
8686
@test x2 === (3:8)
8787
end
8888

89-
@testset "str -> String" begin
89+
@testitem "str String" begin
9090
x1 = pyconvert(String, pystr("foo"))
9191
@test x1 === "foo"
9292
x2 = pyconvert(String, pystr("αβγℵ√"))
9393
@test x2 === "αβγℵ√"
9494
end
9595

96-
@testset "str -> Symbol" begin
96+
@testitem "str Symbol" begin
9797
x1 = pyconvert(Symbol, pystr("hello"))
9898
@test x1 === :hello
9999
end
100100

101-
@testset "str -> Char" begin
101+
@testitem "str Char" begin
102102
@test_throws Exception pyconvert(Char, pystr(""))
103103
@test_throws Exception pyconvert(Char, pystr("ab"))
104104
@test_throws Exception pyconvert(Char, pystr("abc"))
@@ -108,7 +108,7 @@ end
108108
@test x2 === 'Ψ'
109109
end
110110

111-
@testset "iterable -> Tuple" begin
111+
@testitem "iterable Tuple" begin
112112
t1 = pyconvert(Tuple, (1, 2))
113113
@test t1 === (1, 2)
114114
t2 = pyconvert(Tuple{Vararg{Int}}, (3, 4, 5))
@@ -120,7 +120,7 @@ end
120120
@test t4 === ntuple(i->i, 30)
121121
end
122122

123-
@testset "iterable -> Vector" begin
123+
@testitem "iterable Vector" begin
124124
x1 = pyconvert(Vector, pylist([1, 2]))
125125
@test x1 isa Vector{Int}
126126
@test x1 == [1, 2]
@@ -132,7 +132,7 @@ end
132132
@test x3 == [4.0, 5.0, 6.0]
133133
end
134134

135-
@testset "iterable -> Set" begin
135+
@testitem "iterable Set" begin
136136
x1 = pyconvert(Set, pyset([1, 2]))
137137
@test x1 isa Set{Int}
138138
@test x1 == Set([1, 2])
@@ -144,7 +144,7 @@ end
144144
@test x3 == Set([4.0, 5.0, 6.0])
145145
end
146146

147-
@testset "iterable -> Pair" begin
147+
@testitem "iterable Pair" begin
148148
@test_throws Exception pyconvert(Pair, ())
149149
@test_throws Exception pyconvert(Pair, (1,))
150150
@test_throws Exception pyconvert(Pair, (1, 2, 3))
@@ -154,7 +154,7 @@ end
154154
@test x2 === ("foo" => missing)
155155
end
156156

157-
@testset "mapping -> Dict" begin
157+
@testitem "mapping Dict" begin
158158
x1 = pyconvert(Dict, pydict(["a"=>1, "b"=>2]))
159159
@test x1 isa Dict{String, Int}
160160
@test x1 == Dict("a"=>1, "b"=>2)
@@ -163,17 +163,20 @@ end
163163
@test x2 == Dict('c'=>3.0, 'd'=>4.0)
164164
end
165165

166-
@testset "date -> Date" begin
166+
@testitem "date → Date" begin
167+
using Dates
167168
x1 = pyconvert(Date, pydate(2001, 2, 3))
168169
@test x1 === Date(2001, 2, 3)
169170
end
170171

171-
@testset "time -> Time" begin
172+
@testitem "time → Time" begin
173+
using Dates
172174
x1 = pyconvert(Time, pytime(12, 3, 4, 5))
173175
@test x1 === Time(12, 3, 4, 0, 5)
174176
end
175177

176-
@testset "datetime -> DateTime" begin
178+
@testitem "datetime → DateTime" begin
179+
using Dates
177180
x1 = pyconvert(DateTime, pydatetime(2001, 2, 3, 4, 5, 6, 7000))
178181
@test x1 === DateTime(2001, 2, 3, 4, 5, 6, 7)
179182
end

test/jlwrap.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@testset "iter" begin
1+
@testitem "iter" begin
22
x1 = [1,2,3,4,5]
33
x2 = pyjl(x1)
44
x3 = pylist(x2)

0 commit comments

Comments
 (0)