472472 end
473473end
474474
475- @testitem " type" setup= [Setup] begin
475+ @testitem " type" setup = [Setup] begin
476476 @testset " type" begin
477477 @test pyis (pytype (pyjl (Int)), PythonCall. pyjltypetype)
478478 end
@@ -482,44 +482,46 @@ end
482482 @testset " numpy dtype" begin
483483 if Setup. devdeps
484484 np = pyimport (" numpy" )
485- @test pyeq (Bool, pygetattr (pyjl (Bool), " __numpy_dtype__" ), np. dtype (np. bool_))
486- @test pyeq (Bool, pygetattr (pyjl (Int8), " __numpy_dtype__" ), np. dtype (np. int8))
487- @test pyeq (Bool, pygetattr (pyjl (Int16), " __numpy_dtype__" ), np. dtype (np. int16))
488- @test pyeq (Bool, pygetattr (pyjl (Int32), " __numpy_dtype__" ), np. dtype (np. int32))
489- @test pyeq (Bool, pygetattr (pyjl (Int64), " __numpy_dtype__" ), np. dtype (np. int64))
490- @test pyeq (Bool, pygetattr (pyjl (Int), " __numpy_dtype__" ), np. dtype (np. int_))
491- @test pyeq (Bool, pygetattr (pyjl (UInt8), " __numpy_dtype__" ), np. dtype (np. uint8))
492- @test pyeq (Bool, pygetattr (pyjl (UInt16), " __numpy_dtype__" ), np. dtype (np. uint16))
493- @test pyeq (Bool, pygetattr (pyjl (UInt32), " __numpy_dtype__" ), np. dtype (np. uint32))
494- @test pyeq (Bool, pygetattr (pyjl (UInt64), " __numpy_dtype__" ), np. dtype (np. uint64))
495- @test pyeq (Bool, pygetattr (pyjl (UInt), " __numpy_dtype__" ), np. dtype (np. uintp))
496- @test pyeq (Bool, pygetattr (pyjl (Float16), " __numpy_dtype__" ), np. dtype (np. float16))
497- @test pyeq (Bool, pygetattr (pyjl (Float32), " __numpy_dtype__" ), np. dtype (np. float32))
498- @test pyeq (Bool, pygetattr (pyjl (Float64), " __numpy_dtype__" ), np. dtype (np. float64))
499- @test pyeq (Bool, pygetattr (pyjl (ComplexF32), " __numpy_dtype__" ), np. dtype (np. complex64))
500- @test pyeq (Bool, pygetattr (pyjl (ComplexF64), " __numpy_dtype__" ), np. dtype (np. complex128))
501- @test pyeq (Bool, pygetattr (pyjl (Ptr{Cvoid}), " __numpy_dtype__" ), np. dtype (" P" ))
502- @test pyeq (Bool, np. dtype (pyjl (Int64)), np. dtype (np. int64))
503485
504- err = try
505- pygetattr (pyjl (ComplexF16), " __numpy_dtype__" )
506- nothing
507- catch err
508- err
486+ # success cases
487+ @testset " $t -> $d " for (t, d) in [
488+ (Bool, " bool" ),
489+ (Int8, " int8" ),
490+ (Int16, " int16" ),
491+ (Int32, " int32" ),
492+ (Int64, " int64" ),
493+ (UInt8, " uint8" ),
494+ (UInt16, " uint16" ),
495+ (UInt32, " uint32" ),
496+ (UInt64, " uint64" ),
497+ (Float16, " float16" ),
498+ (Float32, " float32" ),
499+ (Float64, " float64" ),
500+ (ComplexF32, " complex64" ),
501+ (ComplexF64, " complex128" ),
502+ (Ptr{Cvoid}, " P" ),
503+ ]
504+ @test pyeq (Bool, pygetattr (pyjl (t), " __numpy_dtype__" ), np. dtype (d))
505+ @test pyeq (Bool, np. dtype (pyjl (t)), np. dtype (d))
509506 end
510- @test err isa PythonCall. PyException
511- @test pyis (err. _t, pybuiltins. AttributeError)
512507
513- err = try
514- pygetattr (pyjl (String), " __numpy_dtype__" )
515- nothing
516- catch err
517- err
508+ # unsupported cases
509+ @testset " $t -> AttributeError" for t in [
510+ ComplexF16,
511+ String,
512+ Tuple{},
513+ Ptr{Int},
514+ Ptr{PythonCall. C. PyPtr},
515+ ]
516+ err = try
517+ pygetattr (pyjl (t), " __numpy_dtype__" )
518+ nothing
519+ catch err
520+ err
521+ end
522+ @test err isa PythonCall. PyException
523+ @test pyis (err. t, pybuiltins. AttributeError)
518524 end
519- @test err isa PythonCall. PyException
520- @test pyis (err. _t, pybuiltins. AttributeError)
521- else
522- @test_skip Setup. devdeps
523525 end
524526 end
525527end
0 commit comments