Remove another redundant composer test

This commit is contained in:
Nyall Dawson 2018-01-07 11:27:47 +10:00
parent 9a13cfd4e5
commit 71a33e9956
2 changed files with 0 additions and 100 deletions

View File

@ -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)

View File

@ -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()