|
1 | 1 | @testitem "PyArray" begin
|
| 2 | + x = pyimport("array").array("i", [1,2,3]) |
| 3 | + y = PyArray(x) |
| 4 | + z = PyArray{Cint,1,false,false,Cint}(x) |
| 5 | + @testset "construct" begin |
| 6 | + @test y isa PyArray{Cint,1,true,true,Cint} |
| 7 | + @test z isa PyArray{Cint,1,false,false,Cint} |
| 8 | + @test PythonCall.ispy(y) |
| 9 | + @test PythonCall.ispy(z) |
| 10 | + @test Py(y) === x |
| 11 | + @test Py(z) === x |
| 12 | + end |
| 13 | + @testset "length" begin |
| 14 | + @test length(y) === 3 |
| 15 | + @test length(z) === 3 |
| 16 | + end |
| 17 | + @testset "size" begin |
| 18 | + @test size(y) === (3,) |
| 19 | + @test size(z) === (3,) |
| 20 | + end |
| 21 | + @testset "IndexStyle" begin |
| 22 | + @test Base.IndexStyle(y) === Base.IndexLinear() |
| 23 | + @test Base.IndexStyle(z) === Base.IndexCartesian() |
| 24 | + end |
| 25 | + @testset "strides" begin |
| 26 | + @test strides(y) === (1,) |
| 27 | + @test strides(z) === (1,) |
| 28 | + end |
| 29 | + @testset "getindex" begin |
| 30 | + @test_throws BoundsError y[0] |
| 31 | + @test y[1] == 1 |
| 32 | + @test y[2] == 2 |
| 33 | + @test y[3] == 3 |
| 34 | + @test_throws BoundsError y[4] |
| 35 | + @test_throws BoundsError z[0] |
| 36 | + @test z[1] == 1 |
| 37 | + @test z[2] == 2 |
| 38 | + @test z[3] == 3 |
| 39 | + @test_throws BoundsError z[4] |
| 40 | + end |
| 41 | + @testset "copy" begin |
| 42 | + @test copy(y) == [1, 2, 3] |
| 43 | + @test copy(z) == [1, 2, 3] |
| 44 | + end |
| 45 | + @testset "setindex!" begin |
| 46 | + @test_throws BoundsError y[0] = 0 |
| 47 | + y[2] = 22 |
| 48 | + @test y[2] == 22 |
| 49 | + y[2] = 2 |
| 50 | + @test y[2] == 2 |
| 51 | + @test_throws BoundsError y[4] = 0 |
| 52 | + @test_throws Exception z[0] = 0 |
| 53 | + @test_throws Exception z[1] = 0 |
| 54 | + @test_throws Exception z[2] = 0 |
| 55 | + @test_throws Exception z[3] = 0 |
| 56 | + @test_throws Exception z[4] = 0 |
| 57 | + end |
| 58 | + @testset "mutate" begin |
| 59 | + y[2] = 22 |
| 60 | + @test pyconvert(Int, x[1]) == 22 |
| 61 | + @test y[2] == 22 |
| 62 | + @test z[2] == 22 |
| 63 | + y[2] = 2 |
| 64 | + x[2] = 33 |
| 65 | + @test pyconvert(Int, x[2]) == 33 |
| 66 | + @test y[3] == 33 |
| 67 | + @test z[3] == 33 |
| 68 | + x[2] = 3 |
| 69 | + @test y == [1, 2, 3] |
| 70 | + @test z == [1, 2, 3] |
| 71 | + end |
2 | 72 | end
|
3 | 73 |
|
4 | 74 | @testitem "PyDict" begin
|
|
0 commit comments