Debian Codegraph @

tests/test_path.py

raw symbols SCIP
1 import cairo
2 import pytest
3
4
5 @pytest.fixture
6 def context():
7 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 42, 42)
8 return cairo.Context(surface)
9
10
11 def test_path():
12 assert cairo.Path
13
14 with pytest.raises(TypeError):
15 cairo.Path()
16
17
18 def test_path_str(context):
19 p = context.copy_path()
20 assert isinstance(p, cairo.Path)
21 assert str(p) == ""
22
23 context.line_to(1, 2)
24 p = context.copy_path()
25 assert str(p) == "move_to 1.000000 2.000000"
26
27 context.line_to(1, 2)
28 p = context.copy_path()
29 assert str(p) == "move_to 1.000000 2.000000\nline_to 1.000000 2.000000"
30
31 context.new_path()
32 context.curve_to(0, 1, 2, 3, 4, 5)
33 p = context.copy_path()
34 assert str(p) == (
35 "move_to 0.000000 1.000000\n"
36 "curve_to 0.000000 1.000000 2.000000 3.000000 4.000000 5.000000")
37
38 context.new_path()
39 context.line_to(1, 2)
40 context.close_path()
41 p = context.copy_path()
42 assert str(p) == (
43 "move_to 1.000000 2.000000\n"
44 "close path\n"
45 "move_to 1.000000 2.000000")
46
47
48 def test_path_compare_hash(context):
49 p = context.copy_path()
50 assert p == p
51 hash(p)
52 assert not p != p
53 assert p != object()
54 assert not p < p
55 assert p <= p
56 assert p >= p
57 assert not p > p
58
59
60 def test_path_iter(context):
61 context.line_to(1, 2)
62 context.line_to(2, 3)
63 context.curve_to(0, 1, 2, 3, 4, 5)
64 context.close_path()
65 p = context.copy_path()
66 i = iter(p)
67 assert list(i) == [
68 (0, (1.0, 2.0)),
69 (1, (2.0, 3.0)),
70 (2, (0.0, 1.0, 2.0, 3.0, 4.0, 5.0)),
71 (3, ()),
72 (0, (1.0, 2.0)),
73 ]