tests: coverage
This commit is contained in:
parent
e16ee1af75
commit
e8daeb58d1
|
@ -19,6 +19,8 @@
|
|||
MANIFEST
|
||||
dist
|
||||
.hypothesis
|
||||
*.pyd
|
||||
*.dll
|
||||
|
||||
# image files
|
||||
*.pdf
|
||||
|
|
|
@ -618,6 +618,10 @@ font_options_dealloc(PycairoFontOptions *o) {
|
|||
|
||||
static PyObject *
|
||||
font_options_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
|
||||
|
||||
if (!PyArg_ParseTuple (args, ":FontOptions.__new__"))
|
||||
return NULL;
|
||||
|
||||
return PycairoFontOptions_FromFontOptions (cairo_font_options_create());
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,6 @@ import cairo
|
|||
import pytest
|
||||
import py.test as test
|
||||
|
||||
try:
|
||||
long
|
||||
except NameError:
|
||||
long = int
|
||||
|
||||
|
||||
def test_version():
|
||||
cairo.cairo_version()
|
||||
|
@ -119,65 +114,6 @@ def test_context():
|
|||
ctx.paint()
|
||||
|
||||
|
||||
def test_matrix():
|
||||
m = cairo.Matrix()
|
||||
m.rotate(10)
|
||||
m.scale(1.5, 2.5)
|
||||
m.translate(10, 20)
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
m * 42
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
m + 42
|
||||
|
||||
assert m != 42
|
||||
assert m == m
|
||||
assert m != cairo.Matrix()
|
||||
|
||||
|
||||
def test_matrix_properties():
|
||||
m = cairo.Matrix(*range(6))
|
||||
assert [m.xx, m.yx, m.xy, m.yy, m.x0, m.y0] == list(range(6))
|
||||
m.xx = 42
|
||||
assert m.xx == 42
|
||||
m.scale(2, 2)
|
||||
assert m.xx == 84
|
||||
|
||||
|
||||
def test_pattern():
|
||||
# TypeError: The Pattern type cannot be instantiated
|
||||
test.raises(TypeError, "p = cairo.Pattern()")
|
||||
|
||||
r, g, b, a = 0.1, 0.2, 0.3, 0.4
|
||||
p = cairo.SolidPattern(r, g, b, a)
|
||||
assert p.get_rgba() == (r, g, b, a)
|
||||
|
||||
# SurfacePattern
|
||||
|
||||
# TypeError: The Gradient type cannot be instantiated
|
||||
test.raises(TypeError, "p = cairo.Gradient()")
|
||||
|
||||
x0, y0, x1, y1 = 0.0, 0.0, 0.0, 1.0
|
||||
p = cairo.LinearGradient(x0, y0, x1, y1)
|
||||
assert p.get_linear_points() == (x0, y0, x1, y1)
|
||||
p.add_color_stop_rgba(1, 0, 0, 0, 1)
|
||||
p.add_color_stop_rgba(0, 1, 1, 1, 1)
|
||||
|
||||
cx0, cy0, radius0, cx1, cy1, radius1 = 1.0, 1.0, 1.0, 2.0, 2.0, 1.0
|
||||
p = cairo.RadialGradient(cx0, cy0, radius0, cx1, cy1, radius1)
|
||||
assert p.get_radial_circles() == (cx0, cy0, radius0, cx1, cy1, radius1)
|
||||
p.add_color_stop_rgba(0, 1, 1, 1, 1)
|
||||
p.add_color_stop_rgba(1, 0, 0, 0, 1)
|
||||
|
||||
|
||||
def test_pattern_filter():
|
||||
pattern = cairo.SolidPattern(1, 2, 3)
|
||||
assert pattern.get_filter() == cairo.FILTER_GOOD
|
||||
pattern.set_filter(cairo.FILTER_NEAREST)
|
||||
assert pattern.get_filter() == cairo.FILTER_NEAREST
|
||||
|
||||
|
||||
def test_surface():
|
||||
# TypeError: The Surface type cannot be instantiated
|
||||
test.raises(TypeError, "s = cairo.Surface()")
|
||||
|
@ -439,55 +375,6 @@ def test_supports_mime_type():
|
|||
assert not surface.supports_mime_type("nope")
|
||||
|
||||
|
||||
def test_font_options_copy_equal():
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1)
|
||||
font_options = surface.get_font_options()
|
||||
font_options.set_hint_metrics(cairo.HINT_METRICS_DEFAULT)
|
||||
new = font_options.copy()
|
||||
assert font_options.equal(new)
|
||||
assert new.get_hint_metrics() == cairo.HINT_METRICS_DEFAULT
|
||||
font_options.set_hint_metrics(cairo.HINT_METRICS_ON)
|
||||
assert not font_options.equal(new)
|
||||
assert new.get_hint_metrics() == cairo.HINT_METRICS_DEFAULT
|
||||
|
||||
|
||||
def test_font_options_hash():
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1)
|
||||
font_options = surface.get_font_options()
|
||||
assert font_options.hash() == font_options.hash()
|
||||
assert isinstance(font_options.hash(), long)
|
||||
|
||||
|
||||
def test_font_options_merge():
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1)
|
||||
font_options = surface.get_font_options()
|
||||
font_options.set_hint_metrics(cairo.HINT_METRICS_DEFAULT)
|
||||
new = font_options.copy()
|
||||
new.set_hint_metrics(cairo.HINT_METRICS_ON)
|
||||
font_options.merge(new)
|
||||
assert font_options.get_hint_metrics() == cairo.HINT_METRICS_ON
|
||||
|
||||
|
||||
def test_font_options_hashable_protocol():
|
||||
# make sure __eq__ and __ne__ work
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1)
|
||||
font_options = surface.get_font_options()
|
||||
assert font_options == font_options.copy()
|
||||
assert not font_options != font_options.copy()
|
||||
font_options.set_hint_metrics(cairo.HINT_METRICS_DEFAULT)
|
||||
different = font_options.copy()
|
||||
different.set_hint_metrics(cairo.HINT_METRICS_ON)
|
||||
assert font_options != different
|
||||
assert not font_options == different
|
||||
assert font_options != object()
|
||||
|
||||
# make sure the other operators are undefined
|
||||
if sys.version_info[0] == 3:
|
||||
with pytest.raises(TypeError):
|
||||
font_options < font_options
|
||||
assert font_options.__gt__(font_options) is NotImplemented
|
||||
|
||||
|
||||
def test_surface_mime_data_for_pdf():
|
||||
jpeg_bytes = zlib.decompress(base64.b64decode(
|
||||
b'eJz7f+P/AwYBLzdPNwZGRkYGDyBk+H+bwRnEowj8P8TAzcHACDJHkOH/EQYRIBsV'
|
||||
|
|
|
@ -1,7 +1,129 @@
|
|||
import sys
|
||||
|
||||
import cairo
|
||||
import pytest
|
||||
|
||||
|
||||
try:
|
||||
long
|
||||
except NameError:
|
||||
long = int
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def font_options():
|
||||
surface = cairo.ImageSurface(0, 10, 10)
|
||||
return surface.get_font_options()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def font_face():
|
||||
surface = cairo.ImageSurface(0, 10, 10)
|
||||
context = cairo.Context(surface)
|
||||
return context.get_font_face()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def scaled_font(font_face, font_options):
|
||||
return cairo.ScaledFont(
|
||||
font_face, cairo.Matrix(), cairo.Matrix(), font_options)
|
||||
|
||||
|
||||
def test_font_options():
|
||||
assert isinstance(cairo.FontOptions(), cairo.FontOptions)
|
||||
with pytest.raises(TypeError):
|
||||
cairo.FontOptions(object())
|
||||
|
||||
|
||||
def test_font_options_copy_equal():
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1)
|
||||
font_options = surface.get_font_options()
|
||||
font_options.set_hint_metrics(cairo.HINT_METRICS_DEFAULT)
|
||||
new = font_options.copy()
|
||||
assert font_options.equal(new)
|
||||
assert new.get_hint_metrics() == cairo.HINT_METRICS_DEFAULT
|
||||
font_options.set_hint_metrics(cairo.HINT_METRICS_ON)
|
||||
assert not font_options.equal(new)
|
||||
assert new.get_hint_metrics() == cairo.HINT_METRICS_DEFAULT
|
||||
with pytest.raises(TypeError):
|
||||
font_options.equal(object())
|
||||
|
||||
|
||||
def test_font_options_hash():
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1)
|
||||
font_options = surface.get_font_options()
|
||||
assert font_options.hash() == font_options.hash()
|
||||
assert isinstance(font_options.hash(), long)
|
||||
|
||||
|
||||
def test_font_options_merge():
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1)
|
||||
font_options = surface.get_font_options()
|
||||
font_options.set_hint_metrics(cairo.HINT_METRICS_DEFAULT)
|
||||
new = font_options.copy()
|
||||
new.set_hint_metrics(cairo.HINT_METRICS_ON)
|
||||
font_options.merge(new)
|
||||
assert font_options.get_hint_metrics() == cairo.HINT_METRICS_ON
|
||||
with pytest.raises(TypeError):
|
||||
font_options.merge(object())
|
||||
|
||||
|
||||
def test_font_options_hashable_protocol():
|
||||
# make sure __eq__ and __ne__ work
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1)
|
||||
font_options = surface.get_font_options()
|
||||
assert font_options == font_options.copy()
|
||||
assert not font_options != font_options.copy()
|
||||
font_options.set_hint_metrics(cairo.HINT_METRICS_DEFAULT)
|
||||
different = font_options.copy()
|
||||
different.set_hint_metrics(cairo.HINT_METRICS_ON)
|
||||
assert font_options != different
|
||||
assert not font_options == different
|
||||
assert font_options != object()
|
||||
|
||||
# make sure the other operators are undefined
|
||||
if sys.version_info[0] == 3:
|
||||
with pytest.raises(TypeError):
|
||||
font_options < font_options
|
||||
assert font_options.__gt__(font_options) is NotImplemented
|
||||
|
||||
|
||||
def test_font_options_set_antialias(font_options):
|
||||
font_options.set_antialias(cairo.Antialias.GRAY)
|
||||
assert font_options.get_antialias() == cairo.Antialias.GRAY
|
||||
with pytest.raises(TypeError):
|
||||
font_options.set_antialias(object())
|
||||
|
||||
|
||||
def test_font_options_set_hint_metrics(font_options):
|
||||
font_options.set_hint_metrics(cairo.HintMetrics.OFF)
|
||||
assert font_options.get_hint_metrics() == cairo.HintMetrics.OFF
|
||||
with pytest.raises(TypeError):
|
||||
font_options.set_hint_metrics(object())
|
||||
|
||||
|
||||
def test_font_options_set_hint_style(font_options):
|
||||
font_options.set_hint_style(cairo.HintStyle.SLIGHT)
|
||||
assert font_options.get_hint_style() == cairo.HintStyle.SLIGHT
|
||||
with pytest.raises(TypeError):
|
||||
font_options.set_hint_style(object())
|
||||
|
||||
|
||||
def test_font_options_set_subpixel_order(font_options):
|
||||
font_options.set_subpixel_order(cairo.SubpixelOrder.VRGB)
|
||||
assert font_options.get_subpixel_order() == cairo.SubpixelOrder.VRGB
|
||||
with pytest.raises(TypeError):
|
||||
font_options.set_subpixel_order(object())
|
||||
|
||||
|
||||
def test_font_face(font_face):
|
||||
with pytest.raises(TypeError):
|
||||
cairo.FontFace()
|
||||
|
||||
assert font_face == font_face
|
||||
assert font_face != object()
|
||||
|
||||
|
||||
def test_font_face_cmp_hash():
|
||||
surface = cairo.ImageSurface(0, 10, 10)
|
||||
context = cairo.Context(surface)
|
||||
|
@ -24,6 +146,48 @@ def test_font_face_cmp_hash():
|
|||
hash(fo)
|
||||
|
||||
|
||||
def test_scaled_font(scaled_font):
|
||||
with pytest.raises(TypeError):
|
||||
cairo.ScaledFont()
|
||||
|
||||
assert scaled_font == scaled_font
|
||||
assert scaled_font != object()
|
||||
|
||||
|
||||
def test_scaled_font_extents(scaled_font):
|
||||
assert isinstance(scaled_font.extents(), tuple)
|
||||
|
||||
|
||||
def test_scaled_font_get_font_face(scaled_font):
|
||||
assert isinstance(scaled_font.get_font_face(), cairo.FontFace)
|
||||
|
||||
|
||||
def test_scaled_font_get_scale_matrix(scaled_font):
|
||||
assert isinstance(scaled_font.get_scale_matrix(), cairo.Matrix)
|
||||
|
||||
|
||||
def test_scaled_font_text_extents(scaled_font):
|
||||
with pytest.raises(TypeError):
|
||||
scaled_font.text_extents(object())
|
||||
|
||||
|
||||
def test_scaled_font_glyph_extents(scaled_font):
|
||||
with pytest.raises(TypeError):
|
||||
scaled_font.glyph_extents(object())
|
||||
with pytest.raises(TypeError):
|
||||
scaled_font.glyph_extents([object()])
|
||||
|
||||
|
||||
def test_toy_font_face():
|
||||
with pytest.raises(TypeError):
|
||||
cairo.ToyFontFace(object())
|
||||
|
||||
|
||||
def test_toy_font_get_family():
|
||||
font_face = cairo.ToyFontFace("")
|
||||
assert isinstance(font_face.get_family(), str)
|
||||
|
||||
|
||||
def test_toy_font_get_slant():
|
||||
font_face = cairo.ToyFontFace("")
|
||||
assert font_face.get_slant() == cairo.FontSlant.NORMAL
|
||||
|
@ -36,12 +200,6 @@ def test_toy_font_get_weight():
|
|||
assert isinstance(font_face.get_weight(), cairo.FontWeight)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def font_options():
|
||||
surface = cairo.ImageSurface(0, 10, 10)
|
||||
return surface.get_font_options()
|
||||
|
||||
|
||||
def test_font_options_get_antialias(font_options):
|
||||
assert font_options.get_antialias() == cairo.Antialias.DEFAULT
|
||||
assert isinstance(font_options.get_antialias(), cairo.Antialias)
|
||||
|
@ -103,3 +261,6 @@ def test_scaled_font_text_to_glyphs():
|
|||
assert len(glyphs) == 3
|
||||
assert glyphs[0] != glyphs[1]
|
||||
assert len(clusters) == 3
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
sf.text_to_glyphs(object())
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
import cairo
|
||||
import pytest
|
||||
|
||||
|
||||
def test_matrix():
|
||||
m = cairo.Matrix()
|
||||
m.rotate(10)
|
||||
m.scale(1.5, 2.5)
|
||||
m.translate(10, 20)
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
m * 42
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
m + 42
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
cairo.Matrix(object())
|
||||
|
||||
assert m != 42
|
||||
assert m == m
|
||||
assert m != cairo.Matrix()
|
||||
|
||||
assert repr(cairo.Matrix()) == "cairo.Matrix(1, 0, 0, 1, 0, 0)"
|
||||
|
||||
|
||||
def test_init_rotate():
|
||||
r = cairo.Matrix.init_rotate(0)
|
||||
assert cairo.Matrix() == r
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
cairo.Matrix.init_rotate(object())
|
||||
|
||||
|
||||
def test_invert():
|
||||
m = cairo.Matrix(1, 1)
|
||||
m.invert()
|
||||
assert m == cairo.Matrix(1, -1, -0, 1, 0, 0)
|
||||
|
||||
|
||||
def test_matrix_properties():
|
||||
m = cairo.Matrix(*range(6))
|
||||
assert [m.xx, m.yx, m.xy, m.yy, m.x0, m.y0] == list(range(6))
|
||||
m.xx = 42
|
||||
assert m.xx == 42
|
||||
m.scale(2, 2)
|
||||
assert m.xx == 84
|
||||
|
||||
|
||||
def test_get_item():
|
||||
m = cairo.Matrix(1, 2, 3, 4, 5, 6)
|
||||
for i in range(6):
|
||||
assert m[i] == i + 1
|
||||
with pytest.raises(IndexError):
|
||||
m[6]
|
||||
with pytest.raises(IndexError):
|
||||
m[-1]
|
||||
|
||||
|
||||
def test_multiply():
|
||||
with pytest.raises(TypeError):
|
||||
cairo.Matrix().multiply(object())
|
||||
|
||||
m = cairo.Matrix(1, 1, 0, 1)
|
||||
assert m.multiply(m) == cairo.Matrix(1, 2, 0, 1, 0, 0)
|
||||
assert m * m == m.multiply(m)
|
||||
|
||||
|
||||
def test_translate():
|
||||
m = cairo.Matrix()
|
||||
m.translate(1, 1)
|
||||
assert m == cairo.Matrix(1, 0, 0, 1, 1, 1)
|
||||
with pytest.raises(TypeError):
|
||||
cairo.Matrix.translate(1, object())
|
||||
|
||||
|
||||
def test_rotate():
|
||||
m = cairo.Matrix()
|
||||
with pytest.raises(TypeError):
|
||||
m.rotate(object())
|
||||
|
||||
|
||||
def test_scale():
|
||||
m = cairo.Matrix()
|
||||
with pytest.raises(TypeError):
|
||||
m.scale(object())
|
||||
m.scale(2, 2)
|
||||
assert m != cairo.Matrix()
|
||||
m.scale(0.5, 0.5)
|
||||
assert m == cairo.Matrix()
|
||||
|
||||
|
||||
def test_transform_distance():
|
||||
m = cairo.Matrix()
|
||||
assert m.transform_distance(1, 1) == (1, 1)
|
||||
with pytest.raises(TypeError):
|
||||
m.transform_distance(1, object())
|
||||
|
||||
|
||||
def test_transform_point():
|
||||
m = cairo.Matrix()
|
||||
assert m.transform_point(1, 1) == (1, 1)
|
||||
with pytest.raises(TypeError):
|
||||
m.transform_point(1, object())
|
|
@ -7,6 +7,9 @@ def test_raster_source():
|
|||
assert isinstance(pattern, cairo.RasterSourcePattern)
|
||||
assert issubclass(cairo.RasterSourcePattern, cairo.Pattern)
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
cairo.RasterSourcePattern(object())
|
||||
|
||||
was_called = []
|
||||
|
||||
def acquire_callback(target, extents):
|
||||
|
@ -23,6 +26,9 @@ def test_raster_source():
|
|||
was_called.append("release")
|
||||
return None
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
pattern.set_acquire()
|
||||
|
||||
pattern.set_acquire(None, release_callback)
|
||||
assert pattern.get_acquire() == (None, release_callback)
|
||||
|
||||
|
@ -68,6 +74,16 @@ def test_get_filter():
|
|||
assert pattern.get_filter() == cairo.Filter.GOOD
|
||||
|
||||
|
||||
def test_linear_gradient():
|
||||
with pytest.raises(TypeError):
|
||||
cairo.LinearGradient()
|
||||
|
||||
|
||||
def test_radial_gradient():
|
||||
with pytest.raises(TypeError):
|
||||
cairo.RadialGradient()
|
||||
|
||||
|
||||
def test_gradient_get_color_stops():
|
||||
pattern = cairo.LinearGradient(1, 2, 4, 5)
|
||||
assert pattern.get_color_stops_rgba() == []
|
||||
|
@ -78,10 +94,24 @@ def test_gradient_get_color_stops():
|
|||
[(0.125, 0.25, 0.5, 0.75, 1.0), (1.0, 0.75, 0.5, 0.25, 0.125)]
|
||||
|
||||
|
||||
def test_gradient_add_color_stop_rgb():
|
||||
pattern = cairo.LinearGradient(1, 2, 4, 5)
|
||||
with pytest.raises(TypeError):
|
||||
pattern.add_color_stop_rgb()
|
||||
|
||||
|
||||
def test_gradient_add_color_stop_rgba():
|
||||
pattern = cairo.LinearGradient(1, 2, 4, 5)
|
||||
with pytest.raises(TypeError):
|
||||
pattern.add_color_stop_rgba()
|
||||
|
||||
|
||||
def test_mesh_pattern():
|
||||
mesh = cairo.MeshPattern()
|
||||
assert isinstance(mesh, cairo.MeshPattern)
|
||||
assert issubclass(cairo.MeshPattern, cairo.Pattern)
|
||||
with pytest.raises(TypeError):
|
||||
cairo.MeshPattern(object())
|
||||
|
||||
|
||||
def test_mesh_pattern_example1():
|
||||
|
@ -114,6 +144,60 @@ def test_mesh_pattern_example1():
|
|||
pattern.get_path(9)
|
||||
|
||||
|
||||
def test_mesh_pattern_curve_to():
|
||||
pattern = cairo.MeshPattern()
|
||||
with pytest.raises(TypeError):
|
||||
pattern.curve_to(object())
|
||||
|
||||
|
||||
def test_mesh_pattern_get_control_point():
|
||||
pattern = cairo.MeshPattern()
|
||||
with pytest.raises(TypeError):
|
||||
pattern.get_control_point(object())
|
||||
|
||||
|
||||
def test_mesh_pattern_get_corner_color_rgba():
|
||||
pattern = cairo.MeshPattern()
|
||||
with pytest.raises(TypeError):
|
||||
pattern.get_corner_color_rgba(object())
|
||||
|
||||
|
||||
def test_mesh_pattern_get_path():
|
||||
pattern = cairo.MeshPattern()
|
||||
with pytest.raises(TypeError):
|
||||
pattern.get_path(object())
|
||||
|
||||
|
||||
def test_mesh_pattern_line_to():
|
||||
pattern = cairo.MeshPattern()
|
||||
with pytest.raises(TypeError):
|
||||
pattern.line_to(object())
|
||||
|
||||
|
||||
def test_mesh_pattern_move_to():
|
||||
pattern = cairo.MeshPattern()
|
||||
with pytest.raises(TypeError):
|
||||
pattern.move_to(object())
|
||||
|
||||
|
||||
def test_mesh_pattern_set_control_point():
|
||||
pattern = cairo.MeshPattern()
|
||||
with pytest.raises(TypeError):
|
||||
pattern.set_control_point(object())
|
||||
|
||||
|
||||
def test_mesh_pattern_set_corner_color_rgb():
|
||||
pattern = cairo.MeshPattern()
|
||||
with pytest.raises(TypeError):
|
||||
pattern.set_corner_color_rgb(object())
|
||||
|
||||
|
||||
def test_mesh_pattern_set_corner_color_rgba():
|
||||
pattern = cairo.MeshPattern()
|
||||
with pytest.raises(TypeError):
|
||||
pattern.set_corner_color_rgba(object())
|
||||
|
||||
|
||||
def test_mesh_pattern_example2():
|
||||
pattern = cairo.MeshPattern()
|
||||
pattern.begin_patch()
|
||||
|
@ -169,3 +253,61 @@ def test_mesh_pattern_error_states():
|
|||
|
||||
with pytest.raises(cairo.Error):
|
||||
cairo.MeshPattern().set_corner_color_rgb(0, 0.125, 0.25, 0.5)
|
||||
|
||||
|
||||
def test_get_matrix():
|
||||
pattern = cairo.SolidPattern(1, 2, 4)
|
||||
assert isinstance(pattern.get_matrix(), cairo.Matrix)
|
||||
|
||||
|
||||
def test_set_extend():
|
||||
pattern = cairo.SolidPattern(1, 2, 4)
|
||||
pattern.set_extend(42)
|
||||
assert pattern.get_extend() == 42
|
||||
with pytest.raises(TypeError):
|
||||
pattern.set_extend(object())
|
||||
|
||||
|
||||
def test_set_filter():
|
||||
pattern = cairo.SolidPattern(1, 2, 4)
|
||||
with pytest.raises(TypeError):
|
||||
pattern.set_filter(object())
|
||||
|
||||
|
||||
def test_pattern():
|
||||
with pytest.raises(TypeError):
|
||||
cairo.Pattern()
|
||||
|
||||
r, g, b, a = 0.1, 0.2, 0.3, 0.4
|
||||
p = cairo.SolidPattern(r, g, b, a)
|
||||
assert p.get_rgba() == (r, g, b, a)
|
||||
|
||||
assert not p == object()
|
||||
hash(p)
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
cairo.Gradient()
|
||||
|
||||
x0, y0, x1, y1 = 0.0, 0.0, 0.0, 1.0
|
||||
p = cairo.LinearGradient(x0, y0, x1, y1)
|
||||
assert p.get_linear_points() == (x0, y0, x1, y1)
|
||||
p.add_color_stop_rgba(1, 0, 0, 0, 1)
|
||||
p.add_color_stop_rgba(0, 1, 1, 1, 1)
|
||||
|
||||
cx0, cy0, radius0, cx1, cy1, radius1 = 1.0, 1.0, 1.0, 2.0, 2.0, 1.0
|
||||
p = cairo.RadialGradient(cx0, cy0, radius0, cx1, cy1, radius1)
|
||||
assert p.get_radial_circles() == (cx0, cy0, radius0, cx1, cy1, radius1)
|
||||
p.add_color_stop_rgba(0, 1, 1, 1, 1)
|
||||
p.add_color_stop_rgba(1, 0, 0, 0, 1)
|
||||
|
||||
|
||||
def test_pattern_filter():
|
||||
pattern = cairo.SolidPattern(1, 2, 3)
|
||||
assert pattern.get_filter() == cairo.FILTER_GOOD
|
||||
pattern.set_filter(cairo.FILTER_NEAREST)
|
||||
assert pattern.get_filter() == cairo.FILTER_NEAREST
|
||||
|
||||
|
||||
def test_surface_pattern():
|
||||
with pytest.raises(TypeError):
|
||||
cairo.SurfacePattern(object())
|
||||
|
|
Loading…
Reference in New Issue