130
130
@test pylen (x) == 0
131
131
end
132
132
@testset " pydir" begin
133
- x = pytype (" Foo" , (), [" foo" => 1 , " bar" => 2 ])()
133
+ x = pytype (" Foo" , (), [" foo" => 1 , " bar" => 2 ])()
134
134
d = pydir (x)
135
135
@test pycontains (d, " __class__" )
136
136
@test pycontains (d, " foo" )
256
256
end
257
257
@testset " pyinv" begin
258
258
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 ))
260
260
end
261
261
end
262
262
@testset " pyindex" begin
@@ -267,21 +267,21 @@ end
267
267
@testset " pyadd" begin
268
268
for x in - 2 : 2
269
269
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))
271
271
end
272
272
end
273
273
end
274
274
@testset " pysub" begin
275
275
for x in - 2 : 2
276
276
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))
278
278
end
279
279
end
280
280
end
281
281
@testset " pymul" begin
282
282
for x in - 2 : 2
283
283
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))
285
285
end
286
286
end
287
287
end
299
299
if y == 0
300
300
@test_throws PyException pytruediv (pyint (x), pyint (y))
301
301
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))
303
303
end
304
304
end
305
305
end
@@ -409,15 +409,15 @@ end
409
409
@test pyeq (Bool, sys. __name__, " sys" )
410
410
@test pyeq (Bool, os. __name__, " os" )
411
411
sysos = pyimport (" sys" , " os" )
412
- @test sysos isa Tuple{Py, Py}
412
+ @test sysos isa Tuple{Py,Py}
413
413
@test pyis (sysos[1 ], sys)
414
414
@test pyis (sysos[2 ], os)
415
415
ver = pyimport (" sys" => " version" )
416
416
@test pyis (ver, sys. version)
417
417
path = pyimport (" sys" => " path" )
418
418
@test pyis (path, sys. path)
419
419
verpath = pyimport (" sys" => (" version" , " path" ))
420
- @test verpath isa Tuple{Py, Py}
420
+ @test verpath isa Tuple{Py,Py}
421
421
@test pyis (verpath[1 ], ver)
422
422
@test pyis (verpath[2 ], path)
423
423
end
@@ -438,12 +438,12 @@ end
438
438
end
439
439
440
440
@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 ]))
443
443
@test pyeq (Bool, pybytes (b " foo" ), pystr (" foo" ). encode (" ascii" ))
444
444
@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 ]
447
447
@test pybytes (Base. CodeUnits, pystr (" foo" ). encode (" ascii" )) == b " foo"
448
448
@test pybytes (Base. CodeUnits{UInt8,String}, pystr (" bar" ). encode (" ascii" )) == b " bar"
449
449
end
@@ -452,36 +452,36 @@ end
452
452
z = pytuple ()
453
453
@test pyisinstance (z, pybuiltins. tuple)
454
454
@test pylen (z) == 0
455
- x = pytuple ((1 ,2 , 3 ))
455
+ x = pytuple ((1 , 2 , 3 ))
456
456
@test pyisinstance (x, pybuiltins. tuple)
457
457
@test pylen (x) == 3
458
458
@test pyeq (Bool, pygetitem (x, 0 ), 1 )
459
459
@test pyeq (Bool, pygetitem (x, 1 ), 2 )
460
460
@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)
465
465
end
466
466
467
467
@testitem " list" begin
468
468
z = pylist ()
469
469
@test pyisinstance (z, pybuiltins. list)
470
470
@test pylen (z) == 0
471
- x = pylist ((1 ,2 , 3 ))
471
+ x = pylist ((1 , 2 , 3 ))
472
472
@test pyisinstance (x, pybuiltins. list)
473
473
@test pylen (x) == 3
474
474
@test pyeq (Bool, pygetitem (x, 0 ), 1 )
475
475
@test pyeq (Bool, pygetitem (x, 1 ), 2 )
476
476
@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 ]))))
485
485
end
486
486
487
487
@testitem " dict" begin
493
493
@test pylen (x) == 2
494
494
@test pyeq (Bool, pygetitem (x, " foo" ), 1 )
495
495
@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)
499
499
@test pyeq (Bool, pydict ((foo= 1 , bar= 2 )), x)
500
500
@test pyeq (Bool, pydict (x), x)
501
501
end
508
508
@test pyis (pybool (- 1.2 ), pybuiltins. True)
509
509
@test pyis (pybool (pybuiltins. None), pybuiltins. False)
510
510
@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)
512
512
end
513
513
514
514
@testitem " int" begin
546
546
y = pyfloat (x)
547
547
@test pyisinstance (y, pybuiltins. float)
548
548
@test pyeq (Bool, y, pytruediv (1 , 4 ))
549
- x = 1 // 4
549
+ x = 1 // 4
550
550
y = pyfloat (x)
551
551
@test pyisinstance (y, pybuiltins. float)
552
552
@test pyeq (Bool, y, pyfloat (float (x)))
584
584
@test pyisinstance (yf, pybuiltins. frozenset)
585
585
@test pylen (yf) == 0
586
586
@test pyeq (Bool, y, yf)
587
- x = [1 ,2 , 3 , 2 , 1 ]
587
+ x = [1 , 2 , 3 , 2 , 1 ]
588
588
y = pyset (x)
589
589
yf = pyfrozenset (x)
590
590
@test pyisinstance (y, pybuiltins. set)
649
649
x = pytype (pybuiltins. type)
650
650
@test pyisinstance (x, pybuiltins. type)
651
651
@test pyis (x, pybuiltins. type)
652
- x = pytype (" Foo" , (), [" foo" => 1 , " bar" => 2 ])
652
+ x = pytype (" Foo" , (), [" foo" => 1 , " bar" => 2 ])
653
653
@test pyisinstance (x, pybuiltins. type)
654
654
@test pyeq (Bool, x. __name__, " Foo" )
655
655
@test pyeq (Bool, x. foo, 1 )
782
782
# but now tries to do `1 + [1, 2]` which properly fails
783
783
@test_throws PyException [1 2 ; 3 4 ] .+ pylist ([1 , 2 ])
784
784
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
785
799
end
786
800
787
801
@testitem " pywith" begin
0 commit comments