|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +''' |
| 3 | +test_qgscomposerhtml.py |
| 4 | + -------------------------------------- |
| 5 | + Date : August 2012 |
| 6 | + Copyright : (C) 2012 by Dr. Horst Düster / |
| 7 | + Dr. Marco Hugentobler |
| 8 | + Tim Sutton |
| 9 | + email : marco@sourcepole.ch |
| 10 | + *************************************************************************** |
| 11 | + * * |
| 12 | + * This program is free software; you can redistribute it and/or modify * |
| 13 | + * it under the terms of the GNU General Public License as published by * |
| 14 | + * the Free Software Foundation; either version 2 of the License, or * |
| 15 | + * (at your option) any later version. * |
| 16 | + * * |
| 17 | + ***************************************************************************/ |
| 18 | +''' |
| 19 | +import unittest |
| 20 | +import sys |
| 21 | +import os |
| 22 | +from utilities import unitTestDataPath, getQgisTestApp |
| 23 | +from PyQt4.QtCore import QUrl, QString, qDebug |
| 24 | +from PyQt4.QtXml import QDomDocument |
| 25 | +from qgis.core import (QgsComposition, QgsPoint) |
| 26 | + |
| 27 | +from qgscompositionchecker import QgsCompositionChecker |
| 28 | +# support python < 2.7 via unittest2 |
| 29 | +# needed for expected failure decorator |
| 30 | +if sys.version_info[0:2] < (2,7): |
| 31 | + try: |
| 32 | + from unittest2 import TestCase, expectedFailure |
| 33 | + except ImportError: |
| 34 | + print "You need to install unittest2 to run the salt tests" |
| 35 | + sys.exit(1) |
| 36 | +else: |
| 37 | + from unittest import TestCase, expectedFailure |
| 38 | + |
| 39 | +QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp() |
| 40 | +TEST_DATA_DIR = unitTestDataPath() |
| 41 | + |
| 42 | + |
| 43 | +class TestQgsComposition(unittest.TestCase): |
| 44 | + |
| 45 | + def setUp(self): |
| 46 | + """Run before each test.""" |
| 47 | + pass |
| 48 | + |
| 49 | + def tearDown(self): |
| 50 | + """Run after each test.""" |
| 51 | + pass |
| 52 | + |
| 53 | + def testSubstitutionMap(self): |
| 54 | + """Test that we can use degree symbols in substitutions. |
| 55 | + """ |
| 56 | + # Create a point and convert it to text containing a degree symbol. |
| 57 | + myPoint = QgsPoint(12.3, -33.33) |
| 58 | + myCoordinates = myPoint.toDegreesMinutesSeconds(2) |
| 59 | + myTokens = myCoordinates.split(',') |
| 60 | + myLongitude = myTokens[0] |
| 61 | + myLatitude = myTokens[1] |
| 62 | + myText = 'Latitude: %s, Longitude: %s' % (myLatitude, myLongitude) |
| 63 | + |
| 64 | + # Load the composition with the substitutions |
| 65 | + myComposition = QgsComposition(CANVAS.mapRenderer()) |
| 66 | + mySubstitutionMap = {'replace-me': myText } |
| 67 | + myFile = os.path.join(TEST_DATA_DIR, 'template.qpt') |
| 68 | + myTemplateFile = file(myFile, 'rt') |
| 69 | + myTemplateContent = myTemplateFile.read() |
| 70 | + myTemplateFile.close() |
| 71 | + myDocument = QDomDocument() |
| 72 | + myDocument.setContent(myTemplateContent) |
| 73 | + myComposition.loadFromTemplate(myDocument, mySubstitutionMap) |
| 74 | + |
| 75 | + |
| 76 | +if __name__ == '__main__': |
| 77 | + unittest.main() |
0 commit comments