From 71a33e995676d95ccacf108305b8c94a19cb2a9c Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sun, 7 Jan 2018 11:27:47 +1000 Subject: [PATCH] Remove another redundant composer test --- tests/src/python/CMakeLists.txt | 1 - tests/src/python/test_qgscomposition.py | 99 ------------------------- 2 files changed, 100 deletions(-) delete mode 100644 tests/src/python/test_qgscomposition.py diff --git a/tests/src/python/CMakeLists.txt b/tests/src/python/CMakeLists.txt index d1ed96fc5c0..3e7a981c0b2 100644 --- a/tests/src/python/CMakeLists.txt +++ b/tests/src/python/CMakeLists.txt @@ -25,7 +25,6 @@ ADD_PYTHON_TEST(PyQgsColorButton test_qgscolorbutton.py) ADD_PYTHON_TEST(PyQgsColorScheme test_qgscolorscheme.py) ADD_PYTHON_TEST(PyQgsColorSchemeRegistry test_qgscolorschemeregistry.py) ADD_PYTHON_TEST(PyQgsCoordinateFormatter test_qgscoordinateformatter.py) -ADD_PYTHON_TEST(PyQgsComposition test_qgscomposition.py) ADD_PYTHON_TEST(PyQgsConditionalStyle test_qgsconditionalstyle.py) ADD_PYTHON_TEST(PyQgsCoordinateTransformContext test_qgscoordinatetransformcontext.py) ADD_PYTHON_TEST(PyQgsDefaultValue test_qgsdefaultvalue.py) diff --git a/tests/src/python/test_qgscomposition.py b/tests/src/python/test_qgscomposition.py deleted file mode 100644 index 8733dad2614..00000000000 --- a/tests/src/python/test_qgscomposition.py +++ /dev/null @@ -1,99 +0,0 @@ -# -*- coding: utf-8 -*- -"""QGIS Unit tests for QgsComposition. - -.. 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) 2012 by Tim Sutton' -__date__ = '20/08/2012' -__copyright__ = 'Copyright 2012, 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, QDir -from qgis.PyQt.QtXml import QDomDocument - -from qgis.core import (QgsComposition, - QgsPointXY, - QgsRasterLayer, - QgsMultiBandColorRenderer, - QgsProject, - QgsCoordinateFormatter) - -from qgis.testing import start_app, unittest -from qgis.testing.mocked import get_iface -from utilities import unitTestDataPath -from qgis.PyQt.QtXml import QDomDocument - -start_app() -TEST_DATA_DIR = unitTestDataPath() - - -class TestQgsComposition(unittest.TestCase): - - def setUp(self): - """Run before each test.""" - self.iface = get_iface() - - def tearDown(self): - """Run after each test.""" - pass - - def testPrintMapFromTemplate(self): - """Test that we can get a map to render in the template.""" - myPath = os.path.join(TEST_DATA_DIR, 'landsat.tif') - myFileInfo = QFileInfo(myPath) - myRasterLayer = QgsRasterLayer(myFileInfo.filePath(), - myFileInfo.completeBaseName()) - myRenderer = QgsMultiBandColorRenderer( - myRasterLayer.dataProvider(), 2, 3, 4 - ) - # mRasterLayer.setRenderer( rasterRenderer ) - myPipe = myRasterLayer.pipe() - assert myPipe.set(myRenderer), "Cannot set pipe renderer" - - QgsProject.instance().addMapLayers([myRasterLayer]) - - myComposition = QgsComposition(QgsProject.instance()) - myFile = os.path.join(TEST_DATA_DIR, 'template-for-substitution.qpt') - with open(myFile) as f: - myTemplateContent = f.read() - myDocument = QDomDocument() - myDocument.setContent(myTemplateContent) - myComposition.loadFromTemplate(myDocument) - - # now render the map, first zooming to the raster extents - myMap = myComposition.getComposerMapById(0) - myMessage = ('Map 0 could not be found in template %s', myFile) - assert myMap is not None, myMessage - - myExtent = myRasterLayer.extent() - myMap.setNewExtent(myExtent) - myMap.setLayers([myRasterLayer]) - - myImagePath = os.path.join(str(QDir.tempPath()), - 'template_map_render_python.png') - - myPageNumber = 0 - myImage = myComposition.printPageAsRaster(myPageNumber) - myImage.save(myImagePath) - assert os.path.exists(myImagePath), 'Map render was not created.' - - # Not sure if this is a predictable way to test but its quicker than - # rendering. - myFileSize = QFileInfo(myImagePath).size() - myExpectedFileSize = 100000 - myMessage = ('Expected file size to be greater than %s, got %s' - ' for %s' % - (myExpectedFileSize, myFileSize, myImagePath)) - assert myFileSize > myExpectedFileSize, myMessage - - -if __name__ == '__main__': - unittest.main()