Skip to content

Commit cb99839

Browse files
committed
Add allowable mismatch per group/test for labeling tests
1 parent 30bf3ec commit cb99839

5 files changed

+43
-38
lines changed

tests/src/python/test_qgspallabeling_base.py

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def setUpClass(cls):
104104
cls._TestGroupCanvasAbbr = ''
105105
cls._TestImage = ''
106106
cls._TestMapSettings = None
107+
cls._Mismatch = 0
108+
cls._Mismatches = dict()
107109

108110
# initialize class MapRegistry, Canvas, MapRenderer, Map and PAL
109111
# noinspection PyArgumentList

tests/src/python/test_qgspallabeling_canvas.py

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def tearDownClass(cls):
5858
def setUp(self):
5959
"""Run before each test."""
6060
super(TestCanvasBase, self).setUp()
61+
self._Mismatches.clear()
6162

6263
def checkTest(self, **kwargs):
6364
self.lyr.writeToLayer(self.layer)

tests/src/python/test_qgspallabeling_composer.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ def setUpClass(cls):
7474
TestQgsPalLabeling.setUpClass()
7575
# the blue background (set via layer style) to match renderchecker's
7676
TestQgsPalLabeling.loadFeatureLayer('background', True)
77-
cls._CheckMismatch = 0 # mismatch expected for crosscheck
78-
cls._TestImage = ''
7977
cls._TestKind = 0 # OutputKind.(Img|Svg|Pdf)
8078

8179
@classmethod
@@ -91,6 +89,8 @@ def setUp(self):
9189
self._TestImage = ''
9290
# ensure per test map settings stay encapsulated
9391
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
92+
self._Mismatch = 200 # default mismatch for crosscheck
93+
self._Mismatches.clear()
9494

9595
def _set_up_composition(self, width, height, dpi):
9696
# set up composition and add map
@@ -262,7 +262,10 @@ def checkTest(self, **kwargs):
262262
res_m, self._TestImage = self.get_composer_output(self._TestKind)
263263
self.saveControlImage(self._TestImage)
264264
self.assertTrue(res_m, 'Failed to retrieve/save output from composer')
265-
self.assertTrue(*self.renderCheck(mismatch=self._CheckMismatch,
265+
mismatch = self._Mismatch
266+
if self._TestGroup in self._Mismatches:
267+
mismatch = self._Mismatches[self._TestGroup]
268+
self.assertTrue(*self.renderCheck(mismatch=mismatch,
266269
imgpath=self._TestImage))
267270

268271

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

287288

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

300297

301298
if __name__ == '__main__':

tests/src/python/test_qgspallabeling_server.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def setUpClass(cls):
7878

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

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

112113
# noinspection PyPep8Naming
113114
def delete_cache(self):
@@ -143,7 +144,7 @@ def get_wms_params(self):
143144
'TRANSPARENT': 'FALSE',
144145
'IgnoreGetMapUrl': '1'
145146
}
146-
print params
147+
# print params
147148
return params
148149

149150
def checkTest(self, **kwargs):
@@ -158,7 +159,7 @@ def checkTest(self, **kwargs):
158159
# print self._TestImage.__repr__()
159160
self.saveControlImage(self._TestImage)
160161
self.assertTrue(res_m, 'Failed to retrieve/save image from test server')
161-
self.assertTrue(*self.renderCheck(mismatch=self._CheckMismatch,
162+
self.assertTrue(*self.renderCheck(mismatch=self._Mismatch,
162163
imgpath=self._TestImage))
163164

164165

tests/src/python/test_qgspallabeling_tests.py

+30-26
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ def __init__(self):
4040
""":type: QgsPalLabeling"""
4141
self._Canvas = None
4242
""":type: QgsMapCanvas"""
43+
# custom mismatches per group/test (should not mask needed anomaly)
44+
# e.g. self._Mismatches['TestClassName'] = 300
45+
self._Mismatches = dict()
4346

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

4852
def test_text_size_map_unit(self):
@@ -51,15 +55,18 @@ def test_text_size_map_unit(self):
5155
font = QFont(self._TestFont)
5256
font.setPointSizeF(460)
5357
self.lyr.textFont = font
58+
self._Mismatches['TestComposerImageVsCanvasPoint'] = 1877
5459
self.checkTest()
5560

5661
def test_text_color(self):
5762
# Label color change
5863
self.lyr.textColor = Qt.blue
64+
self._Mismatches['TestComposerImageVsCanvasPoint'] = 2034
5965
self.checkTest()
6066

6167
def test_background_rect(self):
6268
self.lyr.shapeDraw = True
69+
self._Mismatches['TestComposerImageVsCanvasPoint'] = 2751
6370
self.checkTest()
6471

6572
def test_background_rect_w_offset(self):
@@ -75,11 +82,11 @@ def test_background_rect_w_offset(self):
7582
self.lyr.shapeDraw = True
7683
self.lyr.shapeOffsetUnits = QgsPalLayerSettings.MapUnits
7784
self.lyr.shapeOffset = QPointF(-2900.0, -450.0)
85+
self._Mismatches['TestComposerImageVsCanvasPoint'] = 2530
7886
self.checkTest()
7987

8088
def test_background_svg(self):
8189
# Label SVG background
82-
# NOTE: this has higher _CheckMismatch (3600) in ComposerVsCanvasPoint
8390
self.lyr.fontSizeInMapUnits = True
8491
font = QFont(self._TestFont)
8592
font.setPointSizeF(460)
@@ -93,11 +100,11 @@ def test_background_svg(self):
93100
self.lyr.shapeSizeUnits = QgsPalLayerSettings.MapUnits
94101
self.lyr.shapeSizeType = QgsPalLayerSettings.SizeBuffer
95102
self.lyr.shapeSize = QPointF(100.0, 0.0)
103+
self._Mismatches['TestComposerImageVsCanvasPoint'] = 2882
96104
self.checkTest()
97105

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

115122
self.lyr.shapeOffsetUnits = QgsPalLayerSettings.MapUnits
116123
self.lyr.shapeOffset = QPointF(-2850.0, 500.0)
124+
self._Mismatches['TestComposerImageVsCanvasPoint'] = 2901
117125
self.checkTest()
118126

119127
def test_partials_labels_enabled(self):
@@ -124,7 +132,7 @@ def test_partials_labels_enabled(self):
124132
# Enable partials labels
125133
self._Pal.setShowingPartialsLabels(True)
126134
self._Pal.saveEngineSettings()
127-
# Check
135+
self._Mismatches['TestComposerImageVsCanvasPoint'] = 2250
128136
self.checkTest()
129137

130138
def test_partials_labels_disabled(self):
@@ -135,7 +143,6 @@ def test_partials_labels_disabled(self):
135143
# Disable partials labels
136144
self._Pal.setShowingPartialsLabels(False)
137145
self._Pal.saveEngineSettings()
138-
# Check
139146
self.checkTest()
140147

141148

@@ -145,29 +152,26 @@ def suiteTests():
145152
Use to define which tests are run when PAL_SUITE is set.
146153
Use sp_vs_suite comparison of server and composer outputs to canvas
147154
"""
155+
sp_suite = [
156+
# 'test_default_label',
157+
# 'test_text_size_map_unit',
158+
# 'test_text_color',
159+
# 'test_background_rect',
160+
# 'test_background_rect_w_offset',
161+
# 'test_background_svg',
162+
# 'test_background_svg_w_offset',
163+
# 'test_partials_labels_enabled',
164+
# 'test_partials_labels_disabled',
165+
]
166+
sp_vs_suite = [
167+
#'test_something_specific',
168+
]
169+
# extended separately for finer control of PAL_SUITE (comment-out undesired)
170+
sp_vs_suite.extend(sp_suite)
171+
148172
return {
149-
'sp_suite': [
150-
# 'test_default_label',
151-
# 'test_text_size_map_unit',
152-
# 'test_text_color',
153-
# 'test_background_rect',
154-
# 'test_background_rect_w_offset',
155-
# 'test_background_svg',
156-
# 'test_background_svg_w_offset',
157-
# 'test_partials_labels_enabled',
158-
# 'test_partials_labels_disabled',
159-
],
160-
'sp_vs_suite': [
161-
# 'test_default_label',
162-
# 'test_text_size_map_unit',
163-
# 'test_text_color',
164-
# 'test_background_rect',
165-
# 'test_background_rect_w_offset',
166-
# 'test_background_svg',
167-
# 'test_background_svg_w_offset',
168-
# 'test_partials_labels_enabled',
169-
# 'test_partials_labels_disabled',
170-
]
173+
'sp_suite': sp_suite,
174+
'sp_vs_suite': sp_vs_suite
171175
}
172176

173177

0 commit comments

Comments
 (0)