| 1 | import cairo |
| 2 | import pytest |
| 3 | |
| 4 | |
| 5 | def test_matrix(): |
| 6 | m = cairo.Matrix() |
| 7 | m.rotate(10) |
| 8 | m.scale(1.5, 2.5) |
| 9 | m.translate(10, 20) |
| 10 | |
| 11 | with pytest.raises(TypeError): |
| 12 | m * 42 |
| 13 | |
| 14 | with pytest.raises(TypeError): |
| 15 | m + 42 |
| 16 | |
| 17 | with pytest.raises(TypeError): |
| 18 | cairo.Matrix(object()) |
| 19 | |
| 20 | assert m != 42 |
| 21 | assert m == m |
| 22 | assert m != cairo.Matrix() |
| 23 | |
| 24 | assert repr(cairo.Matrix()) == "cairo.Matrix(1, 0, 0, 1, 0, 0)" |
| 25 | |
| 26 | |
| 27 | def test_init_rotate(): |
| 28 | r = cairo.Matrix.init_rotate(0) |
| 29 | assert cairo.Matrix() == r |
| 30 | |
| 31 | with pytest.raises(TypeError): |
| 32 | cairo.Matrix.init_rotate(object()) |
| 33 | |
| 34 | |
| 35 | def test_invert(): |
| 36 | m = cairo.Matrix(1, 1) |
| 37 | m.invert() |
| 38 | assert m == cairo.Matrix(1, -1, -0, 1, 0, 0) |
| 39 | |
| 40 | |
| 41 | def test_matrix_properties(): |
| 42 | m = cairo.Matrix(*range(6)) |
| 43 | assert [m.xx, m.yx, m.xy, m.yy, m.x0, m.y0] == list(range(6)) |
| 44 | m.xx = 42 |
| 45 | assert m.xx == 42 |
| 46 | m.scale(2, 2) |
| 47 | assert m.xx == 84 |
| 48 | |
| 49 | |
| 50 | def test_get_item(): |
| 51 | m = cairo.Matrix(1, 2, 3, 4, 5, 6) |
| 52 | for i in range(6): |
| 53 | assert m[i] == i + 1 |
| 54 | with pytest.raises(IndexError): |
| 55 | m[6] |
| 56 | with pytest.raises(IndexError): |
| 57 | m[-1] |
| 58 | |
| 59 | |
| 60 | def test_multiply(): |
| 61 | with pytest.raises(TypeError): |
| 62 | cairo.Matrix().multiply(object()) |
| 63 | |
| 64 | m = cairo.Matrix(1, 1, 0, 1) |
| 65 | assert m.multiply(m) == cairo.Matrix(1, 2, 0, 1, 0, 0) |
| 66 | assert m * m == m.multiply(m) |
| 67 | |
| 68 | |
| 69 | def test_translate(): |
| 70 | m = cairo.Matrix() |
| 71 | m.translate(1, 1) |
| 72 | assert m == cairo.Matrix(1, 0, 0, 1, 1, 1) |
| 73 | with pytest.raises(TypeError): |
| 74 | m.translate(1, object()) |
| 75 | |
| 76 | |
| 77 | def test_rotate(): |
| 78 | m = cairo.Matrix() |
| 79 | with pytest.raises(TypeError): |
| 80 | m.rotate(object()) |
| 81 | |
| 82 | |
| 83 | def test_scale(): |
| 84 | m = cairo.Matrix() |
| 85 | with pytest.raises(TypeError): |
| 86 | m.scale(object()) |
| 87 | m.scale(2, 2) |
| 88 | assert m != cairo.Matrix() |
| 89 | m.scale(0.5, 0.5) |
| 90 | assert m == cairo.Matrix() |
| 91 | |
| 92 | |
| 93 | def test_transform_distance(): |
| 94 | m = cairo.Matrix() |
| 95 | assert m.transform_distance(1, 1) == (1, 1) |
| 96 | with pytest.raises(TypeError): |
| 97 | m.transform_distance(1, object()) |
| 98 | |
| 99 | |
| 100 | def test_transform_point(): |
| 101 | m = cairo.Matrix() |
| 102 | assert m.transform_point(1, 1) == (1, 1) |
| 103 | with pytest.raises(TypeError): |
| 104 | m.transform_point(1, object()) |