tests: Add some optional hypothesis tests

This commit is contained in:
Christoph Reiter 2017-07-11 13:03:27 +02:00
parent 065a7a7aed
commit 0021664ea2
2 changed files with 43 additions and 0 deletions

1
.gitignore vendored
View File

@ -18,6 +18,7 @@
.cache
MANIFEST
dist
.hypothesis
# image files
*.pdf

42
tests/test_hypothesis.py Normal file
View File

@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
import math
import pytest
import cairo
pytest.importorskip("hypothesis")
from hypothesis import given, strategies, assume
@given(strategies.floats(), strategies.floats())
def test_surface_set_device_scale(x_scale, y_scale):
assume(not any(math.isnan(v) for v in [x_scale, y_scale]))
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10)
try:
surface.set_device_scale(x_scale, y_scale)
except cairo.Error as e:
assert e.status == cairo.Status.INVALID_MATRIX
else:
assert surface.get_device_scale() == (x_scale, y_scale)
@given(strategies.floats(), strategies.floats())
def test_surface_set_device_offset(x_offset, y_offset):
assume(not any(math.isnan(v) for v in [x_offset, y_offset]))
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10)
surface.set_device_offset(x_offset, y_offset)
@given(strategies.floats(), strategies.floats(), strategies.floats(),
strategies.floats())
def test_surface_create_for_rectangle(x, y, w, h):
assume(not any(math.isnan(v) for v in [x, y, w, h]))
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 100, 100)
try:
surface.create_for_rectangle(x, y, w, h)
except cairo.Error as e:
assert e.status == cairo.Status.INVALID_SIZE