Skip to content
Permalink
Browse files

Split layout map overview tests into their own file, add masks

  • Loading branch information
nyalldawson committed Jan 2, 2019
1 parent 9d800d4 commit 0f7d8c05e3358e0720faa8f9a681c6342c0b00b2
@@ -100,6 +100,7 @@ ADD_PYTHON_TEST(PyQgsLayoutLabel test_qgslayoutlabel.py)
ADD_PYTHON_TEST(PyQgsLayoutLegend test_qgslayoutlegend.py)
ADD_PYTHON_TEST(PyQgsLayoutMap test_qgslayoutmap.py)
ADD_PYTHON_TEST(PyQgsLayoutMapGrid test_qgslayoutmapgrid.py)
ADD_PYTHON_TEST(PyQgsLayoutMapOverview test_qgslayoutmapoverview.py)
ADD_PYTHON_TEST(PyQgsLayoutPage test_qgslayoutpage.py)
ADD_PYTHON_TEST(PyQgsLayoutPicture test_qgslayoutpicture.py)
ADD_PYTHON_TEST(PyQgsLayoutPolygon test_qgslayoutpolygon.py)
@@ -41,8 +41,7 @@
QgsUnitTypes,
QgsLayoutObject,
QgsProperty,
QgsReadWriteContext,
QgsPrintLayout)
QgsReadWriteContext)

from qgis.testing import start_app, unittest
from utilities import unitTestDataPath
@@ -97,87 +96,6 @@ def __init__(self, methodName):
self.map.setLayers([self.raster_layer])
self.layout.addLayoutItem(self.map)

def testOverviewMap(self):
overviewMap = QgsLayoutItemMap(self.layout)
overviewMap.attemptSetSceneRect(QRectF(20, 130, 70, 70))
overviewMap.setFrameEnabled(True)
overviewMap.setLayers([self.raster_layer])
self.layout.addLayoutItem(overviewMap)
# zoom in
myRectangle = QgsRectangle(96, -152, 160, -120)
self.map.setExtent(myRectangle)
myRectangle2 = QgsRectangle(0, -256, 256, 0)
overviewMap.setExtent(myRectangle2)
overviewMap.overview().setLinkedMap(self.map)
checker = QgsLayoutChecker('composermap_overview', self.layout)
checker.setColorTolerance(6)
checker.setControlPathPrefix("composer_mapoverview")
myTestResult, myMessage = checker.testLayout()
self.report += checker.report()
self.layout.removeLayoutItem(overviewMap)
assert myTestResult, myMessage

def testOverviewMapBlend(self):
overviewMap = QgsLayoutItemMap(self.layout)
overviewMap.attemptSetSceneRect(QRectF(20, 130, 70, 70))
overviewMap.setFrameEnabled(True)
overviewMap.setLayers([self.raster_layer])
self.layout.addLayoutItem(overviewMap)
# zoom in
myRectangle = QgsRectangle(96, -152, 160, -120)
self.map.setExtent(myRectangle)
myRectangle2 = QgsRectangle(0, -256, 256, 0)
overviewMap.setExtent(myRectangle2)
overviewMap.overview().setLinkedMap(self.map)
overviewMap.overview().setBlendMode(QPainter.CompositionMode_Multiply)
checker = QgsLayoutChecker('composermap_overview_blending', self.layout)
checker.setControlPathPrefix("composer_mapoverview")
myTestResult, myMessage = checker.testLayout()
self.report += checker.report()
self.layout.removeLayoutItem(overviewMap)
assert myTestResult, myMessage

def testOverviewMapInvert(self):
overviewMap = QgsLayoutItemMap(self.layout)
overviewMap.attemptSetSceneRect(QRectF(20, 130, 70, 70))
overviewMap.setFrameEnabled(True)
overviewMap.setLayers([self.raster_layer])
self.layout.addLayoutItem(overviewMap)
# zoom in
myRectangle = QgsRectangle(96, -152, 160, -120)
self.map.setExtent(myRectangle)
myRectangle2 = QgsRectangle(0, -256, 256, 0)
overviewMap.setExtent(myRectangle2)
overviewMap.overview().setLinkedMap(self.map)
overviewMap.overview().setInverted(True)
checker = QgsLayoutChecker('composermap_overview_invert', self.layout)
checker.setControlPathPrefix("composer_mapoverview")
myTestResult, myMessage = checker.testLayout()
self.report += checker.report()
self.layout.removeLayoutItem(overviewMap)
assert myTestResult, myMessage

def testOverviewMapCenter(self):
overviewMap = QgsLayoutItemMap(self.layout)
overviewMap.attemptSetSceneRect(QRectF(20, 130, 70, 70))
overviewMap.setFrameEnabled(True)
overviewMap.setLayers([self.raster_layer])
self.layout.addLayoutItem(overviewMap)
# zoom in
myRectangle = QgsRectangle(192, -288, 320, -224)
self.map.setExtent(myRectangle)
myRectangle2 = QgsRectangle(0, -256, 256, 0)
overviewMap.setExtent(myRectangle2)
overviewMap.overview().setLinkedMap(self.map)
overviewMap.overview().setInverted(False)
overviewMap.overview().setCentered(True)
checker = QgsLayoutChecker('composermap_overview_center', self.layout)
checker.setControlPathPrefix("composer_mapoverview")
myTestResult, myMessage = checker.testLayout()
self.report += checker.report()
self.layout.removeLayoutItem(overviewMap)
assert myTestResult, myMessage

def testMapCrs(self):
# create layout with layout map
map_settings = QgsMapSettings()
@@ -0,0 +1,163 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLayoutItemMap.
.. 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__ = '(C) 2017 Nyall Dawson'
__date__ = '20/10/2017'
__copyright__ = 'Copyright 2017, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis # NOQA

import os

from qgis.PyQt.QtCore import QFileInfo, QRectF, QDir
from qgis.PyQt.QtGui import QPainter

from qgis.core import (QgsLayoutItemMap,
QgsRectangle,
QgsRasterLayer,
QgsVectorLayer,
QgsLayout,
QgsProject,
QgsMultiBandColorRenderer)

from qgis.testing import start_app, unittest
from utilities import unitTestDataPath
from qgslayoutchecker import QgsLayoutChecker
from test_qgslayoutitem import LayoutItemTestCase

start_app()
TEST_DATA_DIR = unitTestDataPath()


class TestQgsLayoutMap(unittest.TestCase, LayoutItemTestCase):

@classmethod
def setUpClass(cls):
cls.item_class = QgsLayoutItemMap

def setUp(self):
self.report = "<h1>Python QgsLayoutItemMap 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 __init__(self, methodName):
"""Run once on class initialization."""
unittest.TestCase.__init__(self, methodName)
myPath = os.path.join(TEST_DATA_DIR, 'rgb256x256.png')
rasterFileInfo = QFileInfo(myPath)
self.raster_layer = QgsRasterLayer(rasterFileInfo.filePath(),
rasterFileInfo.completeBaseName())
rasterRenderer = QgsMultiBandColorRenderer(
self.raster_layer.dataProvider(), 1, 2, 3)
self.raster_layer.setRenderer(rasterRenderer)

myPath = os.path.join(TEST_DATA_DIR, 'points.shp')
vector_file_info = QFileInfo(myPath)
self.vector_layer = QgsVectorLayer(vector_file_info.filePath(),
vector_file_info.completeBaseName(), 'ogr')
assert self.vector_layer.isValid()
QgsProject.instance().addMapLayers([self.raster_layer, self.vector_layer])

# create layout with layout map
self.layout = QgsLayout(QgsProject.instance())
self.layout.initializeDefaults()
self.map = QgsLayoutItemMap(self.layout)
self.map.attemptSetSceneRect(QRectF(20, 20, 200, 100))
self.map.setFrameEnabled(True)
self.map.setLayers([self.raster_layer])
self.layout.addLayoutItem(self.map)

def testOverviewMap(self):
overviewMap = QgsLayoutItemMap(self.layout)
overviewMap.attemptSetSceneRect(QRectF(20, 130, 70, 70))
overviewMap.setFrameEnabled(True)
overviewMap.setLayers([self.raster_layer])
self.layout.addLayoutItem(overviewMap)
# zoom in
myRectangle = QgsRectangle(96, -152, 160, -120)
self.map.setExtent(myRectangle)
myRectangle2 = QgsRectangle(0, -256, 256, 0)
overviewMap.setExtent(myRectangle2)
overviewMap.overview().setLinkedMap(self.map)
checker = QgsLayoutChecker('composermap_overview', self.layout)
checker.setColorTolerance(6)
checker.setControlPathPrefix("composer_mapoverview")
myTestResult, myMessage = checker.testLayout()
self.report += checker.report()
self.layout.removeLayoutItem(overviewMap)
assert myTestResult, myMessage

def testOverviewMapBlend(self):
overviewMap = QgsLayoutItemMap(self.layout)
overviewMap.attemptSetSceneRect(QRectF(20, 130, 70, 70))
overviewMap.setFrameEnabled(True)
overviewMap.setLayers([self.raster_layer])
self.layout.addLayoutItem(overviewMap)
# zoom in
myRectangle = QgsRectangle(96, -152, 160, -120)
self.map.setExtent(myRectangle)
myRectangle2 = QgsRectangle(0, -256, 256, 0)
overviewMap.setExtent(myRectangle2)
overviewMap.overview().setLinkedMap(self.map)
overviewMap.overview().setBlendMode(QPainter.CompositionMode_Multiply)
checker = QgsLayoutChecker('composermap_overview_blending', self.layout)
checker.setControlPathPrefix("composer_mapoverview")
myTestResult, myMessage = checker.testLayout()
self.report += checker.report()
self.layout.removeLayoutItem(overviewMap)
assert myTestResult, myMessage

def testOverviewMapInvert(self):
overviewMap = QgsLayoutItemMap(self.layout)
overviewMap.attemptSetSceneRect(QRectF(20, 130, 70, 70))
overviewMap.setFrameEnabled(True)
overviewMap.setLayers([self.raster_layer])
self.layout.addLayoutItem(overviewMap)
# zoom in
myRectangle = QgsRectangle(96, -152, 160, -120)
self.map.setExtent(myRectangle)
myRectangle2 = QgsRectangle(0, -256, 256, 0)
overviewMap.setExtent(myRectangle2)
overviewMap.overview().setLinkedMap(self.map)
overviewMap.overview().setInverted(True)
checker = QgsLayoutChecker('composermap_overview_invert', self.layout)
checker.setControlPathPrefix("composer_mapoverview")
myTestResult, myMessage = checker.testLayout()
self.report += checker.report()
self.layout.removeLayoutItem(overviewMap)
assert myTestResult, myMessage

def testOverviewMapCenter(self):
overviewMap = QgsLayoutItemMap(self.layout)
overviewMap.attemptSetSceneRect(QRectF(20, 130, 70, 70))
overviewMap.setFrameEnabled(True)
overviewMap.setLayers([self.raster_layer])
self.layout.addLayoutItem(overviewMap)
# zoom in
myRectangle = QgsRectangle(192, -288, 320, -224)
self.map.setExtent(myRectangle)
myRectangle2 = QgsRectangle(0, -256, 256, 0)
overviewMap.setExtent(myRectangle2)
overviewMap.overview().setLinkedMap(self.map)
overviewMap.overview().setInverted(False)
overviewMap.overview().setCentered(True)
checker = QgsLayoutChecker('composermap_overview_center', self.layout)
checker.setControlPathPrefix("composer_mapoverview")
myTestResult, myMessage = checker.testLayout()
self.report += checker.report()
self.layout.removeLayoutItem(overviewMap)
assert myTestResult, myMessage


if __name__ == '__main__':
unittest.main()
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 0f7d8c0

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