Skip to content
Permalink
Browse files

More unit tests

  • Loading branch information
nyalldawson committed Nov 1, 2017
1 parent f4d3152 commit 9083420312a553ee9f6eaf5d5399304450db5b56
@@ -33,6 +33,9 @@
from qgis.core import (QgsGeometry,
QgsMapUnitScale,
QgsMarkerSymbol,
QgsMultiPolygon,
QgsPolygon,
QgsLineString,
QgsFillSymbol,
QgsLineSymbol,
QgsRenderContext,
@@ -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'},
@@ -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'},
@@ -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)
@@ -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)
Binary file not shown.

0 comments on commit 9083420

Please sign in to comment.
You can’t perform that action at this time.