Skip to content

Commit

Permalink
Add tests for line placement of labels
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 24, 2015
1 parent d4b659e commit 16cab9f
Show file tree
Hide file tree
Showing 52 changed files with 514 additions and 3 deletions.
15 changes: 15 additions & 0 deletions tests/src/python/test_qgspallabeling_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from test_qgspallabeling_base import TestQgsPalLabeling, runSuite
from test_qgspallabeling_tests import (
TestPointBase,
TestLineBase,
suiteTests
)

Expand Down Expand Up @@ -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
Expand Down
69 changes: 69 additions & 0 deletions tests/src/python/test_qgspallabeling_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from test_qgspallabeling_base import TestQgsPalLabeling, runSuite
from test_qgspallabeling_tests import (
TestPointBase,
TestLineBase,
suiteTests
)

Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions tests/src/python/test_qgspallabeling_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from test_qgspallabeling_base import TestQgsPalLabeling, runSuite
from test_qgspallabeling_tests import (
TestPointBase,
TestLineBase,
suiteTests
)

Expand Down Expand Up @@ -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
Expand Down
83 changes: 80 additions & 3 deletions tests/src/python/test_qgspallabeling_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.