Skip to content

Commit 92a4532

Browse files
author
Christopher Doris
committed
tests
1 parent a5e1d3f commit 92a4532

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

test/concrete.jl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,28 @@ end
259259
end
260260

261261
@testset "datetime" begin
262-
# TODO
262+
dt = pyimport("datetime")
263+
x1 = pydate(2001, 2, 3)
264+
@test pyisinstance(x1, dt.date)
265+
@test pyeq(Bool, x1, dt.date(2001, 2, 3))
266+
x2 = pydate(Date(2002, 3, 4))
267+
@test pyisinstance(x2, dt.date)
268+
@test pyeq(Bool, x2, dt.date(2002, 3, 4))
269+
x3 = pytime(12, 3, 4, 5)
270+
@test pyisinstance(x3, dt.time)
271+
@test pyeq(Bool, x3, dt.time(12, 3, 4, 5))
272+
x4 = pytime(Time(23, 4, 5, 0, 6))
273+
@test pyisinstance(x4, dt.time)
274+
@test pyeq(Bool, x4, dt.time(23, 4, 5, 6))
275+
x5 = pydatetime(2001, 2, 3, 4, 5, 6, 7)
276+
@test pyisinstance(x5, dt.datetime)
277+
@test pyeq(Bool, x5, dt.datetime(2001, 2, 3, 4, 5, 6, 7))
278+
x6 = pydatetime(Date(2007, 8, 9))
279+
@test pyisinstance(x6, dt.datetime)
280+
@test pyeq(Bool, x6, dt.datetime(2007, 8, 9))
281+
x7 = pydatetime(DateTime(2001, 2, 3, 4, 5, 6, 7))
282+
@test pyisinstance(x7, dt.datetime)
283+
@test pyeq(Bool, x7, dt.datetime(2001, 2, 3, 4, 5, 6, 7000))
263284
end
264285

265286
@testset "code" begin

test/convert.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
@test_throws Exception pyconvert(Bool, "hello")
55
end
66

7+
@testset "bool -> Integer" begin
8+
@test pyconvert(Int, true) === 1
9+
@test pyconvert(Int, false) === 0
10+
end
11+
712
@testset "bytes -> Vector" begin
813
x1 = pyconvert(Vector{UInt8}, pybytes(pylist([1, 2, 3])))
914
@test x1 isa Vector{UInt8}
@@ -157,3 +162,18 @@ end
157162
@test x2 isa Dict{Char,Float32}
158163
@test x2 == Dict('c'=>3.0, 'd'=>4.0)
159164
end
165+
166+
@testset "date -> Date" begin
167+
x1 = pyconvert(Date, pydate(2001, 2, 3))
168+
@test x1 === Date(2001, 2, 3)
169+
end
170+
171+
@testset "time -> Time" begin
172+
x1 = pyconvert(Time, pytime(12, 3, 4, 5))
173+
@test x1 === Time(12, 3, 4, 0, 5)
174+
end
175+
176+
@testset "datetime -> DateTime" begin
177+
x1 = pyconvert(DateTime, pydatetime(2001, 2, 3, 4, 5, 6, 7000))
178+
@test x1 === DateTime(2001, 2, 3, 4, 5, 6, 7)
179+
end

0 commit comments

Comments
 (0)