Skip to content

Commit

Permalink
Add allowable mismatch per group/test for labeling tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dakcarto committed Mar 6, 2014
1 parent 30bf3ec commit cb99839
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 38 deletions.
2 changes: 2 additions & 0 deletions tests/src/python/test_qgspallabeling_base.py
Expand Up @@ -104,6 +104,8 @@ def setUpClass(cls):
cls._TestGroupCanvasAbbr = ''
cls._TestImage = ''
cls._TestMapSettings = None
cls._Mismatch = 0
cls._Mismatches = dict()

# initialize class MapRegistry, Canvas, MapRenderer, Map and PAL
# noinspection PyArgumentList
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_qgspallabeling_canvas.py
Expand Up @@ -58,6 +58,7 @@ def tearDownClass(cls):
def setUp(self):
"""Run before each test."""
super(TestCanvasBase, self).setUp()
self._Mismatches.clear()

def checkTest(self, **kwargs):
self.lyr.writeToLayer(self.layer)
Expand Down
15 changes: 6 additions & 9 deletions tests/src/python/test_qgspallabeling_composer.py
Expand Up @@ -74,8 +74,6 @@ def setUpClass(cls):
TestQgsPalLabeling.setUpClass()
# the blue background (set via layer style) to match renderchecker's
TestQgsPalLabeling.loadFeatureLayer('background', True)
cls._CheckMismatch = 0 # mismatch expected for crosscheck
cls._TestImage = ''
cls._TestKind = 0 # OutputKind.(Img|Svg|Pdf)

@classmethod
Expand All @@ -91,6 +89,8 @@ 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._Mismatches.clear()

def _set_up_composition(self, width, height, dpi):
# set up composition and add map
Expand Down Expand Up @@ -262,7 +262,10 @@ def checkTest(self, **kwargs):
res_m, self._TestImage = self.get_composer_output(self._TestKind)
self.saveControlImage(self._TestImage)
self.assertTrue(res_m, 'Failed to retrieve/save output from composer')
self.assertTrue(*self.renderCheck(mismatch=self._CheckMismatch,
mismatch = self._Mismatch
if self._TestGroup in self._Mismatches:
mismatch = self._Mismatches[self._TestGroup]
self.assertTrue(*self.renderCheck(mismatch=mismatch,
imgpath=self._TestImage))


Expand All @@ -281,8 +284,6 @@ def setUp(self):
super(TestComposerImagePoint, self).setUp()
self._TestKind = OutputKind.Img
self.configTest('pal_composer', 'sp_img')
# TODO: due to double antialiasing?
self._CheckMismatch = 2700 # comment to PAL_REPORT difference


class TestComposerImageVsCanvasPoint(TestComposerPointBase, TestPointBase):
Expand All @@ -292,10 +293,6 @@ def setUp(self):
super(TestComposerImageVsCanvasPoint, self).setUp()
self._TestKind = OutputKind.Img
self.configTest('pal_canvas', 'sp')
# TODO: due to double antialiasing?
if 'test_background_svg' in self.id():
self._CheckMismatch = 3600
# self._CheckMismatch = 0 # uncomment to PAL_REPORT difference


if __name__ == '__main__':
Expand Down
7 changes: 4 additions & 3 deletions tests/src/python/test_qgspallabeling_server.py
Expand Up @@ -78,7 +78,6 @@ def setUpClass(cls):

# the blue background (set via layer style) to match renderchecker's
TestQgsPalLabeling.loadFeatureLayer('background', True)
cls._CheckMismatch = 200 # default for server tests; mismatch expected

settings = QSettings()
# noinspection PyArgumentList
Expand Down Expand Up @@ -108,6 +107,8 @@ def setUp(self):
self._TestImage = ''
# ensure per test map settings stay encapsulated
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
self._Mismatches.clear()
self._Mismatch = 50 # default for server tests; some mismatch expected

# noinspection PyPep8Naming
def delete_cache(self):
Expand Down Expand Up @@ -143,7 +144,7 @@ def get_wms_params(self):
'TRANSPARENT': 'FALSE',
'IgnoreGetMapUrl': '1'
}
print params
# print params
return params

def checkTest(self, **kwargs):
Expand All @@ -158,7 +159,7 @@ 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._CheckMismatch,
self.assertTrue(*self.renderCheck(mismatch=self._Mismatch,
imgpath=self._TestImage))


Expand Down
56 changes: 30 additions & 26 deletions tests/src/python/test_qgspallabeling_tests.py
Expand Up @@ -40,9 +40,13 @@ def __init__(self):
""":type: QgsPalLabeling"""
self._Canvas = None
""":type: QgsMapCanvas"""
# custom mismatches per group/test (should not mask needed anomaly)
# e.g. self._Mismatches['TestClassName'] = 300
self._Mismatches = dict()

def test_default_label(self):
# Default label placement, with text size in points
self._Mismatches['TestComposerImageVsCanvasPoint'] = 2034
self.checkTest()

def test_text_size_map_unit(self):
Expand All @@ -51,15 +55,18 @@ def test_text_size_map_unit(self):
font = QFont(self._TestFont)
font.setPointSizeF(460)
self.lyr.textFont = font
self._Mismatches['TestComposerImageVsCanvasPoint'] = 1877
self.checkTest()

def test_text_color(self):
# Label color change
self.lyr.textColor = Qt.blue
self._Mismatches['TestComposerImageVsCanvasPoint'] = 2034
self.checkTest()

def test_background_rect(self):
self.lyr.shapeDraw = True
self._Mismatches['TestComposerImageVsCanvasPoint'] = 2751
self.checkTest()

def test_background_rect_w_offset(self):
Expand All @@ -75,11 +82,11 @@ def test_background_rect_w_offset(self):
self.lyr.shapeDraw = True
self.lyr.shapeOffsetUnits = QgsPalLayerSettings.MapUnits
self.lyr.shapeOffset = QPointF(-2900.0, -450.0)
self._Mismatches['TestComposerImageVsCanvasPoint'] = 2530
self.checkTest()

def test_background_svg(self):
# Label SVG background
# NOTE: this has higher _CheckMismatch (3600) in ComposerVsCanvasPoint
self.lyr.fontSizeInMapUnits = True
font = QFont(self._TestFont)
font.setPointSizeF(460)
Expand All @@ -93,11 +100,11 @@ def test_background_svg(self):
self.lyr.shapeSizeUnits = QgsPalLayerSettings.MapUnits
self.lyr.shapeSizeType = QgsPalLayerSettings.SizeBuffer
self.lyr.shapeSize = QPointF(100.0, 0.0)
self._Mismatches['TestComposerImageVsCanvasPoint'] = 2882
self.checkTest()

def test_background_svg_w_offset(self):
# Label SVG background
# NOTE: this has higher _CheckMismatch (3600) in ComposerVsCanvasPoint
self.lyr.fontSizeInMapUnits = True
font = QFont(self._TestFont)
font.setPointSizeF(460)
Expand All @@ -114,6 +121,7 @@ def test_background_svg_w_offset(self):

self.lyr.shapeOffsetUnits = QgsPalLayerSettings.MapUnits
self.lyr.shapeOffset = QPointF(-2850.0, 500.0)
self._Mismatches['TestComposerImageVsCanvasPoint'] = 2901
self.checkTest()

def test_partials_labels_enabled(self):
Expand All @@ -124,7 +132,7 @@ def test_partials_labels_enabled(self):
# Enable partials labels
self._Pal.setShowingPartialsLabels(True)
self._Pal.saveEngineSettings()
# Check
self._Mismatches['TestComposerImageVsCanvasPoint'] = 2250
self.checkTest()

def test_partials_labels_disabled(self):
Expand All @@ -135,7 +143,6 @@ def test_partials_labels_disabled(self):
# Disable partials labels
self._Pal.setShowingPartialsLabels(False)
self._Pal.saveEngineSettings()
# Check
self.checkTest()


Expand All @@ -145,29 +152,26 @@ def suiteTests():
Use to define which tests are run when PAL_SUITE is set.
Use sp_vs_suite comparison of server and composer outputs to canvas
"""
sp_suite = [
# 'test_default_label',
# 'test_text_size_map_unit',
# 'test_text_color',
# 'test_background_rect',
# 'test_background_rect_w_offset',
# 'test_background_svg',
# 'test_background_svg_w_offset',
# 'test_partials_labels_enabled',
# 'test_partials_labels_disabled',
]
sp_vs_suite = [
#'test_something_specific',
]
# extended separately for finer control of PAL_SUITE (comment-out undesired)
sp_vs_suite.extend(sp_suite)

return {
'sp_suite': [
# 'test_default_label',
# 'test_text_size_map_unit',
# 'test_text_color',
# 'test_background_rect',
# 'test_background_rect_w_offset',
# 'test_background_svg',
# 'test_background_svg_w_offset',
# 'test_partials_labels_enabled',
# 'test_partials_labels_disabled',
],
'sp_vs_suite': [
# 'test_default_label',
# 'test_text_size_map_unit',
# 'test_text_color',
# 'test_background_rect',
# 'test_background_rect_w_offset',
# 'test_background_svg',
# 'test_background_svg_w_offset',
# 'test_partials_labels_enabled',
# 'test_partials_labels_disabled',
]
'sp_suite': sp_suite,
'sp_vs_suite': sp_vs_suite
}


Expand Down

0 comments on commit cb99839

Please sign in to comment.