File: test_path.py

package info (click to toggle)
pycairo 1.27.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,984 kB
  • sloc: ansic: 8,873; python: 3,688; makefile: 32; sh: 4
file content (73 lines) | stat: -rw-r--r-- 1,638 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import cairo
import pytest


@pytest.fixture
def context():
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 42, 42)
    return cairo.Context(surface)


def test_path():
    assert cairo.Path

    with pytest.raises(TypeError):
        cairo.Path()


def test_path_str(context):
    p = context.copy_path()
    assert isinstance(p, cairo.Path)
    assert str(p) == ""

    context.line_to(1, 2)
    p = context.copy_path()
    assert str(p) == "move_to 1.000000 2.000000"

    context.line_to(1, 2)
    p = context.copy_path()
    assert str(p) == "move_to 1.000000 2.000000\nline_to 1.000000 2.000000"

    context.new_path()
    context.curve_to(0, 1, 2, 3, 4, 5)
    p = context.copy_path()
    assert str(p) == (
        "move_to 0.000000 1.000000\n"
        "curve_to 0.000000 1.000000 2.000000 3.000000 4.000000 5.000000")

    context.new_path()
    context.line_to(1, 2)
    context.close_path()
    p = context.copy_path()
    assert str(p) == (
        "move_to 1.000000 2.000000\n"
        "close path\n"
        "move_to 1.000000 2.000000")


def test_path_compare_hash(context):
    p = context.copy_path()
    assert p == p
    hash(p)
    assert not p != p
    assert p != object()
    assert not p < p
    assert p <= p
    assert p >= p
    assert not p > p


def test_path_iter(context):
    context.line_to(1, 2)
    context.line_to(2, 3)
    context.curve_to(0, 1, 2, 3, 4, 5)
    context.close_path()
    p = context.copy_path()
    i = iter(p)
    assert list(i) == [
        (0, (1.0, 2.0)),
        (1, (2.0, 3.0)),
        (2, (0.0, 1.0, 2.0, 3.0, 4.0, 5.0)),
        (3, ()),
        (0, (1.0, 2.0)),
    ]