Skip to content
Permalink
Browse files

Add tests for line placement of labels

  • Loading branch information
nyalldawson committed Jun 24, 2015
1 parent d4b659e commit 16cab9fcf9e2935cdd8591a4592d39c6c6027ce9
Showing with 514 additions and 3 deletions.
  1. +15 −0 tests/src/python/test_qgspallabeling_canvas.py
  2. +69 −0 tests/src/python/test_qgspallabeling_composer.py
  3. +20 −0 tests/src/python/test_qgspallabeling_server.py
  4. +80 −3 tests/src/python/test_qgspallabeling_tests.py
  5. BIN ...a/control_images/expected_pal_canvas_line/sp_curved_placement_above/sp_curved_placement_above.png
  6. BIN ...a/control_images/expected_pal_canvas_line/sp_curved_placement_below/sp_curved_placement_below.png
  7. BIN ...control_images/expected_pal_canvas_line/sp_curved_placement_online/sp_curved_placement_online.png
  8. BIN ...canvas_line/sp_line_placement_above_line_orientation/sp_line_placement_above_line_orientation.png
  9. BIN ...l_canvas_line/sp_line_placement_above_map_orientation/sp_line_placement_above_map_orientation.png
  10. BIN ...canvas_line/sp_line_placement_below_line_orientation/sp_line_placement_below_line_orientation.png
  11. BIN ...l_canvas_line/sp_line_placement_below_map_orientation/sp_line_placement_below_map_orientation.png
  12. BIN ...ata/control_images/expected_pal_canvas_line/sp_line_placement_online/sp_line_placement_online.png
  13. BIN ...images/expected_pal_composer_line/sp_img_curved_placement_above/sp_img_curved_placement_above.png
  14. BIN ...s/expected_pal_composer_line/sp_img_curved_placement_above/sp_img_curved_placement_above_mask.png
  15. BIN ...images/expected_pal_composer_line/sp_img_curved_placement_below/sp_img_curved_placement_below.png
  16. BIN ...s/expected_pal_composer_line/sp_img_curved_placement_below/sp_img_curved_placement_below_mask.png
  17. BIN ...ages/expected_pal_composer_line/sp_img_curved_placement_online/sp_img_curved_placement_online.png
  18. BIN ...ine/sp_img_line_placement_above_line_orientation/sp_img_line_placement_above_line_orientation.png
  19. BIN ...p_img_line_placement_above_line_orientation/sp_img_line_placement_above_line_orientation_mask.png
  20. BIN ..._line/sp_img_line_placement_above_map_orientation/sp_img_line_placement_above_map_orientation.png
  21. BIN .../sp_img_line_placement_above_map_orientation/sp_img_line_placement_above_map_orientation_mask.png
  22. BIN ...ine/sp_img_line_placement_below_line_orientation/sp_img_line_placement_below_line_orientation.png
  23. BIN ...p_img_line_placement_below_line_orientation/sp_img_line_placement_below_line_orientation_mask.png
  24. BIN ..._line/sp_img_line_placement_below_map_orientation/sp_img_line_placement_below_map_orientation.png
  25. BIN .../sp_img_line_placement_below_map_orientation/sp_img_line_placement_below_map_orientation_mask.png
  26. BIN ...l_images/expected_pal_composer_line/sp_img_line_placement_online/sp_img_line_placement_online.png
  27. BIN ...images/expected_pal_composer_line/sp_pdf_curved_placement_above/sp_pdf_curved_placement_above.png
  28. BIN ...images/expected_pal_composer_line/sp_pdf_curved_placement_below/sp_pdf_curved_placement_below.png
  29. BIN ...ages/expected_pal_composer_line/sp_pdf_curved_placement_online/sp_pdf_curved_placement_online.png
  30. BIN ...ine/sp_pdf_line_placement_above_line_orientation/sp_pdf_line_placement_above_line_orientation.png
  31. BIN ..._line/sp_pdf_line_placement_above_map_orientation/sp_pdf_line_placement_above_map_orientation.png
  32. BIN ...ine/sp_pdf_line_placement_below_line_orientation/sp_pdf_line_placement_below_line_orientation.png
  33. BIN ..._line/sp_pdf_line_placement_below_map_orientation/sp_pdf_line_placement_below_map_orientation.png
  34. BIN ...l_images/expected_pal_composer_line/sp_pdf_line_placement_online/sp_pdf_line_placement_online.png
  35. BIN ...images/expected_pal_composer_line/sp_svg_curved_placement_above/sp_svg_curved_placement_above.png
  36. BIN ...images/expected_pal_composer_line/sp_svg_curved_placement_below/sp_svg_curved_placement_below.png
  37. BIN ...ages/expected_pal_composer_line/sp_svg_curved_placement_online/sp_svg_curved_placement_online.png
  38. BIN ...ine/sp_svg_line_placement_above_line_orientation/sp_svg_line_placement_above_line_orientation.png
  39. BIN ..._line/sp_svg_line_placement_above_map_orientation/sp_svg_line_placement_above_map_orientation.png
  40. BIN ...ine/sp_svg_line_placement_below_line_orientation/sp_svg_line_placement_below_line_orientation.png
  41. BIN ..._line/sp_svg_line_placement_below_map_orientation/sp_svg_line_placement_below_map_orientation.png
  42. BIN ...l_images/expected_pal_composer_line/sp_svg_line_placement_online/sp_svg_line_placement_online.png
  43. BIN ...a/control_images/expected_pal_server_line/sp_curved_placement_above/sp_curved_placement_above.png
  44. BIN ...a/control_images/expected_pal_server_line/sp_curved_placement_below/sp_curved_placement_below.png
  45. BIN ...control_images/expected_pal_server_line/sp_curved_placement_online/sp_curved_placement_online.png
  46. BIN ...server_line/sp_line_placement_above_line_orientation/sp_line_placement_above_line_orientation.png
  47. BIN ...l_server_line/sp_line_placement_above_map_orientation/sp_line_placement_above_map_orientation.png
  48. BIN ...server_line/sp_line_placement_below_line_orientation/sp_line_placement_below_line_orientation.png
  49. BIN ...l_server_line/sp_line_placement_below_map_orientation/sp_line_placement_below_map_orientation.png
  50. BIN ...ata/control_images/expected_pal_server_line/sp_line_placement_online/sp_line_placement_online.png
  51. +330 −0 tests/testdata/labeling/line.qml
  52. BIN tests/testdata/labeling/pal_features_v3.sqlite
@@ -31,6 +31,7 @@
from test_qgspallabeling_base import TestQgsPalLabeling, runSuite
from test_qgspallabeling_tests import (
TestPointBase,
TestLineBase,
suiteTests
)

@@ -114,6 +115,20 @@ def setUp(self):
super(TestCanvasPoint, self).setUp()
self.configTest('pal_canvas', 'sp')

class TestCanvasBaseLine(TestCanvasBase):

@classmethod
def setUpClass(cls):
TestCanvasBase.setUpClass()
cls.layer = TestQgsPalLabeling.loadFeatureLayer('line')

class TestCanvasLine(TestCanvasBaseLine, TestLineBase):

def setUp(self):
"""Run before each test."""
super(TestCanvasLine, self).setUp()
self.configTest('pal_canvas_line', 'sp')


if __name__ == '__main__':
# NOTE: unless PAL_SUITE env var is set all test class methods will be run
@@ -37,6 +37,7 @@
from test_qgspallabeling_base import TestQgsPalLabeling, runSuite
from test_qgspallabeling_tests import (
TestPointBase,
TestLineBase,
suiteTests
)

@@ -375,6 +376,74 @@ def setUp(self):
self._Mismatch = 50
self._ColorTol = 18

class TestComposerLineBase(TestComposerBase):

@classmethod
def setUpClass(cls):
TestComposerBase.setUpClass()
cls.layer = TestQgsPalLabeling.loadFeatureLayer('line')


class TestComposerImageLine(TestComposerLineBase, TestLineBase):

def setUp(self):
"""Run before each test."""
super(TestComposerImageLine, self).setUp()
self._TestKind = OutputKind.Img
self.configTest('pal_composer_line', 'sp_img')


class TestComposerImageVsCanvasLine(TestComposerLineBase, TestLineBase):

def setUp(self):
"""Run before each test."""
super(TestComposerImageVsCanvasLine, self).setUp()
self._TestKind = OutputKind.Img
self.configTest('pal_canvas_line', 'sp')


class TestComposerSvgLine(TestComposerLineBase, TestLineBase):

def setUp(self):
"""Run before each test."""
super(TestComposerSvgLine, self).setUp()
self._TestKind = OutputKind.Svg
self.configTest('pal_composer_line', 'sp_svg')


class TestComposerSvgVsComposerLine(TestComposerLineBase, TestLineBase):
"""
Compare only to composer image, which is already compared to canvas line
"""
def setUp(self):
"""Run before each test."""
super(TestComposerSvgVsComposerLine, self).setUp()
self._TestKind = OutputKind.Svg
self.configTest('pal_composer_line', 'sp_img')
self._ColorTol = 4


class TestComposerPdfLine(TestComposerLineBase, TestLineBase):

def setUp(self):
"""Run before each test."""
super(TestComposerPdfLine, self).setUp()
self._TestKind = OutputKind.Pdf
self.configTest('pal_composer_line', 'sp_pdf')


class TestComposerPdfVsComposerLine(TestComposerLineBase, TestLineBase):
"""
Compare only to composer image, which is already compared to canvas line
"""
def setUp(self):
"""Run before each test."""
super(TestComposerPdfVsComposerLine, self).setUp()
self._TestKind = OutputKind.Pdf
self.configTest('pal_composer_line', 'sp_img')
self._Mismatch = 50
self._ColorTol = 18


if __name__ == '__main__':
# NOTE: unless PAL_SUITE env var is set all test class methods will be run
@@ -34,6 +34,7 @@
from test_qgspallabeling_base import TestQgsPalLabeling, runSuite
from test_qgspallabeling_tests import (
TestPointBase,
TestLineBase,
suiteTests
)

@@ -212,6 +213,25 @@ def setUp(self):
super(TestServerVsCanvasPoint, self).setUp()
self.configTest('pal_canvas', 'sp')

class TestServerBaseLine(TestServerBase):

@classmethod
def setUpClass(cls):
TestServerBase.setUpClass()
cls.layer = TestQgsPalLabeling.loadFeatureLayer('line')

class TestServerLine(TestServerBaseLine, TestLineBase):

def setUp(self):
"""Run before each test."""
super(TestServerLine, self).setUp()
self.configTest('pal_server_line', 'sp')

class TestServerVsCanvasLine(TestServerBaseLine, TestLineBase):

def setUp(self):
super(TestServerVsCanvasLine, self).setUp()
self.configTest('pal_canvas_line', 'sp')

if __name__ == '__main__':
# NOTE: unless PAL_SUITE env var is set all test class methods will be run
@@ -170,19 +170,96 @@ def test_partials_labels_disabled(self):
self._Pal.setShowingPartialsLabels(False)
self._Pal.saveEngineSettings()
self.checkTest()

def test_buffer(self):
# Label with buffer
self.lyr.bufferDraw = True
self.lyr.bufferSize = 2
self.checkTest()
self.checkTest()

def test_shadow(self):
# Label with shadow
self.lyr.shadowDraw = True
self.lyr.shadowOffsetDist = 2
self.lyr.shadowTransparency = 0
self.checkTest()
self.checkTest()

# noinspection PyPep8Naming
class TestLineBase(object):

def __init__(self):
"""Dummy assignments, intended to be overridden in subclasses"""
self.lyr = QgsPalLayerSettings()
""":type: QgsPalLayerSettings"""
# noinspection PyArgumentList
self._TestFont = QFont() # will become a standard test font
self._Pal = None
""":type: QgsPalLabeling"""
self._Canvas = None
""":type: QgsMapCanvas"""
# custom mismatches per group/test (should not mask any needed anomaly)
# e.g. self._Mismatches['TestClassName'] = 300
# check base output class's checkTest() or sublcasses for any defaults
self._Mismatches = dict()
# custom color tolerances per group/test: 1 - 20 (0 default, 20 max)
# (should not mask any needed anomaly)
# e.g. self._ColorTols['TestClassName'] = 10
# check base output class's checkTest() or sublcasses for any defaults
self._ColorTols = dict()

# noinspection PyMethodMayBeStatic
def checkTest(self, **kwargs):
"""Intended to be overridden in subclasses"""
pass

def test_line_placement_above_line_orientation(self):
# Line placement, above, follow line orientation
self.lyr.placement = QgsPalLayerSettings.Line
self.lyr.placementFlags = QgsPalLayerSettings.AboveLine
self.checkTest()

def test_line_placement_online(self):
# Line placement, on line
self.lyr.placement = QgsPalLayerSettings.Line
self.lyr.placementFlags = QgsPalLayerSettings.OnLine
self.checkTest()

def test_line_placement_below_line_orientation(self):
# Line placement, below, follow line orientation
self.lyr.placement = QgsPalLayerSettings.Line
self.lyr.placementFlags = QgsPalLayerSettings.BelowLine
self.checkTest()

def test_line_placement_above_map_orientation(self):
# Line placement, above, follow map orientation
self.lyr.placement = QgsPalLayerSettings.Line
self.lyr.placementFlags = QgsPalLayerSettings.AboveLine | QgsPalLayerSettings.MapOrientation
self.checkTest()

def test_line_placement_below_map_orientation(self):
# Line placement, below, follow map orientation
self.lyr.placement = QgsPalLayerSettings.Line
self.lyr.placementFlags = QgsPalLayerSettings.BelowLine | QgsPalLayerSettings.MapOrientation
self.checkTest()

def test_curved_placement_online(self):
# Curved placement, on line
self.lyr.placement = QgsPalLayerSettings.Curved
self.lyr.placementFlags = QgsPalLayerSettings.OnLine
self.checkTest()

def test_curved_placement_above(self):
# Curved placement, on line
self.lyr.placement = QgsPalLayerSettings.Curved
self.lyr.placementFlags = QgsPalLayerSettings.AboveLine | QgsPalLayerSettings.MapOrientation
self.checkTest()

def test_curved_placement_below(self):
# Curved placement, on line
self.lyr.placement = QgsPalLayerSettings.Curved
self.lyr.placementFlags = QgsPalLayerSettings.BelowLine | QgsPalLayerSettings.MapOrientation
self.checkTest()


# noinspection PyPep8Naming
def suiteTests():
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.
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.
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.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.

0 comments on commit 16cab9f

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