From 671cc988954818165bd5e3727084107e3689ef3c Mon Sep 17 00:00:00 2001 From: Tim Sutton Date: Wed, 26 Sep 2012 14:34:20 +0200 Subject: [PATCH] Added test which shows failure in composer substitution if passing in a QString containing a degree symbol. Test is marked as expected to fail for now. --- tests/src/python/test_qgscomposition.py | 25 ++++++++++++-- tests/testdata/template-for-substitution.qpt | 35 ++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 tests/testdata/template-for-substitution.qpt diff --git a/tests/src/python/test_qgscomposition.py b/tests/src/python/test_qgscomposition.py index c32e6909da32..2ad701f9ecb5 100644 --- a/tests/src/python/test_qgscomposition.py +++ b/tests/src/python/test_qgscomposition.py @@ -50,6 +50,7 @@ def tearDown(self): """Run after each test.""" pass + @expectedFailure def testSubstitutionMap(self): """Test that we can use degree symbols in substitutions. """ @@ -64,14 +65,34 @@ def testSubstitutionMap(self): # Load the composition with the substitutions myComposition = QgsComposition(CANVAS.mapRenderer()) mySubstitutionMap = {'replace-me': myText } - myFile = os.path.join(TEST_DATA_DIR, 'template.qpt') + myFile = os.path.join(TEST_DATA_DIR, 'template-for-substitution.qpt') myTemplateFile = file(myFile, 'rt') myTemplateContent = myTemplateFile.read() myTemplateFile.close() myDocument = QDomDocument() myDocument.setContent(myTemplateContent) myComposition.loadFromTemplate(myDocument, mySubstitutionMap) - + + # We should be able to get map0 + myMap = myComposition.getComposerMapById(0) + myMessage = ('Map 0 could not be found in template %s', myFile) + assert myMap is not None, myMessage + + def testNoSubstitutionMap(self): + """Test that we can get a map if we use no text substitutions.""" + myComposition = QgsComposition(CANVAS.mapRenderer()) + myFile = os.path.join(TEST_DATA_DIR, 'template-for-substitution.qpt') + myTemplateFile = file(myFile, 'rt') + myTemplateContent = myTemplateFile.read() + myTemplateFile.close() + myDocument = QDomDocument() + myDocument.setContent(myTemplateContent) + myComposition.loadFromTemplate(myDocument) + + # We should be able to get map0 + myMap = myComposition.getComposerMapById(0) + myMessage = ('Map 0 could not be found in template %s', myFile) + assert myMap is not None, myMessage if __name__ == '__main__': unittest.main() diff --git a/tests/testdata/template-for-substitution.qpt b/tests/testdata/template-for-substitution.qpt new file mode 100644 index 000000000000..9b852803fd0a --- /dev/null +++ b/tests/testdata/template-for-substitution.qpt @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +