Skip to content
Permalink
Browse files

Test improvements

- Use standard test font, larger font size to minimize cross platform
rendering differences
- Create a local test report for debugging
  • Loading branch information
nyalldawson committed Mar 26, 2019
1 parent c282e95 commit e5b87474d48ca30dd4de950d110427f95f8140ff
@@ -28,7 +28,7 @@
import os

from qgis.PyQt.QtGui import QColor
from qgis.PyQt.QtCore import QSize, QThreadPool
from qgis.PyQt.QtCore import QSize, QThreadPool, QDir
from qgis.PyQt.QtXml import QDomDocument

from qgis.core import (QgsVectorLayer,
@@ -60,6 +60,14 @@

class TestQgsPointDisplacementRenderer(unittest.TestCase):

def setUp(self):
self.report = "<h1>Python QgsPointDisplacementRenderer Tests</h1>\n"

def tearDown(self):
report_file_path = "%s/qgistest.html" % QDir.tempPath()
with open(report_file_path, 'a') as report_file:
report_file.write(self.report)

def _setUp(self):
myShpFile = os.path.join(TEST_DATA_DIR, 'points.shp')
layer = QgsVectorLayer(myShpFile, 'Points', 'ogr')
@@ -200,7 +208,9 @@ def testRenderNoCluster(self):
renderchecker.setMapSettings(mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_no_cluster')
self.assertTrue(renderchecker.runTest('displacement_no_cluster'))
res = renderchecker.runTest('displacement_no_cluster')
self.report += renderchecker.report()
self.assertTrue(res)
self._tearDown(layer)

def testRenderWithin(self):
@@ -210,7 +220,9 @@ def testRenderWithin(self):
renderchecker.setMapSettings(mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster'))
res = renderchecker.runTest('expected_displacement_cluster')
self.report += renderchecker.report()
self.assertTrue(res)
self._tearDown(layer)

def testRenderVariables(self):
@@ -229,6 +241,7 @@ def testRenderVariables(self):
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_variables')
result = renderchecker.runTest('expected_displacement_variables')
self.report += renderchecker.report()
layer.renderer().setCenterSymbol(old_marker)
self.assertTrue(result)
self._tearDown(layer)
@@ -241,7 +254,9 @@ def testRenderGrid(self):
renderchecker.setMapSettings(mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_grid')
self.assertTrue(renderchecker.runTest('expected_displacement_grid'))
res = renderchecker.runTest('expected_displacement_grid')
self.report += renderchecker.report()
self.assertTrue(res)
self._tearDown(layer)

def testRenderGridAdjust(self):
@@ -254,45 +269,59 @@ def testRenderGridAdjust(self):
renderchecker.setMapSettings(mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_adjust_grid')
self.assertTrue(renderchecker.runTest('expected_displacement_adjust_grid'))
res = renderchecker.runTest('expected_displacement_adjust_grid')
self.report += renderchecker.report()
self.assertTrue(res)
self._tearDown(layer)

def testClusterRingLabels(self):
layer, renderer, mapsettings = self._setUp()
layer.renderer().setTolerance(10)
layer.renderer().setLabelAttributeName('Class')
layer.renderer().setLabelDistanceFactor(0.35)
f = QgsFontUtils.getStandardTestFont('Bold', 14)
layer.renderer().setLabelFont(f)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster_ring_labels')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster_ring_labels'))
res = renderchecker.runTest('expected_displacement_cluster_ring_labels')
self.report += renderchecker.report()
self.assertTrue(res)
self._tearDown(layer)

def testClusterGridLabels(self):
layer, renderer, mapsettings = self._setUp()
layer.renderer().setTolerance(10)
layer.renderer().setLabelAttributeName('Class')
layer.renderer().setLabelDistanceFactor(0.35)
f = QgsFontUtils.getStandardTestFont('Bold', 14)
layer.renderer().setLabelFont(f)
layer.renderer().setPlacement(QgsPointDisplacementRenderer.Grid)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster_grid_labels')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster_grid_labels'))
res = renderchecker.runTest('expected_displacement_cluster_grid_labels')
self.report += renderchecker.report()
self.assertTrue(res)
self._tearDown(layer)

def testClusterConcentricLabels(self):
layer, renderer, mapsettings = self._setUp()
layer.renderer().setTolerance(10)
layer.renderer().setLabelAttributeName('Class')
layer.renderer().setLabelDistanceFactor(0.35)
f = QgsFontUtils.getStandardTestFont('Bold', 14)
layer.renderer().setLabelFont(f)
layer.renderer().setPlacement(QgsPointDisplacementRenderer.ConcentricRings)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster_concentric_labels')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster_concentric_labels'))
res = renderchecker.runTest('expected_displacement_cluster_concentric_labels')
self.report += renderchecker.report()
self.assertTrue(res)
self._tearDown(layer)

def testClusterRingLabelsDifferentSizes(self):
@@ -301,11 +330,15 @@ def testClusterRingLabelsDifferentSizes(self):
layer.renderer().setTolerance(10)
layer.renderer().setLabelAttributeName('Class')
layer.renderer().setLabelDistanceFactor(0.35)
f = QgsFontUtils.getStandardTestFont('Bold', 14)
layer.renderer().setLabelFont(f)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster_ring_labels_diff_size')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster_ring_labels_diff_size'))
res = renderchecker.runTest('expected_displacement_cluster_ring_labels_diff_size')
self.report += renderchecker.report()
self.assertTrue(res)
self._tearDown(layer)

def testClusterGridLabelsDifferentSizes(self):
@@ -314,12 +347,16 @@ def testClusterGridLabelsDifferentSizes(self):
layer.renderer().setTolerance(10)
layer.renderer().setLabelAttributeName('Class')
layer.renderer().setLabelDistanceFactor(0.35)
f = QgsFontUtils.getStandardTestFont('Bold', 14)
layer.renderer().setLabelFont(f)
layer.renderer().setPlacement(QgsPointDisplacementRenderer.Grid)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster_grid_labels_diff_size')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster_grid_labels_diff_size'))
res = renderchecker.runTest('expected_displacement_cluster_grid_labels_diff_size')
self.report += renderchecker.report()
self.assertTrue(res)
self._tearDown(layer)

def testClusterConcentricLabelsDifferentSizes(self):
@@ -328,12 +365,16 @@ def testClusterConcentricLabelsDifferentSizes(self):
layer.renderer().setTolerance(10)
layer.renderer().setLabelAttributeName('Class')
layer.renderer().setLabelDistanceFactor(0.35)
f = QgsFontUtils.getStandardTestFont('Bold', 14)
layer.renderer().setLabelFont(f)
layer.renderer().setPlacement(QgsPointDisplacementRenderer.ConcentricRings)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster_concentric_labels_diff_size')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster_concentric_labels_diff_size'))
res = renderchecker.runTest('expected_displacement_cluster_concentric_labels_diff_size')
self.report += renderchecker.report()
self.assertTrue(res)
self._tearDown(layer)

def testClusterRingLabelsDifferentSizesFarther(self):
@@ -342,11 +383,15 @@ def testClusterRingLabelsDifferentSizesFarther(self):
layer.renderer().setTolerance(10)
layer.renderer().setLabelAttributeName('Class')
layer.renderer().setLabelDistanceFactor(1)
f = QgsFontUtils.getStandardTestFont('Bold', 14)
layer.renderer().setLabelFont(f)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster_ring_labels_diff_size_farther')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster_ring_labels_diff_size_farther'))
res = renderchecker.runTest('expected_displacement_cluster_ring_labels_diff_size_farther')
self.report += renderchecker.report()
self.assertTrue(res)
self._tearDown(layer)

def testClusterGridLabelsDifferentSizesFarther(self):
@@ -356,11 +401,15 @@ def testClusterGridLabelsDifferentSizesFarther(self):
layer.renderer().setLabelAttributeName('Class')
layer.renderer().setLabelDistanceFactor(1)
layer.renderer().setPlacement(QgsPointDisplacementRenderer.Grid)
f = QgsFontUtils.getStandardTestFont('Bold', 14)
layer.renderer().setLabelFont(f)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster_grid_labels_diff_size_farther')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster_grid_labels_diff_size_farther'))
res = renderchecker.runTest('expected_displacement_cluster_grid_labels_diff_size_farther')
self.report += renderchecker.report()
self.assertTrue(res)
self._tearDown(layer)

def testClusterConcentricLabelsDifferentSizesFarther(self):
@@ -369,12 +418,16 @@ def testClusterConcentricLabelsDifferentSizesFarther(self):
layer.renderer().setTolerance(10)
layer.renderer().setLabelAttributeName('Class')
layer.renderer().setLabelDistanceFactor(1)
f = QgsFontUtils.getStandardTestFont('Bold', 14)
layer.renderer().setLabelFont(f)
layer.renderer().setPlacement(QgsPointDisplacementRenderer.ConcentricRings)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster_concentric_labels_diff_size_farther')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster_concentric_labels_diff_size_farther'))
res = renderchecker.runTest('expected_displacement_cluster_concentric_labels_diff_size_farther')
self.report += renderchecker.report()
self.assertTrue(res)
self._tearDown(layer)


Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit e5b8747

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