Skip to content

Commit 0161b8c

Browse files
committedSep 26, 2012
Initial work for composition test
1 parent f70ba60 commit 0161b8c

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
 

‎tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ ADD_PYTHON_TEST(PyQgsCoordinateTransform test_qgscoordinatetransform.py)
1010
ADD_PYTHON_TEST(PyQgsRectangle test_qgsrectangle.py)
1111
ADD_PYTHON_TEST(PyQgsSpatialIndex test_qgsspatialindex.py)
1212
ADD_PYTHON_TEST(PyQgsComposerHtml test_qgscomposerhtml.py)
13+
ADD_PYTHON_TEST(PyQgsComposition test_qgscomposition.py)
1314
#ADD_PYTHON_TEST(PyQgsComposerMap test_qgscomposermap.py)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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

Comments
 (0)
Please sign in to comment.