Skip to content
Permalink
Browse files

Add render checker color tolerance to labeling tests

  • Loading branch information
dakcarto committed Mar 24, 2014
1 parent 81ba9ed commit a6f25c5386e8b529e2f8c0c92b25f9abf375809b
@@ -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
@@ -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
@@ -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
@@ -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)
@@ -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
@@ -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))


@@ -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):
@@ -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))


@@ -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):

0 comments on commit a6f25c5

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