Skip to content

Commit a6f25c5

Browse files
committed
Add render checker color tolerance to labeling tests
1 parent 81ba9ed commit a6f25c5

5 files changed

+49
-12
lines changed

tests/src/python/test_qgspallabeling_base.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ def setUpClass(cls):
106106
cls._TestMapSettings = None
107107
cls._Mismatch = 0
108108
cls._Mismatches = dict()
109+
cls._ColorTol = 0
110+
cls._ColorTols = dict()
109111

110112
# initialize class MapRegistry, Canvas, MapRenderer, Map and PAL
111113
# noinspection PyArgumentList
@@ -368,12 +370,13 @@ def saveControlImage(self, tmpimg=''):
368370
if not os.path.exists(imgpath):
369371
raise OSError('Control image not created: {0}'.format(imgpath))
370372

371-
def renderCheck(self, mismatch=0, imgpath='', grpprefix=''):
373+
def renderCheck(self, mismatch=0, colortol=0, imgpath='', grpprefix=''):
372374
"""Check rendered map canvas or existing image against control image
373375
374-
mismatch: number of pixels different from control, and still valid check
375-
imgpath: existing image; if present, skips rendering canvas
376-
grpprefix: compare test image/rendering against different test group
376+
:mismatch: number of pixels different from control, and still valid
377+
:colortol: maximum difference for each color component including alpha
378+
:imgpath: existing image; if present, skips rendering canvas
379+
:grpprefix: compare test image/rendering against different test group
377380
"""
378381
if not grpprefix:
379382
grpprefix = self._TestGroupPrefix
@@ -383,6 +386,7 @@ def renderCheck(self, mismatch=0, imgpath='', grpprefix=''):
383386
chk = QgsRenderChecker()
384387
chk.setControlPathPrefix('expected_' + grpprefix)
385388
chk.setControlName(self._Test)
389+
chk.setColorTolerance(colortol)
386390
chk.setMapSettings(self._MapSettings)
387391
# noinspection PyUnusedLocal
388392
res = False

tests/src/python/test_qgspallabeling_canvas.py

+3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ def tearDownClass(cls):
5858
def setUp(self):
5959
"""Run before each test."""
6060
super(TestCanvasBase, self).setUp()
61+
self._Mismatch = 0
62+
self._ColorTol = 0
6163
self._Mismatches.clear()
64+
self._ColorTols.clear()
6265

6366
def checkTest(self, **kwargs):
6467
self.lyr.writeToLayer(self.layer)

tests/src/python/test_qgspallabeling_composer.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ def setUp(self):
8989
self._TestImage = ''
9090
# ensure per test map settings stay encapsulated
9191
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
92-
self._Mismatch = 200 # default mismatch for crosscheck
92+
self._Mismatch = 0
93+
self._ColorTol = 0
9394
self._Mismatches.clear()
95+
self._ColorTols.clear()
9496

9597
def _set_up_composition(self, width, height, dpi):
9698
# set up composition and add map
@@ -259,11 +261,18 @@ def checkTest(self, **kwargs):
259261
res_m, self._TestImage = self.get_composer_output(self._TestKind)
260262
self.assertTrue(res_m, 'Failed to retrieve/save output from composer')
261263
self.saveControlImage(self._TestImage)
262-
mismatch = self._Mismatch
263-
if (self._TestGroup in self._Mismatches
264-
and 'PAL_NO_MISMATCH' not in os.environ):
265-
mismatch = self._Mismatches[self._TestGroup]
264+
mismatch = 0
265+
if 'PAL_NO_MISMATCH' not in os.environ:
266+
# some mismatch expected
267+
mismatch = self._Mismatch if self._Mismatch else 200
268+
if self._TestGroup in self._Mismatches:
269+
mismatch = self._Mismatches[self._TestGroup]
270+
colortol = 0
271+
if 'PAL_NO_COLORTOL' not in os.environ:
272+
if self._TestGroup in self._ColorTols:
273+
colortol = self._ColorTols[self._TestGroup]
266274
self.assertTrue(*self.renderCheck(mismatch=mismatch,
275+
colortol=colortol,
267276
imgpath=self._TestImage))
268277

269278

tests/src/python/test_qgspallabeling_server.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ def setUp(self):
109109
self._TestImage = ''
110110
# ensure per test map settings stay encapsulated
111111
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
112+
self._Mismatch = 0
113+
self._ColorTol = 0
112114
self._Mismatches.clear()
113-
self._Mismatch = 50 # default for server tests; some mismatch expected
115+
self._ColorTols.clear()
114116

115117
# noinspection PyPep8Naming
116118
def delete_cache(self):
@@ -161,7 +163,20 @@ def checkTest(self, **kwargs):
161163
# print self._TestImage.__repr__()
162164
self.saveControlImage(self._TestImage)
163165
self.assertTrue(res_m, 'Failed to retrieve/save image from test server')
164-
self.assertTrue(*self.renderCheck(mismatch=self._Mismatch,
166+
mismatch = 0
167+
if 'PAL_NO_MISMATCH' not in os.environ:
168+
# some mismatch expected
169+
mismatch = self._Mismatch if self._Mismatch else 50
170+
if self._TestGroup in self._Mismatches:
171+
mismatch = self._Mismatches[self._TestGroup]
172+
colortol = 0
173+
if 'PAL_NO_COLORTOL' not in os.environ:
174+
# some mismatch expected
175+
# colortol = self._ColorTol if self._ColorTol else 10
176+
if self._TestGroup in self._ColorTols:
177+
colortol = self._ColorTols[self._TestGroup]
178+
self.assertTrue(*self.renderCheck(mismatch=mismatch,
179+
colortol=colortol,
165180
imgpath=self._TestImage))
166181

167182

tests/src/python/test_qgspallabeling_tests.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,15 @@ def __init__(self):
3939
""":type: QgsPalLabeling"""
4040
self._Canvas = None
4141
""":type: QgsMapCanvas"""
42-
# custom mismatches per group/test (should not mask needed anomaly)
42+
# custom mismatches per group/test (should not mask any needed anomaly)
4343
# e.g. self._Mismatches['TestClassName'] = 300
44+
# check base output class's checkTest() or sublcasses for any defaults
4445
self._Mismatches = dict()
46+
# custom color tolerances per group/test: 1 - 20 (0 default, 20 max)
47+
# (should not mask any needed anomaly)
48+
# e.g. self._ColorTols['TestClassName'] = 10
49+
# check base output class's checkTest() or sublcasses for any defaults
50+
self._ColorTols = dict()
4551

4652
# noinspection PyMethodMayBeStatic
4753
def checkTest(self, **kwargs):

0 commit comments

Comments
 (0)