Skip to content

Commit

Permalink
Initial work for composition test
Browse files Browse the repository at this point in the history
  • Loading branch information
timlinux committed Sep 26, 2012
1 parent f70ba60 commit 0161b8c
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Expand Up @@ -10,4 +10,5 @@ ADD_PYTHON_TEST(PyQgsCoordinateTransform test_qgscoordinatetransform.py)
ADD_PYTHON_TEST(PyQgsRectangle test_qgsrectangle.py)
ADD_PYTHON_TEST(PyQgsSpatialIndex test_qgsspatialindex.py)
ADD_PYTHON_TEST(PyQgsComposerHtml test_qgscomposerhtml.py)
ADD_PYTHON_TEST(PyQgsComposition test_qgscomposition.py)
#ADD_PYTHON_TEST(PyQgsComposerMap test_qgscomposermap.py)
77 changes: 77 additions & 0 deletions tests/src/python/test_qgscomposition.py
@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-
'''
test_qgscomposerhtml.py
--------------------------------------
Date : August 2012
Copyright : (C) 2012 by Dr. Horst Düster /
Dr. Marco Hugentobler
Tim Sutton
email : marco@sourcepole.ch
***************************************************************************
* *
* 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. *
* *
***************************************************************************/
'''
import unittest
import sys
import os
from utilities import unitTestDataPath, getQgisTestApp
from PyQt4.QtCore import QUrl, QString, qDebug
from PyQt4.QtXml import QDomDocument
from qgis.core import (QgsComposition, QgsPoint)

from qgscompositionchecker import QgsCompositionChecker
# support python < 2.7 via unittest2
# needed for expected failure decorator
if sys.version_info[0:2] < (2,7):
try:
from unittest2 import TestCase, expectedFailure
except ImportError:
print "You need to install unittest2 to run the salt tests"
sys.exit(1)
else:
from unittest import TestCase, expectedFailure

QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
TEST_DATA_DIR = unitTestDataPath()


class TestQgsComposition(unittest.TestCase):

def setUp(self):
"""Run before each test."""
pass

def tearDown(self):
"""Run after each test."""
pass

def testSubstitutionMap(self):
"""Test that we can use degree symbols in substitutions.
"""
# Create a point and convert it to text containing a degree symbol.
myPoint = QgsPoint(12.3, -33.33)
myCoordinates = myPoint.toDegreesMinutesSeconds(2)
myTokens = myCoordinates.split(',')
myLongitude = myTokens[0]
myLatitude = myTokens[1]
myText = 'Latitude: %s, Longitude: %s' % (myLatitude, myLongitude)

# Load the composition with the substitutions
myComposition = QgsComposition(CANVAS.mapRenderer())
mySubstitutionMap = {'replace-me': myText }
myFile = os.path.join(TEST_DATA_DIR, 'template.qpt')
myTemplateFile = file(myFile, 'rt')
myTemplateContent = myTemplateFile.read()
myTemplateFile.close()
myDocument = QDomDocument()
myDocument.setContent(myTemplateContent)
myComposition.loadFromTemplate(myDocument, mySubstitutionMap)


if __name__ == '__main__':
unittest.main()

0 comments on commit 0161b8c

Please sign in to comment.