Skip to content

Commit

Permalink
More unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 1, 2017
1 parent f4d3152 commit 9083420
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions tests/src/python/test_qgssymbol.py
Expand Up @@ -33,6 +33,9 @@
from qgis.core import (QgsGeometry,
QgsMapUnitScale,
QgsMarkerSymbol,
QgsMultiPolygon,
QgsPolygon,
QgsLineString,
QgsFillSymbol,
QgsLineSymbol,
QgsRenderContext,
Expand Down Expand Up @@ -69,6 +72,11 @@ def tearDown(self):
def testGeometryRendering(self):
'''Tests rendering a bunch of different geometries, including bad/odd geometries.'''

empty_multipolygon = QgsMultiPolygon()
empty_multipolygon.addGeometry(QgsPolygon())
empty_polygon = QgsPolygon()
empty_linestring = QgsLineString()

tests = [{'name': 'Point',
'wkt': 'Point (1 2)',
'reference_image': 'point'},
Expand All @@ -78,15 +86,24 @@ def testGeometryRendering(self):
{'name': 'LineString',
'wkt': 'LineString (0 0,3 4,4 3)',
'reference_image': 'linestring'},
{'name': 'Empty LineString',
'geom': QgsGeometry(empty_linestring),
'reference_image': 'empty'},
{'name': 'MultiLineString',
'wkt': 'MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 0), (3 1, 5 1, 5 0, 6 0))',
'reference_image': 'multilinestring'},
{'name': 'Polygon',
'wkt': 'Polygon ((0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 7 5, 7 7 , 5 7, 5 5))',
'reference_image': 'polygon'},
{'name': 'Empty Polygon',
'geom': QgsGeometry(empty_polygon),
'reference_image': 'empty'},
{'name': 'MultiPolygon',
'wkt': 'MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))',
'reference_image': 'multipolygon'},
{'name': 'Empty MultiPolygon',
'geom': QgsGeometry(empty_multipolygon),
'reference_image': 'empty'},
{'name': 'CircularString',
'wkt': 'CIRCULARSTRING(268 415,227 505,227 406)',
'reference_image': 'circular_string'},
Expand All @@ -104,16 +121,24 @@ def testGeometryRendering(self):
'reference_image': 'curve_polygon_no_arc'}]

for test in tests:
geom = QgsGeometry.fromWkt(test['wkt'])
assert geom and not geom.isNull(), 'Could not create geometry {}'.format(test['wkt'])

def get_geom():
if 'geom' not in test:
geom = QgsGeometry.fromWkt(test['wkt'])
assert geom and not geom.isNull(), 'Could not create geometry {}'.format(test['wkt'])
else:
geom = test['geom']
return geom

geom = get_geom()
rendered_image = self.renderGeometry(geom)
assert self.imageCheck(test['name'], test['reference_image'], rendered_image)

#Note - each test is repeated with the same geometry and reference image, but with added
#z and m dimensions. This tests that presence of the dimensions does not affect rendering

#test with Z
geom_z = QgsGeometry.fromWkt(test['wkt'])
geom_z = get_geom()
geom_z.get().addZValue(5)
rendered_image = self.renderGeometry(geom_z)
assert self.imageCheck(test['name'] + 'Z', test['reference_image'], rendered_image)
Expand All @@ -124,7 +149,7 @@ def testGeometryRendering(self):
assert self.imageCheck(test['name'] + 'ZM', test['reference_image'], rendered_image)

#test with M
geom_m = QgsGeometry.fromWkt(test['wkt'])
geom_m = get_geom()
geom_m.get().addMValue(15)
rendered_image = self.renderGeometry(geom_m)
assert self.imageCheck(test['name'] + 'M', test['reference_image'], rendered_image)
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9083420

Please sign in to comment.