| 1 | import cairo |
| 2 | import pytest |
| 3 | |
| 4 | |
| 5 | def test_region(): |
| 6 | with pytest.raises(TypeError): |
| 7 | cairo.Region(object()) |
| 8 | |
| 9 | with pytest.raises(TypeError): |
| 10 | cairo.Region(object(), object()) |
| 11 | |
| 12 | with pytest.raises(TypeError): |
| 13 | cairo.Region([object()]) |
| 14 | |
| 15 | |
| 16 | def test_get_rectangle(): |
| 17 | rect = cairo.RectangleInt(0, 0, 10, 10) |
| 18 | r = cairo.Region(rect) |
| 19 | with pytest.raises(ValueError): |
| 20 | r.get_rectangle(-1) |
| 21 | with pytest.raises(ValueError): |
| 22 | r.get_rectangle(1) |
| 23 | assert r.get_rectangle(0) == rect |
| 24 | with pytest.raises(TypeError): |
| 25 | r.get_rectangle(object()) |
| 26 | |
| 27 | |
| 28 | def test_contains_point(): |
| 29 | rect = cairo.RectangleInt(0, 0, 10, 10) |
| 30 | r = cairo.Region(rect) |
| 31 | assert r.contains_point(0, 0) |
| 32 | assert not r.contains_point(0, 20) |
| 33 | with pytest.raises(TypeError): |
| 34 | r.contains_point(0, object()) |
| 35 | |
| 36 | |
| 37 | def test_intersect(): |
| 38 | rect = cairo.RectangleInt(0, 0, 10, 10) |
| 39 | r = cairo.Region(rect) |
| 40 | r.intersect(r) |
| 41 | r.intersect(rect) |
| 42 | with pytest.raises(TypeError): |
| 43 | r.intersect(object()) |
| 44 | with pytest.raises(TypeError): |
| 45 | r.intersect() |
| 46 | |
| 47 | assert r.__eq__(object()) == NotImplemented |
| 48 | assert rect.__eq__(object()) == NotImplemented |
| 49 | |
| 50 | |
| 51 | def test_equal(): |
| 52 | rect = cairo.RectangleInt(0, 0, 10, 10) |
| 53 | r = cairo.Region(rect) |
| 54 | assert r.equal(r) |
| 55 | with pytest.raises(TypeError): |
| 56 | r.equal(object()) |
| 57 | with pytest.raises(TypeError): |
| 58 | r.equal() |
| 59 | |
| 60 | |
| 61 | def test_subtract(): |
| 62 | rect = cairo.RectangleInt(0, 0, 10, 10) |
| 63 | r = cairo.Region(rect) |
| 64 | r.subtract(r) |
| 65 | with pytest.raises(TypeError): |
| 66 | r.subtract(object()) |
| 67 | with pytest.raises(TypeError): |
| 68 | r.subtract() |
| 69 | |
| 70 | |
| 71 | def test_union(): |
| 72 | rect = cairo.RectangleInt(0, 0, 10, 10) |
| 73 | r = cairo.Region(rect) |
| 74 | r.union(r) |
| 75 | r.union(rect) |
| 76 | with pytest.raises(TypeError): |
| 77 | r.union(object()) |
| 78 | with pytest.raises(TypeError): |
| 79 | r.union() |
| 80 | |
| 81 | |
| 82 | def test_xor(): |
| 83 | rect = cairo.RectangleInt(0, 0, 10, 10) |
| 84 | r = cairo.Region(rect) |
| 85 | r.xor(r) |
| 86 | r.xor(rect) |
| 87 | with pytest.raises(TypeError): |
| 88 | r.xor(object()) |
| 89 | with pytest.raises(TypeError): |
| 90 | r.xor() |
| 91 | |
| 92 | |
| 93 | def test_translate(): |
| 94 | r = cairo.Region() |
| 95 | r.translate(1, 1) |
| 96 | with pytest.raises(TypeError): |
| 97 | r.translate(1, object()) |
| 98 | |
| 99 | |
| 100 | def test_region_contains_rectangle(): |
| 101 | rect = cairo.RectangleInt(1, 2, 10, 13) |
| 102 | region = cairo.Region() |
| 103 | assert region.contains_rectangle(rect) == cairo.RegionOverlap.OUT |
| 104 | assert isinstance(region.contains_rectangle(rect), cairo.RegionOverlap) |
| 105 | with pytest.raises(TypeError): |
| 106 | region.contains_rectangle(object()) |
| 107 | |
| 108 | |
| 109 | def test_region_cmp_hash(): |
| 110 | region = cairo.Region() |
| 111 | other = cairo.Region() |
| 112 | differ = cairo.Region(cairo.RectangleInt(0, 0, 10, 10)) |
| 113 | with pytest.raises(TypeError): |
| 114 | hash(region) |
| 115 | assert region == region |
| 116 | assert region == other |
| 117 | assert not region != other |
| 118 | assert region != differ |
| 119 | |
| 120 | with pytest.raises(TypeError): |
| 121 | region < region |
| 122 | |
| 123 | with pytest.raises(TypeError): |
| 124 | region > region |
| 125 | |
| 126 | rect = cairo.RectangleInt(1, 2, 10, 13) |
| 127 | same = cairo.RectangleInt(1, 2, 10, 13) |
| 128 | other = cairo.RectangleInt(2, 2, 10, 13) |
| 129 | with pytest.raises(TypeError): |
| 130 | hash(rect) |
| 131 | |
| 132 | assert rect == same |
| 133 | assert rect != other |
| 134 | |
| 135 | with pytest.raises(TypeError): |
| 136 | rect < same |
| 137 | |
| 138 | with pytest.raises(TypeError): |
| 139 | rect > same |