diff options
Diffstat (limited to 'test/api_test.py')
-rw-r--r-- | test/api_test.py | 84 |
1 files changed, 60 insertions, 24 deletions
diff --git a/test/api_test.py b/test/api_test.py index 6a8db8c..47d3520 100644 --- a/test/api_test.py +++ b/test/api_test.py @@ -14,41 +14,77 @@ import py.test as test def test_context(): - pass + if cairo.HAS_IMAGE_SURFACE: + f, w, h = cairo.FORMAT_ARGB32, 100, 100 + s = cairo.ImageSurface(f, w, h) + ctx = cairo.Context(s) + ctx.set_source_rgb(1.0, 1.0, 1.0) + ctx.set_operator(cairo.OPERATOR_SOURCE) + ctx.paint() + def test_matrix(): - pass + m = cairo.Matrix() + m.rotate(10) + m.scale(1.5, 2.5) + m.translate(10, 20) + def test_path(): - pass + # AttributeError: 'module' object has no attribute 'Path' + test.raises(AttributeError, "p = cairo.Path()") + # see examples/warpedtext.py + + +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) -def test_patterns(): - pass + 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_surfaces(): - # The Surface type cannot be instantiated - test.raises(TypeError, "s = cairo.Surface()") +def test_surface(): + # TypeError: The Surface type cannot be instantiated + test.raises(TypeError, "s = cairo.Surface()") - if cairo.HAS_IMAGE_SURFACE: - f, w, h = cairo.FORMAT_ARGB32, 100, 100 - s = cairo.ImageSurface(f, w, h) - assert s.get_format() == f - assert s.get_width() == w - assert s.get_height() == h + if cairo.HAS_IMAGE_SURFACE: + f, w, h = cairo.FORMAT_ARGB32, 100, 100 + s = cairo.ImageSurface(f, w, h) + assert s.get_format() == f + assert s.get_width() == w + assert s.get_height() == h - if cairo.HAS_PDF_SURFACE: - f, w, h = tfi.TemporaryFile(mode='w+b'), 100, 100 - s = cairo.PDFSurface(f, w, h) + if cairo.HAS_PDF_SURFACE: + f, w, h = tfi.TemporaryFile(mode='w+b'), 100, 100 + s = cairo.PDFSurface(f, w, h) - if cairo.HAS_PS_SURFACE: - f, w, h = tfi.TemporaryFile(mode='w+b'), 100, 100 - s = cairo.PSSurface(f, w, h) + if cairo.HAS_PS_SURFACE: + f, w, h = tfi.TemporaryFile(mode='w+b'), 100, 100 + s = cairo.PSSurface(f, w, h) - if cairo.HAS_SVG_SURFACE: - f, w, h = tfi.TemporaryFile(mode='w+b'), 100, 100 - s = cairo.SVGSurface(f, w, h) + if cairo.HAS_SVG_SURFACE: + f, w, h = tfi.TemporaryFile(mode='w+b'), 100, 100 + s = cairo.SVGSurface(f, w, h) def test_text(): - pass + pass |