Skip to content

Commit

Permalink
Add render checker color tolerance to labeling tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dakcarto committed Mar 24, 2014
1 parent 81ba9ed commit a6f25c5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
12 changes: 8 additions & 4 deletions tests/src/python/test_qgspallabeling_base.py
Expand Up @@ -106,6 +106,8 @@ def setUpClass(cls):
cls._TestMapSettings = None
cls._Mismatch = 0
cls._Mismatches = dict()
cls._ColorTol = 0
cls._ColorTols = dict()

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

def renderCheck(self, mismatch=0, imgpath='', grpprefix=''):
def renderCheck(self, mismatch=0, colortol=0, imgpath='', grpprefix=''):
"""Check rendered map canvas or existing image against control image
mismatch: number of pixels different from control, and still valid check
imgpath: existing image; if present, skips rendering canvas
grpprefix: compare test image/rendering against different test group
:mismatch: number of pixels different from control, and still valid
:colortol: maximum difference for each color component including alpha
:imgpath: existing image; if present, skips rendering canvas
:grpprefix: compare test image/rendering against different test group
"""
if not grpprefix:
grpprefix = self._TestGroupPrefix
Expand All @@ -383,6 +386,7 @@ def renderCheck(self, mismatch=0, imgpath='', grpprefix=''):
chk = QgsRenderChecker()
chk.setControlPathPrefix('expected_' + grpprefix)
chk.setControlName(self._Test)
chk.setColorTolerance(colortol)
chk.setMapSettings(self._MapSettings)
# noinspection PyUnusedLocal
res = False
Expand Down
3 changes: 3 additions & 0 deletions tests/src/python/test_qgspallabeling_canvas.py
Expand Up @@ -58,7 +58,10 @@ def tearDownClass(cls):
def setUp(self):
"""Run before each test."""
super(TestCanvasBase, self).setUp()
self._Mismatch = 0
self._ColorTol = 0
self._Mismatches.clear()
self._ColorTols.clear()

def checkTest(self, **kwargs):
self.lyr.writeToLayer(self.layer)
Expand Down
19 changes: 14 additions & 5 deletions tests/src/python/test_qgspallabeling_composer.py
Expand Up @@ -89,8 +89,10 @@ def setUp(self):
self._TestImage = ''
# ensure per test map settings stay encapsulated
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
self._Mismatch = 200 # default mismatch for crosscheck
self._Mismatch = 0
self._ColorTol = 0
self._Mismatches.clear()
self._ColorTols.clear()

def _set_up_composition(self, width, height, dpi):
# set up composition and add map
Expand Down Expand Up @@ -259,11 +261,18 @@ def checkTest(self, **kwargs):
res_m, self._TestImage = self.get_composer_output(self._TestKind)
self.assertTrue(res_m, 'Failed to retrieve/save output from composer')
self.saveControlImage(self._TestImage)
mismatch = self._Mismatch
if (self._TestGroup in self._Mismatches
and 'PAL_NO_MISMATCH' not in os.environ):
mismatch = self._Mismatches[self._TestGroup]
mismatch = 0
if 'PAL_NO_MISMATCH' not in os.environ:
# some mismatch expected
mismatch = self._Mismatch if self._Mismatch else 200
if self._TestGroup in self._Mismatches:
mismatch = self._Mismatches[self._TestGroup]
colortol = 0
if 'PAL_NO_COLORTOL' not in os.environ:
if self._TestGroup in self._ColorTols:
colortol = self._ColorTols[self._TestGroup]
self.assertTrue(*self.renderCheck(mismatch=mismatch,
colortol=colortol,
imgpath=self._TestImage))


Expand Down
19 changes: 17 additions & 2 deletions tests/src/python/test_qgspallabeling_server.py
Expand Up @@ -109,8 +109,10 @@ def setUp(self):
self._TestImage = ''
# ensure per test map settings stay encapsulated
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
self._Mismatch = 0
self._ColorTol = 0
self._Mismatches.clear()
self._Mismatch = 50 # default for server tests; some mismatch expected
self._ColorTols.clear()

# noinspection PyPep8Naming
def delete_cache(self):
Expand Down Expand Up @@ -161,7 +163,20 @@ def checkTest(self, **kwargs):
# print self._TestImage.__repr__()
self.saveControlImage(self._TestImage)
self.assertTrue(res_m, 'Failed to retrieve/save image from test server')
self.assertTrue(*self.renderCheck(mismatch=self._Mismatch,
mismatch = 0
if 'PAL_NO_MISMATCH' not in os.environ:
# some mismatch expected
mismatch = self._Mismatch if self._Mismatch else 50
if self._TestGroup in self._Mismatches:
mismatch = self._Mismatches[self._TestGroup]
colortol = 0
if 'PAL_NO_COLORTOL' not in os.environ:
# some mismatch expected
# colortol = self._ColorTol if self._ColorTol else 10
if self._TestGroup in self._ColorTols:
colortol = self._ColorTols[self._TestGroup]
self.assertTrue(*self.renderCheck(mismatch=mismatch,
colortol=colortol,
imgpath=self._TestImage))


Expand Down
8 changes: 7 additions & 1 deletion tests/src/python/test_qgspallabeling_tests.py
Expand Up @@ -39,9 +39,15 @@ def __init__(self):
""":type: QgsPalLabeling"""
self._Canvas = None
""":type: QgsMapCanvas"""
# custom mismatches per group/test (should not mask needed anomaly)
# custom mismatches per group/test (should not mask any needed anomaly)
# e.g. self._Mismatches['TestClassName'] = 300
# check base output class's checkTest() or sublcasses for any defaults
self._Mismatches = dict()
# custom color tolerances per group/test: 1 - 20 (0 default, 20 max)
# (should not mask any needed anomaly)
# e.g. self._ColorTols['TestClassName'] = 10
# check base output class's checkTest() or sublcasses for any defaults
self._ColorTols = dict()

# noinspection PyMethodMayBeStatic
def checkTest(self, **kwargs):
Expand Down

0 comments on commit a6f25c5

Please sign in to comment.