-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split layout map overview tests into their own file, add masks
- Loading branch information
1 parent
9d800d4
commit 0f7d8c0
Showing
6 changed files
with
165 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 modified
BIN
+49 Bytes
(100%)
...apoverview/expected_composermap_overview/expected_composermap_overview_mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+27 Bytes
(100%)
...ected_composermap_overview_center/expected_composermap_overview_center_mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+55 Bytes
(100%)
...ected_composermap_overview_invert/expected_composermap_overview_invert_mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.