Skip to content

Commit

Permalink
Test improvements
Browse files Browse the repository at this point in the history
- 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 e5b8747
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 14 deletions.
81 changes: 67 additions & 14 deletions tests/src/python/test_qgspointdisplacementrenderer.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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)


Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e5b8747

Please sign in to comment.