130130 @test pylen (x) == 0
131131 end
132132 @testset " pydir" begin
133- x = pytype (" Foo" , (), [" foo" => 1 , " bar" => 2 ])()
133+ x = pytype (" Foo" , (), [" foo" => 1 , " bar" => 2 ])()
134134 d = pydir (x)
135135 @test pycontains (d, " __class__" )
136136 @test pycontains (d, " foo" )
256256 end
257257 @testset " pyinv" begin
258258 for n in - 2 : 2
259- @test pyeq (Bool, pyinv (pyint (n)), pyint (- n- 1 ))
259+ @test pyeq (Bool, pyinv (pyint (n)), pyint (- n - 1 ))
260260 end
261261 end
262262 @testset " pyindex" begin
@@ -267,21 +267,21 @@ end
267267 @testset " pyadd" begin
268268 for x in - 2 : 2
269269 for y in - 2 : 2
270- @test pyeq (Bool, pyadd (pyint (x), pyint (y)), pyint (x+ y))
270+ @test pyeq (Bool, pyadd (pyint (x), pyint (y)), pyint (x + y))
271271 end
272272 end
273273 end
274274 @testset " pysub" begin
275275 for x in - 2 : 2
276276 for y in - 2 : 2
277- @test pyeq (Bool, pysub (pyint (x), pyint (y)), pyint (x- y))
277+ @test pyeq (Bool, pysub (pyint (x), pyint (y)), pyint (x - y))
278278 end
279279 end
280280 end
281281 @testset " pymul" begin
282282 for x in - 2 : 2
283283 for y in - 2 : 2
284- @test pyeq (Bool, pymul (pyint (x), pyint (y)), pyint (x* y))
284+ @test pyeq (Bool, pymul (pyint (x), pyint (y)), pyint (x * y))
285285 end
286286 end
287287 end
299299 if y == 0
300300 @test_throws PyException pytruediv (pyint (x), pyint (y))
301301 else
302- @test pyeq (Bool, pytruediv (pyint (x), pyint (y)), pyfloat (x/ y))
302+ @test pyeq (Bool, pytruediv (pyint (x), pyint (y)), pyfloat (x / y))
303303 end
304304 end
305305 end
@@ -409,15 +409,15 @@ end
409409 @test pyeq (Bool, sys. __name__, " sys" )
410410 @test pyeq (Bool, os. __name__, " os" )
411411 sysos = pyimport (" sys" , " os" )
412- @test sysos isa Tuple{Py, Py}
412+ @test sysos isa Tuple{Py,Py}
413413 @test pyis (sysos[1 ], sys)
414414 @test pyis (sysos[2 ], os)
415415 ver = pyimport (" sys" => " version" )
416416 @test pyis (ver, sys. version)
417417 path = pyimport (" sys" => " path" )
418418 @test pyis (path, sys. path)
419419 verpath = pyimport (" sys" => (" version" , " path" ))
420- @test verpath isa Tuple{Py, Py}
420+ @test verpath isa Tuple{Py,Py}
421421 @test pyis (verpath[1 ], ver)
422422 @test pyis (verpath[2 ], path)
423423end
@@ -438,12 +438,12 @@ end
438438end
439439
440440@testitem " bytes" begin
441- @test pyisinstance (pybytes (UInt8[1 ,2 , 3 ]), pybuiltins. bytes)
442- @test pyeq (Bool, pybytes (pylist ([1 ,2 , 3 ])), pybytes (UInt8[1 ,2 , 3 ]))
441+ @test pyisinstance (pybytes (UInt8[1 , 2 , 3 ]), pybuiltins. bytes)
442+ @test pyeq (Bool, pybytes (pylist ([1 , 2 , 3 ])), pybytes (UInt8[1 , 2 , 3 ]))
443443 @test pyeq (Bool, pybytes (b " foo" ), pystr (" foo" ). encode (" ascii" ))
444444 @test pyeq (Bool, pybytes (codeunits (SubString (" foobarbaz" , 4 : 6 ))), pystr (" bar" ). encode (" ascii" ))
445- @test pybytes (Vector, pylist ([1 ,2 , 3 ])) == UInt8[1 ,2 , 3 ]
446- @test pybytes (Vector{UInt8}, pylist ([1 ,2 , 3 ])) == UInt8[1 ,2 , 3 ]
445+ @test pybytes (Vector, pylist ([1 , 2 , 3 ])) == UInt8[1 , 2 , 3 ]
446+ @test pybytes (Vector{UInt8}, pylist ([1 , 2 , 3 ])) == UInt8[1 , 2 , 3 ]
447447 @test pybytes (Base. CodeUnits, pystr (" foo" ). encode (" ascii" )) == b " foo"
448448 @test pybytes (Base. CodeUnits{UInt8,String}, pystr (" bar" ). encode (" ascii" )) == b " bar"
449449end
@@ -452,36 +452,36 @@ end
452452 z = pytuple ()
453453 @test pyisinstance (z, pybuiltins. tuple)
454454 @test pylen (z) == 0
455- x = pytuple ((1 ,2 , 3 ))
455+ x = pytuple ((1 , 2 , 3 ))
456456 @test pyisinstance (x, pybuiltins. tuple)
457457 @test pylen (x) == 3
458458 @test pyeq (Bool, pygetitem (x, 0 ), 1 )
459459 @test pyeq (Bool, pygetitem (x, 1 ), 2 )
460460 @test pyeq (Bool, pygetitem (x, 2 ), 3 )
461- @test pyeq (Bool, pytuple ([1 ,2 , 3 ]), x)
462- @test pyeq (Bool, pytuple (i+ 1 for i in 0 : 10 if i< 3 ), x)
463- @test pyeq (Bool, pytuple (pytuple ((1 ,2 , 3 ))), x)
464- @test pyeq (Bool, pytuple (pylist ([1 ,2 , 3 ])), x)
461+ @test pyeq (Bool, pytuple ([1 , 2 , 3 ]), x)
462+ @test pyeq (Bool, pytuple (i + 1 for i in 0 : 10 if i < 3 ), x)
463+ @test pyeq (Bool, pytuple (pytuple ((1 , 2 , 3 ))), x)
464+ @test pyeq (Bool, pytuple (pylist ([1 , 2 , 3 ])), x)
465465end
466466
467467@testitem " list" begin
468468 z = pylist ()
469469 @test pyisinstance (z, pybuiltins. list)
470470 @test pylen (z) == 0
471- x = pylist ((1 ,2 , 3 ))
471+ x = pylist ((1 , 2 , 3 ))
472472 @test pyisinstance (x, pybuiltins. list)
473473 @test pylen (x) == 3
474474 @test pyeq (Bool, pygetitem (x, 0 ), 1 )
475475 @test pyeq (Bool, pygetitem (x, 1 ), 2 )
476476 @test pyeq (Bool, pygetitem (x, 2 ), 3 )
477- @test pyeq (Bool, pylist ([1 ,2 , 3 ]), x)
478- @test pyeq (Bool, pylist (i+ 1 for i in 0 : 10 if i< 3 ), x)
479- @test pyeq (Bool, pylist (pylist ((1 ,2 , 3 ))), x)
480- @test pyeq (Bool, pylist (pytuple ([1 ,2 , 3 ])), x)
481- @test pyeq (Bool, pycollist ([1 ,2 , 3 ]), pylist ([1 ,2 , 3 ]))
482- @test pyeq (Bool, pycollist ([1 2 ; 3 4 ]), pylist ((pylist ([1 ,3 ]), pylist ([2 ,4 ]))))
483- @test pyeq (Bool, pyrowlist ([1 ,2 , 3 ]), pylist ([1 ,2 , 3 ]))
484- @test pyeq (Bool, pyrowlist ([1 2 ; 3 4 ]), pylist ((pylist ([1 ,2 ]), pylist ([3 ,4 ]))))
477+ @test pyeq (Bool, pylist ([1 , 2 , 3 ]), x)
478+ @test pyeq (Bool, pylist (i + 1 for i in 0 : 10 if i < 3 ), x)
479+ @test pyeq (Bool, pylist (pylist ((1 , 2 , 3 ))), x)
480+ @test pyeq (Bool, pylist (pytuple ([1 , 2 , 3 ])), x)
481+ @test pyeq (Bool, pycollist ([1 , 2 , 3 ]), pylist ([1 , 2 , 3 ]))
482+ @test pyeq (Bool, pycollist ([1 2 ; 3 4 ]), pylist ((pylist ([1 , 3 ]), pylist ([2 , 4 ]))))
483+ @test pyeq (Bool, pyrowlist ([1 , 2 , 3 ]), pylist ([1 , 2 , 3 ]))
484+ @test pyeq (Bool, pyrowlist ([1 2 ; 3 4 ]), pylist ((pylist ([1 , 2 ]), pylist ([3 , 4 ]))))
485485end
486486
487487@testitem " dict" begin
493493 @test pylen (x) == 2
494494 @test pyeq (Bool, pygetitem (x, " foo" ), 1 )
495495 @test pyeq (Bool, pygetitem (x, " bar" ), 2 )
496- @test pyeq (Bool, pydict ([" foo" => 1 , " bar" => 2 ]), x)
497- @test pyeq (Bool, pydict ([(" foo" => 1 ), (" bar" => 2 )]), x)
498- @test pyeq (Bool, pydict (Dict (" foo" => 1 , " bar" => 2 )), x)
496+ @test pyeq (Bool, pydict ([" foo" => 1 , " bar" => 2 ]), x)
497+ @test pyeq (Bool, pydict ([(" foo" => 1 ), (" bar" => 2 )]), x)
498+ @test pyeq (Bool, pydict (Dict (" foo" => 1 , " bar" => 2 )), x)
499499 @test pyeq (Bool, pydict ((foo= 1 , bar= 2 )), x)
500500 @test pyeq (Bool, pydict (x), x)
501501end
508508 @test pyis (pybool (- 1.2 ), pybuiltins. True)
509509 @test pyis (pybool (pybuiltins. None), pybuiltins. False)
510510 @test pyis (pybool (pylist ()), pybuiltins. False)
511- @test pyis (pybool (pylist ([1 ,2 , 3 ])), pybuiltins. True)
511+ @test pyis (pybool (pylist ([1 , 2 , 3 ])), pybuiltins. True)
512512end
513513
514514@testitem " int" begin
546546 y = pyfloat (x)
547547 @test pyisinstance (y, pybuiltins. float)
548548 @test pyeq (Bool, y, pytruediv (1 , 4 ))
549- x = 1 // 4
549+ x = 1 // 4
550550 y = pyfloat (x)
551551 @test pyisinstance (y, pybuiltins. float)
552552 @test pyeq (Bool, y, pyfloat (float (x)))
584584 @test pyisinstance (yf, pybuiltins. frozenset)
585585 @test pylen (yf) == 0
586586 @test pyeq (Bool, y, yf)
587- x = [1 ,2 , 3 , 2 , 1 ]
587+ x = [1 , 2 , 3 , 2 , 1 ]
588588 y = pyset (x)
589589 yf = pyfrozenset (x)
590590 @test pyisinstance (y, pybuiltins. set)
649649 x = pytype (pybuiltins. type)
650650 @test pyisinstance (x, pybuiltins. type)
651651 @test pyis (x, pybuiltins. type)
652- x = pytype (" Foo" , (), [" foo" => 1 , " bar" => 2 ])
652+ x = pytype (" Foo" , (), [" foo" => 1 , " bar" => 2 ])
653653 @test pyisinstance (x, pybuiltins. type)
654654 @test pyeq (Bool, x. __name__, " Foo" )
655655 @test pyeq (Bool, x. foo, 1 )
782782 # but now tries to do `1 + [1, 2]` which properly fails
783783 @test_throws PyException [1 2 ; 3 4 ] .+ pylist ([1 , 2 ])
784784 end
785+ @testset " showable" begin
786+ @test showable (MIME (" text/plain" ), Py (nothing ))
787+ @test showable (MIME (" text/plain" ), Py (12 ))
788+ # https://github.com/JuliaPy/PythonCall.jl/issues/522
789+ @test showable (MIME (" text/plain" ), PythonCall. pynew ())
790+ @test ! showable (MIME (" text/html" ), PythonCall. pynew ())
791+ end
792+ @testset " show" begin
793+ @test sprint (show, MIME (" text/plain" ), Py (nothing )) == " Python: None"
794+ @test sprint (show, MIME (" text/plain" ), Py (12 )) == " Python: 12"
795+ # https://github.com/JuliaPy/PythonCall.jl/issues/522
796+ @test sprint (show, MIME (" text/plain" ), PythonCall. pynew ()) == " Python: NULL"
797+ @test_throws MethodError sprint (show, MIME (" text/html" ), PythonCall. pynew ())
798+ end
785799end
786800
787801@testitem " pywith" begin
0 commit comments