Example #1
0
def test_type():
    assert cairo.TextExtents
    assert issubclass(cairo.TextExtents, tuple)

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

    r = cairo.TextExtents(0.0, 0.5, 0.25, 0.75, 0.5, 0.125)
    assert hash(r) == hash(cairo.TextExtents(0.0, 0.5, 0.25, 0.75, 0.5, 0.125))
    assert isinstance(r, tuple)
    assert r == (0.0, 0.5, 0.25, 0.75, 0.5, 0.125)
    assert r == cairo.TextExtents(0.0, 0.5, 0.25, 0.75, 0.5, 0.125)
    assert r[1] == 0.5
    assert r.width == 0.25
    assert r.height == 0.75
    assert r.x_bearing == 0.0
    assert r.y_bearing == 0.5

    with pytest.raises(AttributeError):
        assert r.z

    assert repr(r) == \
        "cairo.TextExtents(x_bearing=0.0, y_bearing=0.5, " \
        "width=0.25, height=0.75, x_advance=0.5, " \
        "y_advance=0.125)"
    assert str(r) == repr(r)
    assert eval(repr(r)) == r
Example #2
0
def test_text_extents(x_bearing, y_bearing, width, height, x_advance,
                      y_advance):
    te = cairo.TextExtents(x_bearing, y_bearing, width, height, x_advance,
                           y_advance)
    assert te.x_bearing == x_bearing
    assert te.y_bearing == y_bearing
    assert te.width == width
    assert te.height == height
    assert te.x_advance == x_advance
    assert te.y_advance == y_advance