4 changes: 2 additions & 2 deletions src/core/qgsrenderchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ bool QgsRenderChecker::compareImages( QString theTestName,
mReport += "<tr><td colspan=2>";
mReport += "Test image and result image for " + theTestName + "<br>"
"Expected size: " + QString::number( myExpectedImage.width() ).toLocal8Bit() + "w x " +
QString::number( myExpectedImage.width() ).toLocal8Bit() + "h (" +
QString::number( myExpectedImage.height() ).toLocal8Bit() + "h (" +
QString::number( mMatchTarget ).toLocal8Bit() + " pixels)<br>"
"Actual size: " + QString::number( myResultImage.width() ).toLocal8Bit() + "w x " +
QString::number( myResultImage.width() ).toLocal8Bit() + "h (" +
QString::number( myResultImage.height() ).toLocal8Bit() + "h (" +
QString::number( myPixelCount ).toLocal8Bit() + " pixels)";
mReport += "</td></tr>";
mReport += "<tr><td colspan = 2>\n";
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ADD_PYTHON_TEST(PyQgsComposerLabel test_qgscomposerlabel.py)
ADD_PYTHON_TEST(PyQgsExpression test_qgsexpression.py)
ADD_PYTHON_TEST(PyQgsPalLabelingBase test_qgspallabeling_base.py)
ADD_PYTHON_TEST(PyQgsPalLabelingCanvas test_qgspallabeling_canvas.py)
#ADD_PYTHON_TEST(PyQgsPalLabelingComposer test_qgspallabeling_composer.py)
ADD_PYTHON_TEST(PyQgsPalLabelingComposer test_qgspallabeling_composer.py)
ADD_PYTHON_TEST(PyQgsPalLabelingServer test_qgspallabeling_server.py)
ADD_PYTHON_TEST(PyQgsVectorFileWriter test_qgsvectorfilewriter.py)
ADD_PYTHON_TEST(PyQgsSpatialiteProvider test_qgsspatialiteprovider.py)
Expand Down
13 changes: 11 additions & 2 deletions tests/src/python/test_qgspallabeling_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
PALREPORTS = {}


# noinspection PyPep8Naming,PyShadowingNames
class TestQgsPalLabeling(TestCase):

_TestDataDir = unitTestDataPath()
Expand All @@ -82,6 +83,7 @@ def setUpClass(cls):

# verify that spatialite provider is available
msg = '\nSpatialite provider not found, SKIPPING TEST SUITE'
# noinspection PyArgumentList
res = 'spatialite' in QgsProviderRegistry.instance().providerList()
assert res, msg

Expand All @@ -92,16 +94,20 @@ def setUpClass(cls):
cls._TestImage = ''

# initialize class MapRegistry, Canvas, MapRenderer, Map and PAL
# noinspection PyArgumentList
cls._MapRegistry = QgsMapLayerRegistry.instance()
""":type: QgsMapLayerRegistry"""
# set color to match render test comparisons background
cls._Canvas.setCanvasColor(QColor(152, 219, 249))
cls._Map = cls._Canvas.map()
cls._Map.resize(QSize(600, 400))
cls._MapRenderer = cls._Canvas.mapRenderer()
""":type: QgsMapRenderer"""
cls._CRS = QgsCoordinateReferenceSystem()
# default for labeling test data sources: WGS 84 / UTM zone 13N
cls._CRS.createFromSrid(32613)
cls._MapRenderer.setDestinationCrs(cls._CRS)
cls._MapRenderer.setProjectionsEnabled(False)
# use platform's native logical output dpi for QgsMapRenderer on launch

cls.setDefaultEngineSettings()
Expand Down Expand Up @@ -140,7 +146,9 @@ def loadFeatureLayer(cls, table):
vlayer.loadNamedStyle(os.path.join(cls._PalDataDir,
'{0}.qml'.format(table)))
cls._MapRegistry.addMapLayer(vlayer)
cls._MapRenderer.setLayerSet([vlayer.id()])
# place new layer on top of render stack
render_lyrs = [vlayer.id()] + list(cls._MapRenderer.layerSet())
cls._MapRenderer.setLayerSet(render_lyrs)

# zoom to aoi
cls._MapRenderer.setExtent(cls.aoiExtent())
Expand Down Expand Up @@ -234,6 +242,7 @@ def renderCheck(self, mismatch=0, imgpath='', grpprefix=''):
chk.setControlPathPrefix('expected_' + grpprefix)
chk.setControlName(self._Test)
chk.setMapRenderer(self._MapRenderer)
# noinspection PyUnusedLocal
res = False
if imgpath:
res = chk.compareImages(self._Test, mismatch, str(imgpath))
Expand Down Expand Up @@ -317,7 +326,7 @@ def test_partials_labels_deactivate(self):
self.assertFalse(pal.isShowingPartialsLabels())



# noinspection PyPep8Naming,PyShadowingNames
def runSuite(module, tests):
"""This allows for a list of test names to be selectively run.
Also, ensures unittest verbose output comes at end, after debug output"""
Expand Down
6 changes: 5 additions & 1 deletion tests/src/python/test_qgspallabeling_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ def checkTest(self, **kwargs):
# NOTE: unless PAL_SUITE env var is set all test class methods will be run
# ex: 'TestGroup(Point|Line|Curved|Polygon|Feature).test_method'
suite = [
'TestCanvasPoint.test_text_size_map_unit'
'TestCanvasPoint.test_default_label',
'TestCanvasPoint.test_text_size_map_unit',
'TestCanvasPoint.test_text_color',
'TestCanvasPoint.test_partials_labels_enabled',
'TestCanvasPoint.test_partials_labels_disabled',
]
res = runSuite(sys.modules[__name__], suite)
sys.exit(not res.wasSuccessful())
163 changes: 163 additions & 0 deletions tests/src/python/test_qgspallabeling_composer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# -*- coding: utf-8 -*-
"""QGIS unit tests for QgsPalLabeling: label rendering to composer
From build dir: ctest -R PyQgsPalLabelingComposer -V
Set the following env variables when manually running tests:
PAL_SUITE to run specific tests (define in __main__)
PAL_VERBOSE to output individual test summary
PAL_CONTROL_IMAGE to trigger building of new control images
PAL_REPORT to open any failed image check reports in web browser
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""

__author__ = 'Larry Shaffer'
__date__ = '2014/02/21'
__copyright__ = 'Copyright 2013, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import sys
import os
import tempfile
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from qgis.core import *

from utilities import (
unittest,
expectedFailure,
)

from test_qgspallabeling_base import TestQgsPalLabeling, runSuite
from test_qgspallabeling_tests import TestPointBase


# noinspection PyShadowingNames
class TestComposerBase(TestQgsPalLabeling):

@classmethod
def setUpClass(cls):
TestQgsPalLabeling.setUpClass()
# the blue background (set via layer style) to match renderchecker's
cls._BkgrdLayer = TestQgsPalLabeling.loadFeatureLayer('background')
cls._CheckMismatch = 0 # mismatch expected for crosscheck
cls._CheckGroup = ''

@classmethod
def tearDownClass(cls):
"""Run after all tests"""
TestQgsPalLabeling.tearDownClass()

def get_composer_image(self, width=600, height=400, dpi=72):
# set up composition and add map
comp = QgsComposition(self._MapRenderer)
""":type: QgsComposition"""
comp.setPrintResolution(dpi)
# 600 x 400 px = 211.67 x 141.11 mm @ 72 dpi
# TODO: figure out why this doesn't work and needs fudging
# probably need sets of fudgyness per dpi group (72, 150, 300)?
paperw = round((width * 25.4 / dpi) + 0.05, 0)
paperh = round((height * 25.4 / dpi) + 0.05, 1)
comp.setPaperSize(paperw, paperh)
compmap = QgsComposerMap(
comp, 0, 0, comp.paperWidth(), comp.paperHeight())
""":type: QgsComposerMap"""
compmap.setFrameEnabled(False)
comp.addComposerMap(compmap)
compmap.setNewExtent(self.aoiExtent())

comp.setPlotStyle(QgsComposition.Print)
dpi = comp.printResolution()
dpmm = dpi / 25.4
img_width = int(dpmm * comp.paperWidth())
img_height = int(dpmm * comp.paperHeight())

# create output image and initialize it
image = QImage(QSize(img_width, img_height), QImage.Format_ARGB32)
image.setDotsPerMeterX(dpmm * 1000)
image.setDotsPerMeterY(dpmm * 1000)
image.fill(QColor(152, 219, 249).rgb())

# render the composition
p = QPainter(image)
p.setRenderHint(QPainter.Antialiasing)
src = QRectF(0, 0, comp.paperWidth(), comp.paperHeight())
trgt = QRectF(0, 0, img_width, img_height)
comp.render(p, trgt, src)
p.end()

tmp = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
filepath = tmp.name
tmp.close()

res = image.save(filepath, "png")
if not res:
os.unlink(filepath)
filepath = ''

return res, filepath


class TestComposerPoint(TestComposerBase, TestPointBase):

_TestImage = ''

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

def setUp(self):
"""Run before each test."""
self.configTest('pal_composer', 'sp')
TestQgsPalLabeling.setDefaultEngineSettings()
self.lyr = self.defaultSettings()
self._TestImage = ''

def tearDown(self):
"""Run after each test."""
pass

def checkTest(self, **kwargs):
self.lyr.writeToLayer(self.layer)
res_m, self._TestImage = self.get_composer_image()
self.saveContolImage(self._TestImage)
self.assertTrue(res_m, 'Failed to retrieve/save image from test server')
# gp = kwargs['grpprefix'] if 'grpprefix' in kwargs else ''
self.assertTrue(*self.renderCheck(mismatch=self._CheckMismatch,
imgpath=self._TestImage,
grpprefix=self._CheckGroup))


class TestComposerVsCanvasPoint(TestComposerPoint):

@classmethod
def setUpClass(cls):
TestComposerPoint.setUpClass()
cls._CheckGroup = 'pal_canvas'
cls._CheckMismatch = 2700 # rounding errors on composer output?


if __name__ == '__main__':
# NOTE: unless PAL_SUITE env var is set all test class methods will be run
# ex: 'TestGroup(Point|Line|Curved|Polygon|Feature).test_method'
suite = [
'TestComposerPoint.test_default_label',
'TestComposerPoint.test_text_size_map_unit',
'TestComposerPoint.test_text_color',
'TestComposerPoint.test_partials_labels_enabled',
'TestComposerPoint.test_partials_labels_disabled',

'TestComposerVsCanvasPoint.test_default_label',
'TestComposerVsCanvasPoint.test_text_size_map_unit',
'TestComposerVsCanvasPoint.test_text_color',
'TestComposerVsCanvasPoint.test_partials_labels_enabled',
'TestComposerVsCanvasPoint.test_partials_labels_disabled',
]
res = runSuite(sys.modules[__name__], suite)
sys.exit(not res.wasSuccessful())
14 changes: 11 additions & 3 deletions tests/src/python/test_qgspallabeling_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def setUpClass(cls):
MAPSERV.startup()
MAPSERV.web_dir_install(glob.glob(cls._PalDataDir + os.sep + '*.qml'))

# noinspection PyArgumentList
# noinspection PyArgumentList
cls._TestProj = QgsProject.instance()
cls._TestProjName = 'pal_test.qgs'
cls._TestProj.setFileName(
Expand Down Expand Up @@ -175,9 +175,17 @@ def setUpClass(cls):
# NOTE: unless PAL_SUITE env var is set all test class methods will be run
# ex: 'TestGroup(Point|Line|Curved|Polygon|Feature).test_method'
suite = [
# 'TestServerVsCanvasPoint.test_text_size_map_unit',
'TestServerPoint.test_default_label',
'TestServerPoint.test_text_size_map_unit',
'TestServerPoint.test_text_color',
'TestServerPoint.test_partials_labels_enabled',
'TestServerPoint.test_partials_labels_disabled'
'TestServerPoint.test_partials_labels_disabled',

'TestServerVsCanvasPoint.test_default_label',
'TestServerVsCanvasPoint.test_text_size_map_unit',
'TestServerVsCanvasPoint.test_text_color',
'TestServerVsCanvasPoint.test_partials_labels_enabled',
'TestServerVsCanvasPoint.test_partials_labels_disabled',
]
res = runSuite(sys.modules[__name__], suite)
# if SPAWN:
Expand Down
6 changes: 4 additions & 2 deletions tests/src/python/test_qgspallabeling_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
from qgis.core import *


# noinspection PyPep8Naming
class TestPointBase(object):

def __init__(self):
"""Dummy assignments, intended to be overriden in subclasses"""
self.lyr = QgsPalLayerSettings()
""":type: QgsPalLayerSettings"""
self._TestFont = QApplication.font() # will become a standard test font
# noinspection PyArgumentList
self._TestFont = QFont() # will become a standard test font
self.params = dict()
self._Pal = None
""":type: QgsPalLabeling"""
Expand All @@ -47,7 +49,7 @@ def test_text_size_map_unit(self):
# Label text size in map units
self.lyr.fontSizeInMapUnits = True
font = QFont(self._TestFont)
font.setPointSizeF(500)
font.setPointSizeF(460)
self.lyr.textFont = font
self.checkTest()

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.