Showing with 72 additions and 30 deletions.
  1. +2 −2 tests/src/python/test_qgspallabeling_base.py
  2. +65 −20 tests/src/python/test_qgspallabeling_composer.py
  3. +1 −1 tests/src/python/test_qgspallabeling_server.py
  4. +4 −7 tests/src/python/test_qgspallabeling_tests.py
  5. BIN tests/testdata/control_images/expected_pal_canvas/sp_background_rect/sp_background_rect.png
  6. BIN ...ta/control_images/expected_pal_canvas/sp_background_rect_w_offset/sp_background_rect_w_offset.png
  7. BIN tests/testdata/control_images/expected_pal_canvas/sp_background_svg/sp_background_svg.png
  8. BIN ...data/control_images/expected_pal_canvas/sp_background_svg_w_offset/sp_background_svg_w_offset.png
  9. BIN tests/testdata/control_images/expected_pal_canvas/sp_default_label/sp_default_label.png
  10. BIN ...ta/control_images/expected_pal_canvas/sp_partials_labels_disabled/sp_partials_labels_disabled.png
  11. BIN ...data/control_images/expected_pal_canvas/sp_partials_labels_enabled/sp_partials_labels_enabled.png
  12. BIN tests/testdata/control_images/expected_pal_canvas/sp_text_color/sp_text_color.png
  13. BIN tests/testdata/control_images/expected_pal_canvas/sp_text_size_map_unit/sp_text_size_map_unit.png
  14. BIN ...s/testdata/control_images/expected_pal_composer/sp_img_background_rect/sp_img_background_rect.png
  15. BIN ..._images/expected_pal_composer/sp_img_background_rect_w_offset/sp_img_background_rect_w_offset.png
  16. BIN tests/testdata/control_images/expected_pal_composer/sp_img_background_svg/sp_img_background_svg.png
  17. BIN ...ol_images/expected_pal_composer/sp_img_background_svg_w_offset/sp_img_background_svg_w_offset.png
  18. BIN tests/testdata/control_images/expected_pal_composer/sp_img_default_label/sp_img_default_label.png
  19. BIN ..._images/expected_pal_composer/sp_img_partials_labels_disabled/sp_img_partials_labels_disabled.png
  20. BIN ...ol_images/expected_pal_composer/sp_img_partials_labels_enabled/sp_img_partials_labels_enabled.png
  21. BIN tests/testdata/control_images/expected_pal_composer/sp_img_text_color/sp_img_text_color.png
  22. BIN ...data/control_images/expected_pal_composer/sp_img_text_size_map_unit/sp_img_text_size_map_unit.png
  23. BIN ...s/testdata/control_images/expected_pal_composer/sp_pdf_background_rect/sp_pdf_background_rect.png
  24. BIN ..._images/expected_pal_composer/sp_pdf_background_rect_w_offset/sp_pdf_background_rect_w_offset.png
  25. BIN tests/testdata/control_images/expected_pal_composer/sp_pdf_background_svg/sp_pdf_background_svg.png
  26. BIN ...ol_images/expected_pal_composer/sp_pdf_background_svg_w_offset/sp_pdf_background_svg_w_offset.png
  27. BIN tests/testdata/control_images/expected_pal_composer/sp_pdf_default_label/sp_pdf_default_label.png
  28. BIN ..._images/expected_pal_composer/sp_pdf_partials_labels_disabled/sp_pdf_partials_labels_disabled.png
  29. BIN ...ol_images/expected_pal_composer/sp_pdf_partials_labels_enabled/sp_pdf_partials_labels_enabled.png
  30. BIN tests/testdata/control_images/expected_pal_composer/sp_pdf_text_color/sp_pdf_text_color.png
  31. BIN ...data/control_images/expected_pal_composer/sp_pdf_text_size_map_unit/sp_pdf_text_size_map_unit.png
  32. BIN ...s/testdata/control_images/expected_pal_composer/sp_svg_background_rect/sp_svg_background_rect.png
  33. BIN ..._images/expected_pal_composer/sp_svg_background_rect_w_offset/sp_svg_background_rect_w_offset.png
  34. BIN tests/testdata/control_images/expected_pal_composer/sp_svg_background_svg/sp_svg_background_svg.png
  35. BIN ...ol_images/expected_pal_composer/sp_svg_background_svg_w_offset/sp_svg_background_svg_w_offset.png
  36. BIN tests/testdata/control_images/expected_pal_composer/sp_svg_default_label/sp_svg_default_label.png
  37. BIN ..._images/expected_pal_composer/sp_svg_partials_labels_disabled/sp_svg_partials_labels_disabled.png
  38. BIN ...ol_images/expected_pal_composer/sp_svg_partials_labels_enabled/sp_svg_partials_labels_enabled.png
  39. BIN tests/testdata/control_images/expected_pal_composer/sp_svg_text_color/sp_svg_text_color.png
  40. BIN ...data/control_images/expected_pal_composer/sp_svg_text_size_map_unit/sp_svg_text_size_map_unit.png
  41. BIN tests/testdata/control_images/expected_pal_server/sp_background_rect/sp_background_rect.png
  42. BIN ...ta/control_images/expected_pal_server/sp_background_rect_w_offset/sp_background_rect_w_offset.png
  43. BIN tests/testdata/control_images/expected_pal_server/sp_background_svg/sp_background_svg.png
  44. BIN ...data/control_images/expected_pal_server/sp_background_svg_w_offset/sp_background_svg_w_offset.png
  45. BIN tests/testdata/control_images/expected_pal_server/sp_default_label/sp_default_label.png
  46. BIN ...ta/control_images/expected_pal_server/sp_partials_labels_disabled/sp_partials_labels_disabled.png
  47. BIN ...data/control_images/expected_pal_server/sp_partials_labels_enabled/sp_partials_labels_enabled.png
  48. BIN tests/testdata/control_images/expected_pal_server/sp_text_color/sp_text_color.png
  49. BIN tests/testdata/control_images/expected_pal_server/sp_text_size_map_unit/sp_text_size_map_unit.png
4 changes: 2 additions & 2 deletions tests/src/python/test_qgspallabeling_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def getBaseMapSettings(cls):
# default for labeling test data: WGS 84 / UTM zone 13N
crs.createFromSrid(32613)
ms.setBackgroundColor(QColor(152, 219, 249))
ms.setOutputSize(QSize(600, 400))
ms.setOutputSize(QSize(420, 280))
ms.setOutputDpi(72)
ms.setFlag(QgsMapSettings.Antialiasing)
ms.setDestinationCrs(crs)
Expand Down Expand Up @@ -258,7 +258,7 @@ def defaultLayerSettings(self):
lyr.enabled = True
lyr.fieldName = 'text' # default in test data sources
font = self.getTestFont()
font.setPointSize(48)
font.setPointSize(32)
lyr.textFont = font
lyr.textNamedStyle = 'Roman'
return lyr
Expand Down
85 changes: 65 additions & 20 deletions tests/src/python/test_qgspallabeling_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
from qgis.core import *

from utilities import (
unittest,
expectedFailure,
getTempfilePath,
getExecutablePath,
)
Expand All @@ -42,18 +40,23 @@
suiteTests
)

# look for Poppler, then muPDF PDF-to-image utility
for util in ['pdftoppm', 'mudraw']:
# PDF-to-image utility
# look for Poppler w/ Cairo, then muPDF
# * Poppler w/ Cairo renders correctly
# * Poppler w/o Cairo does not always correctly render vectors in PDF to image
# * muPDF renders correctly, but sightly shifts colors
for util in [
'pdftocairo',
# 'mudraw',
]:
PDFUTIL = getExecutablePath(util)
if PDFUTIL:
break


def skip_if_not_pdf_util(): # skip test class decorator
if PDFUTIL:
return lambda func: func
return unittest.skip('\nPDF-to-image utility not found on PATH\n'
'Install Poppler or muPDF utilities\n\n')
# noinspection PyUnboundLocalVariable
if not PDFUTIL:
raise Exception('PDF-to-image utility not found on PATH: '
'install Poppler (with Cairo)')


# output kind enum
Expand Down Expand Up @@ -214,28 +217,40 @@ def _get_composer_pdf_image(self, width, height, dpi):
return False, ''

filepath = getTempfilePath('png')
# pdftoppm -singlefile -r 72 -x 0 -y 0 -W 600 -H 400 -png in.pdf pngbase
# mudraw -o out.png -r 72 -w 600 -h 400 -c rgb[a] in.pdf
if PDFUTIL == 'pdftoppm':
# Poppler (pdftocairo or pdftoppm):
# PDFUTIL -png -singlefile -r 72 -x 0 -y 0 -W 420 -H 280 in.pdf pngbase
# muPDF (mudraw):
# PDFUTIL -c rgb[a] -r 72 -w 420 -h 280 -o out.png in.pdf
if PDFUTIL.strip().endswith('pdftocairo'):
filebase = os.path.join(
os.path.dirname(filepath),
os.path.splitext(os.path.basename(filepath))[0]
)
call = [
'pdftoppm', '-singlefile', '-r', str(dpi),
'-x', str(0), '-y', str(0), '-W', str(width), '-H', str(height),
'-png', pdfpath, filebase
PDFUTIL, '-png', '-singlefile', '-r', str(dpi),
'-x', '0', '-y', '0', '-W', str(width), '-H', str(height),
pdfpath, filebase
]
elif PDFUTIL == 'mudraw':
elif PDFUTIL.strip().endswith('mudraw'):
call = [
'mudraw', '-c', 'rgba',
PDFUTIL, '-c', 'rgba',
'-r', str(dpi), '-w', str(width), '-h', str(height),
# '-b', '8',
'-o', filepath, pdfpath
]
else:
return False, ''

res = subprocess.check_call(call)
qDebug("_get_composer_pdf_image call: {0}".format(' '.join(call)))
res = False
try:
subprocess.check_call(call)
res = True
except subprocess.CalledProcessError as e:
qDebug("_get_composer_pdf_image failed!\n"
"cmd: {0}\n"
"returncode: {1}\n"
"message: {2}".format(e.cmd, e.returncode, e.message))

if not res:
os.unlink(filepath)
Expand Down Expand Up @@ -264,11 +279,12 @@ def checkTest(self, **kwargs):
mismatch = 0
if 'PAL_NO_MISMATCH' not in os.environ:
# some mismatch expected
mismatch = self._Mismatch if self._Mismatch else 200
mismatch = self._Mismatch if self._Mismatch else 20
if self._TestGroup in self._Mismatches:
mismatch = self._Mismatches[self._TestGroup]
colortol = 0
if 'PAL_NO_COLORTOL' not in os.environ:
colortol = self._ColorTol if self._ColorTol else 0
if self._TestGroup in self._ColorTols:
colortol = self._ColorTols[self._TestGroup]
self.assertTrue(*self.renderCheck(mismatch=mismatch,
Expand Down Expand Up @@ -320,6 +336,29 @@ def setUp(self):
super(TestComposerSvgVsComposerPoint, self).setUp()
self._TestKind = OutputKind.Svg
self.configTest('pal_composer', 'sp_img')
self._ColorTol = 4


class TestComposerPdfPoint(TestComposerPointBase, TestPointBase):

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


class TestComposerPdfVsComposerPoint(TestComposerPointBase, TestPointBase):
"""
Compare only to composer image, which is already compared to canvas point
"""
def setUp(self):
"""Run before each test."""
super(TestComposerPdfVsComposerPoint, self).setUp()
self._TestKind = OutputKind.Pdf
self.configTest('pal_composer', 'sp_img')
self._Mismatch = 50
self._ColorTol = 18


if __name__ == '__main__':
Expand All @@ -330,11 +369,17 @@ def setUp(self):
sp_ivs = ['TestComposerImageVsCanvasPoint.' + t for t in st['sp_vs_suite']]
sp_s = ['TestComposerSvgPoint.' + t for t in st['sp_suite']]
sp_svs = ['TestComposerSvgVsComposerPoint.' + t for t in st['sp_vs_suite']]
sp_p = ['TestComposerPdfPoint.' + t for t in st['sp_suite']]
sp_pvs = ['TestComposerPdfVsComposerPoint.' + t for t in st['sp_vs_suite']]
suite = []

# extended separately for finer control of PAL_SUITE (comment-out undesired)
suite.extend(sp_i)
suite.extend(sp_ivs)
suite.extend(sp_s)
suite.extend(sp_svs)
suite.extend(sp_p)
suite.extend(sp_pvs)

res = runSuite(sys.modules[__name__], suite)
sys.exit(not res.wasSuccessful())
2 changes: 1 addition & 1 deletion tests/src/python/test_qgspallabeling_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def checkTest(self, **kwargs):
mismatch = 0
if 'PAL_NO_MISMATCH' not in os.environ:
# some mismatch expected
mismatch = self._Mismatch if self._Mismatch else 50
mismatch = self._Mismatch if self._Mismatch else 20
if self._TestGroup in self._Mismatches:
mismatch = self._Mismatches[self._TestGroup]
colortol = 0
Expand Down
11 changes: 4 additions & 7 deletions tests/src/python/test_qgspallabeling_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def checkTest(self, **kwargs):

def test_default_label(self):
# Default label placement, with text size in points
self._Mismatches['TestComposerSvgVsComposerPoint'] = 500
self.checkTest()

def test_text_size_map_unit(self):
Expand All @@ -70,12 +69,10 @@ def test_text_size_map_unit(self):
def test_text_color(self):
# Label color change
self.lyr.textColor = Qt.blue
self._Mismatches['TestComposerSvgVsComposerPoint'] = 500
self.checkTest()

def test_background_rect(self):
self.lyr.shapeDraw = True
self._Mismatches['TestComposerSvgVsComposerPoint'] = 1100
self.checkTest()

def test_background_rect_w_offset(self):
Expand All @@ -91,7 +88,6 @@ def test_background_rect_w_offset(self):
self.lyr.shapeDraw = True
self.lyr.shapeOffsetUnits = QgsPalLayerSettings.MapUnits
self.lyr.shapeOffset = QPointF(-2900.0, -450.0)
self._Mismatches['TestComposerSvgVsComposerPoint'] = 750
self.checkTest()

def test_background_svg(self):
Expand All @@ -109,6 +105,7 @@ def test_background_svg(self):
self.lyr.shapeSizeUnits = QgsPalLayerSettings.MapUnits
self.lyr.shapeSizeType = QgsPalLayerSettings.SizeBuffer
self.lyr.shapeSize = QPointF(100.0, 0.0)
self._Mismatches['TestComposerPdfVsComposerPoint'] = 580
self.checkTest()

def test_background_svg_w_offset(self):
Expand All @@ -129,23 +126,23 @@ def test_background_svg_w_offset(self):

self.lyr.shapeOffsetUnits = QgsPalLayerSettings.MapUnits
self.lyr.shapeOffset = QPointF(-2850.0, 500.0)
self._Mismatches['TestComposerPdfVsComposerPoint'] = 760
self.checkTest()

def test_partials_labels_enabled(self):
# Set Big font size
font = QFont(self._TestFont)
font.setPointSizeF(120)
font.setPointSizeF(84)
self.lyr.textFont = font
# Enable partials labels
self._Pal.setShowingPartialsLabels(True)
self._Pal.saveEngineSettings()
self._Mismatches['TestComposerSvgVsComposerPoint'] = 600
self.checkTest()

def test_partials_labels_disabled(self):
# Set Big font size
font = QFont(self._TestFont)
font.setPointSizeF(120)
font.setPointSizeF(84)
self.lyr.textFont = font
# Disable partials labels
self._Pal.setShowingPartialsLabels(False)
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.