Skip to content

Commit 671cc98

Browse files
committed
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.
1 parent 0161b8c commit 671cc98

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

tests/src/python/test_qgscomposition.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def tearDown(self):
5050
"""Run after each test."""
5151
pass
5252

53+
@expectedFailure
5354
def testSubstitutionMap(self):
5455
"""Test that we can use degree symbols in substitutions.
5556
"""
@@ -64,14 +65,34 @@ def testSubstitutionMap(self):
6465
# Load the composition with the substitutions
6566
myComposition = QgsComposition(CANVAS.mapRenderer())
6667
mySubstitutionMap = {'replace-me': myText }
67-
myFile = os.path.join(TEST_DATA_DIR, 'template.qpt')
68+
myFile = os.path.join(TEST_DATA_DIR, 'template-for-substitution.qpt')
6869
myTemplateFile = file(myFile, 'rt')
6970
myTemplateContent = myTemplateFile.read()
7071
myTemplateFile.close()
7172
myDocument = QDomDocument()
7273
myDocument.setContent(myTemplateContent)
7374
myComposition.loadFromTemplate(myDocument, mySubstitutionMap)
74-
75+
76+
# We should be able to get map0
77+
myMap = myComposition.getComposerMapById(0)
78+
myMessage = ('Map 0 could not be found in template %s', myFile)
79+
assert myMap is not None, myMessage
80+
81+
def testNoSubstitutionMap(self):
82+
"""Test that we can get a map if we use no text substitutions."""
83+
myComposition = QgsComposition(CANVAS.mapRenderer())
84+
myFile = os.path.join(TEST_DATA_DIR, 'template-for-substitution.qpt')
85+
myTemplateFile = file(myFile, 'rt')
86+
myTemplateContent = myTemplateFile.read()
87+
myTemplateFile.close()
88+
myDocument = QDomDocument()
89+
myDocument.setContent(myTemplateContent)
90+
myComposition.loadFromTemplate(myDocument)
91+
92+
# We should be able to get map0
93+
myMap = myComposition.getComposerMapById(0)
94+
myMessage = ('Map 0 could not be found in template %s', myFile)
95+
assert myMap is not None, myMessage
7596

7697
if __name__ == '__main__':
7798
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Composer title="Composer 1" visible="1">
2+
<Composition printResolution="300" paperWidth="297" snapGridOffsetX="0" snapGridResolution="0" snapGridOffsetY="0" snapping="0" numPages="1" paperHeight="210" printAsRaster="0">
3+
<ComposerLabel valign="32" labelText="[replace-me] &lt;-- should be replaced by unit test" halign="1" margin="1">
4+
<LabelFont description="Ubuntu,10,-1,5,50,0,0,0,0,0"/>
5+
<FontColor red="0" blue="0" green="0"/>
6+
<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">
7+
<FrameColor alpha="255" red="0" blue="0" green="0"/>
8+
<BackgroundColor alpha="255" red="255" blue="255" green="255"/>
9+
</ComposerItem>
10+
</ComposerLabel>
11+
<ComposerMap keepLayerSet="false" overviewFrameMap="-1" id="0" previewMode="Cache" drawCanvasItems="true">
12+
<overviewFrame overviewFrameMap="-1">
13+
<symbol outputUnit="MM" alpha="0.3" type="fill" name="">
14+
<layer pass="0" class="SimpleFill" locked="0">
15+
<prop k="color" v="255,0,0,76"/>
16+
<prop k="color_border" v="0,0,0,76"/>
17+
<prop k="offset" v="0,0"/>
18+
<prop k="style" v="solid"/>
19+
<prop k="style_border" v="no"/>
20+
<prop k="width_border" v="0.26"/>
21+
</layer>
22+
</symbol>
23+
</overviewFrame>
24+
<Extent ymin="-1" xmin="-1.24602" ymax="0.347325" xmax="1.24602"/>
25+
<LayerSet/>
26+
<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">
27+
<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"/>
28+
</Grid>
29+
<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">
30+
<FrameColor alpha="255" red="0" blue="0" green="0"/>
31+
<BackgroundColor alpha="255" red="255" blue="255" green="255"/>
32+
</ComposerItem>
33+
</ComposerMap>
34+
</Composition>
35+
</Composer>

0 commit comments

Comments
 (0)