Skip to content
Permalink
Browse files

Add allowable mismatch per group/test for labeling tests

  • Loading branch information
dakcarto committed Mar 6, 2014
1 parent 30bf3ec commit cb998399cf8d8fe69080817017d7058a36509d79
@@ -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
@@ -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)
@@ -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
@@ -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
@@ -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))


@@ -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):
@@ -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__':
@@ -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
@@ -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):
@@ -143,7 +144,7 @@ def get_wms_params(self):
'TRANSPARENT': 'FALSE',
'IgnoreGetMapUrl': '1'
}
print params
# print params
return params

def checkTest(self, **kwargs):
@@ -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))


@@ -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):
@@ -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):
@@ -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)
@@ -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)
@@ -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):
@@ -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):
@@ -135,7 +143,6 @@ def test_partials_labels_disabled(self):
# Disable partials labels
self._Pal.setShowingPartialsLabels(False)
self._Pal.saveEngineSettings()
# Check
self.checkTest()


@@ -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
}


0 comments on commit cb99839

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