Skip to content

Commit

Permalink
Added test which shows failure in composer substitution if passing in…
Browse files Browse the repository at this point in the history
… a QString containing a degree symbol. Test is marked as expected to fail for now.
  • Loading branch information
timlinux committed Sep 26, 2012
1 parent 0161b8c commit 671cc98
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
25 changes: 23 additions & 2 deletions tests/src/python/test_qgscomposition.py
Expand Up @@ -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.
"""
Expand All @@ -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()
35 changes: 35 additions & 0 deletions tests/testdata/template-for-substitution.qpt
@@ -0,0 +1,35 @@
<Composer title="Composer 1" visible="1">
<Composition printResolution="300" paperWidth="297" snapGridOffsetX="0" snapGridResolution="0" snapGridOffsetY="0" snapping="0" numPages="1" paperHeight="210" printAsRaster="0">
<ComposerLabel valign="32" labelText="[replace-me] &lt;-- should be replaced by unit test" halign="1" margin="1">
<LabelFont description="Ubuntu,10,-1,5,50,0,0,0,0,0"/>
<FontColor red="0" blue="0" green="0"/>
<ComposerItem width="248.016" x="22.8186" y="29.6098" rotation="0" height="9.7794" frame="true" outlineWidth="0.3" zValue="2" lastValidViewScaleFactor="3.68121" id="" positionLock="false">
<FrameColor alpha="255" red="0" blue="0" green="0"/>
<BackgroundColor alpha="255" red="255" blue="255" green="255"/>
</ComposerItem>
</ComposerLabel>
<ComposerMap keepLayerSet="false" overviewFrameMap="-1" id="0" previewMode="Cache" drawCanvasItems="true">
<overviewFrame overviewFrameMap="-1">
<symbol outputUnit="MM" alpha="0.3" type="fill" name="">
<layer pass="0" class="SimpleFill" locked="0">
<prop k="color" v="255,0,0,76"/>
<prop k="color_border" v="0,0,0,76"/>
<prop k="offset" v="0,0"/>
<prop k="style" v="solid"/>
<prop k="style_border" v="no"/>
<prop k="width_border" v="0.26"/>
</layer>
</symbol>
</overviewFrame>
<Extent ymin="-1" xmin="-1.24602" ymax="0.347325" xmax="1.24602"/>
<LayerSet/>
<Grid gridStyle="0" crossLength="3" penColorRed="0" penColorBlue="0" intervalX="0" offsetX="0" intervalY="0" offsetY="0" gridFrameStyle="0" gridFrameWidth="2" show="0" penWidth="0" penColorGreen="0">
<Annotation rightDirection="0" bottomDirection="0" format="0" topPosition="1" precision="3" leftDirection="0" rightPosition="1" bottomPosition="1" frameDistance="1" show="0" font="Ubuntu,9,-1,5,50,0,0,0,0,0" leftPosition="1" topDirection="0"/>
</Grid>
<ComposerItem width="246" x="24.835" y="64.7284" rotation="0" height="133" frame="true" outlineWidth="0.3" zValue="1" lastValidViewScaleFactor="3.68121" id="map" positionLock="false">
<FrameColor alpha="255" red="0" blue="0" green="0"/>
<BackgroundColor alpha="255" red="255" blue="255" green="255"/>
</ComposerItem>
</ComposerMap>
</Composition>
</Composer>

0 comments on commit 671cc98

Please sign in to comment.