Skip to content

Commit 6aed6fe

Browse files
committedDec 28, 2013
[tests] Fix python compositionchecker to derive from render checker, fix most python composer tests (fix #9117)
1 parent 2e107f2 commit 6aed6fe

13 files changed

+126
-230
lines changed
 

‎python/core/qgsrenderchecker.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,7 @@ class QgsRenderChecker
3838
bool compareImages( QString theTestName, unsigned int theMismatchCount = 0, QString theRenderedImageFile = "" );
3939

4040
bool isKnownAnomaly( QString theDiffImageFile );
41+
42+
QString expectedImageFile();
43+
4144
};

‎python/core/qgsvectorlayer.sip

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,29 @@ class QgsVectorLayer : QgsMapLayer
920920
* @note added in 2.0
921921
*/
922922
int layerTransparency() const;
923+
924+
/** Set the Map2pixel simplification threshold for fast rendering of features */
925+
void setSimplifyDrawingTol( float simplifyDrawingTol );
926+
/** Returns the Map2pixel simplification threshold for fast rendering of features */
927+
float simplifyDrawingTol() const;
928+
929+
/** Simplification flags for fast rendering of features */
930+
enum SimplifyHint
931+
{
932+
NoSimplification = 0, //!< No simplification can be applied
933+
GeometrySimplification = 1, //!< The geometries can be simplified using the current map2pixel context state
934+
EnvelopeSimplification = 2, //!< The geometries can be fully simplified by its BoundingBox using the current map2pixel context state
935+
AntialiasingSimplification = 4, //!< The geometries can be rendered with 'AntiAliasing' disabled because of it is '1-pixel size'
936+
DefaultSimplification = 3, //!< Default simplification hints can be applied ( Geometry + Envelope )
937+
FullSimplification = 7, //!< All simplification hints can be applied ( Geometry + Envelope + AA-disabling )
938+
};
939+
/** Set the Map2pixel simplification hints for fast rendering of features */
940+
void setSimplifyDrawingHints( int simplifyDrawingHints );
941+
/** Returns the Map2pixel simplification hints for fast rendering of features */
942+
int simplifyDrawingHints() const;
943+
944+
/** Returns whether the VectorLayer can apply the specified simplification hint */
945+
bool simplifyDrawingCanbeApplied( int simplifyHint ) const;
923946

924947
public slots:
925948
/**

‎src/core/qgsrenderchecker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class CORE_EXPORT QgsRenderChecker
101101
*/
102102
bool isKnownAnomaly( QString theDiffImageFile );
103103

104+
QString expectedImageFile() { return mExpectedImageFile; };
105+
104106
protected:
105107

106108
QString mReport;

‎tests/src/core/qgscompositionchecker.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
#include <QImage>
2222
#include <QPainter>
2323

24-
QgsCompositionChecker::QgsCompositionChecker( const QString& testName, QgsComposition* composition, const QString& expectedImageFile )
24+
QgsCompositionChecker::QgsCompositionChecker( const QString& testName, QgsComposition* composition )
2525
: QgsRenderChecker( ),
2626
mTestName( testName ),
2727
mComposition( composition )
2828
{
29-
Q_UNUSED( expectedImageFile );
3029
}
3130

3231
QgsCompositionChecker::QgsCompositionChecker()
@@ -37,12 +36,6 @@ QgsCompositionChecker::~QgsCompositionChecker()
3736
{
3837
}
3938

40-
bool QgsCompositionChecker::testComposition( int page )
41-
{
42-
QString fake;
43-
return testComposition( fake, page );
44-
}
45-
4639
bool QgsCompositionChecker::testComposition( QString &report, int page )
4740
{
4841
if ( !mComposition )

‎tests/src/core/qgscompositionchecker.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ class QImage;
2626
class QgsCompositionChecker : public QgsRenderChecker
2727
{
2828
public:
29-
QgsCompositionChecker( const QString& testName, QgsComposition* composition, const QString& expectedImageFile = QString() );
29+
QgsCompositionChecker( const QString& testName, QgsComposition* composition );
3030
~QgsCompositionChecker();
3131

3232
bool testComposition( QString &report, int page = 0 );
33-
bool testComposition( int page = 0 );
3433

3534
private:
3635
QgsCompositionChecker(); //forbidden

‎tests/src/python/qgscompositionchecker.py

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,40 @@
2020
from PyQt4.QtGui import *
2121
from qgis.core import *
2222

23-
class QgsCompositionChecker:
24-
25-
def testComposition(self, mTestName, mComposition, mExpectedImageFile, page=0 ):
26-
if ( mComposition == None):
23+
class QgsCompositionChecker(QgsRenderChecker):
24+
def __init__(self, mTestName, mComposition ):
25+
self.mExpectedImageFile = ""
26+
self.mComposition = mComposition
27+
self.mTestName = mTestName
28+
super(QgsCompositionChecker, self).__init__()
29+
30+
def testComposition(self, page=0 ):
31+
if ( self.mComposition == None):
2732
myMessage = "Composition not valid"
2833
return False, myMessage
2934

30-
3135
#load expected image
32-
expectedImage = QImage( mExpectedImageFile )
36+
self.setControlName("expected_"+self.mTestName);
37+
expectedImage = QImage( self.expectedImageFile() )
3338

3439
#get width/height, create image and render the composition to it
3540
width = expectedImage.width();
3641
height = expectedImage.height();
3742
outputImage = QImage( QSize( width, height ), QImage.Format_ARGB32 )
3843

39-
mComposition.setPlotStyle( QgsComposition.Print )
44+
self.mComposition.setPlotStyle( QgsComposition.Print )
4045
outputImage.setDotsPerMeterX( expectedImage.dotsPerMeterX() )
4146
outputImage.setDotsPerMeterY( expectedImage.dotsPerMeterX() )
4247
outputImage.fill( 0 )
4348
p = QPainter( outputImage )
44-
mComposition.renderPage( p, page )
49+
self.mComposition.renderPage( p, page )
4550
p.end()
4651

47-
renderedFilePath = QDir.tempPath() + QDir.separator() + QFileInfo( mExpectedImageFile ).baseName() + "_rendered_python.png"
52+
renderedFilePath = QDir.tempPath() + QDir.separator() + QFileInfo(self.mTestName).baseName() + "_rendered.png"
4853
outputImage.save( renderedFilePath, "PNG" )
4954

50-
diffFilePath = QDir.tempPath() + QDir.separator() + QFileInfo( mExpectedImageFile ).baseName() + "_diff_python.png"
51-
testResult = self.compareImages( expectedImage, outputImage, diffFilePath )
55+
diffFilePath = QDir.tempPath() + QDir.separator() + QFileInfo(self.mTestName).baseName() + "_result_diff.png"
56+
testResult = self.compareImages( self.mTestName, 0, renderedFilePath )
5257

5358
myDashMessage = (('<DartMeasurementFile name="Rendered Image '
5459
'%s" type="image/png">'
@@ -59,44 +64,15 @@ def testComposition(self, mTestName, mComposition, mExpectedImageFile, page=0
5964
'<DartMeasurementFile name="Difference Image '
6065
'%s" type="image/png">'
6166
'%s</DartMeasurementFile>') %
62-
(mTestName, renderedFilePath, mTestName,
63-
mExpectedImageFile, mTestName, diffFilePath )
67+
(self.mTestName, renderedFilePath, self.mTestName,
68+
self.expectedImageFile(), self.mTestName, diffFilePath )
6469
)
6570
qDebug( myDashMessage )
6671
if not testResult:
6772
myMessage = ('Expected: %s\nGot: %s\nDifference: %s\n' %
68-
(mExpectedImageFile, renderedFilePath, diffFilePath))
73+
(self.expectedImageFile(), renderedFilePath, diffFilePath))
6974
else:
7075
myMessage = 'Control and test images matched.'
71-
return testResult, myMessage
72-
73-
def compareImages( self, imgExpected, imgRendered, differenceImagePath ):
74-
75-
if ( imgExpected.width() != imgRendered.width()
76-
or imgExpected.height() != imgRendered.height() ):
77-
return False
7876

79-
imageWidth = imgExpected.width()
80-
imageHeight = imgExpected.height()
81-
mismatchCount = 0
82-
83-
differenceImage = QImage(
84-
imageWidth, imageHeight, QImage.Format_ARGB32_Premultiplied )
85-
differenceImage.fill( qRgb( 152, 219, 249 ) )
86-
87-
pixel1 = QColor().rgb()
88-
pixel2 = QColor().rgb()
89-
for i in range( imageHeight ):
90-
for j in range( imageWidth ):
91-
pixel1 = imgExpected.pixel( j, i )
92-
pixel2 = imgRendered.pixel( j, i )
93-
if ( pixel1 != pixel2 ):
94-
mismatchCount = mismatchCount + 1
95-
differenceImage.setPixel( j, i, qRgb( 255, 0, 0 ) )
96-
97-
if differenceImagePath != "":
98-
differenceImage.save( differenceImagePath, "PNG" )
77+
return testResult, myMessage
9978

100-
#allow pixel deviation of 1 percent
101-
pixelCount = imageWidth * imageHeight;
102-
return (float(mismatchCount) / float(pixelCount) ) < 0.01

‎tests/src/python/test_qgsatlascomposition.py

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,10 @@ def autoscale_render_test( self ):
121121
self.mAtlas.prepareForFeature( i )
122122
self.mLabel1.adjustSizeToText()
123123

124-
checker = QgsCompositionChecker()
125-
res = checker.testComposition( "Atlas autoscale test", self.mComposition, \
126-
self.TEST_DATA_DIR + QDir.separator() + \
127-
"control_images" + QDir.separator() + \
128-
"expected_composermapatlas" + QDir.separator() + \
129-
"autoscale_%d.png" % i )
130-
assert res[0] == True
124+
checker = QgsCompositionChecker('atlas_autoscale%d' % (i + 1), self.mComposition)
125+
myTestResult, myMessage = checker.testComposition()
126+
127+
assert myTestResult == True
131128
self.mAtlas.endRender()
132129

133130
def fixedscale_render_test( self ):
@@ -140,13 +137,10 @@ def fixedscale_render_test( self ):
140137
self.mAtlas.prepareForFeature( i )
141138
self.mLabel1.adjustSizeToText()
142139

143-
checker = QgsCompositionChecker()
144-
res = checker.testComposition( "Atlas fixed scale test", self.mComposition, \
145-
self.TEST_DATA_DIR + QDir.separator() + \
146-
"control_images" + QDir.separator() + \
147-
"expected_composermapatlas" + QDir.separator() + \
148-
"fixedscale_%d.png" % i )
149-
assert res[0] == True
140+
checker = QgsCompositionChecker('atlas_fixedscale%d' % (i + 1), self.mComposition)
141+
myTestResult, myMessage = checker.testComposition()
142+
143+
assert myTestResult == True
150144
self.mAtlas.endRender()
151145

152146
def hidden_render_test( self ):
@@ -160,13 +154,10 @@ def hidden_render_test( self ):
160154
self.mAtlas.prepareForFeature( i )
161155
self.mLabel1.adjustSizeToText()
162156

163-
checker = QgsCompositionChecker()
164-
res = checker.testComposition( "Atlas hidden test", self.mComposition, \
165-
self.TEST_DATA_DIR + QDir.separator() + \
166-
"control_images" + QDir.separator() + \
167-
"expected_composermapatlas" + QDir.separator() + \
168-
"hiding_%d.png" % i )
169-
assert res[0] == True
157+
checker = QgsCompositionChecker('atlas_hiding%d' % (i + 1), self.mComposition)
158+
myTestResult, myMessage = checker.testComposition()
159+
160+
assert myTestResult == True
170161
self.mAtlas.endRender()
171162

172163
def sorting_render_test( self ):
@@ -184,13 +175,10 @@ def sorting_render_test( self ):
184175
self.mAtlas.prepareForFeature( i )
185176
self.mLabel1.adjustSizeToText()
186177

187-
checker = QgsCompositionChecker()
188-
res = checker.testComposition( "Atlas sorting test", self.mComposition, \
189-
self.TEST_DATA_DIR + QDir.separator() + \
190-
"control_images" + QDir.separator() + \
191-
"expected_composermapatlas" + QDir.separator() + \
192-
"sorting_%d.png" % i )
193-
assert res[0] == True
178+
checker = QgsCompositionChecker('atlas_sorting%d' % (i + 1), self.mComposition)
179+
myTestResult, myMessage = checker.testComposition()
180+
181+
assert myTestResult == True
194182
self.mAtlas.endRender()
195183

196184
def filtering_render_test( self ):
@@ -209,13 +197,10 @@ def filtering_render_test( self ):
209197
self.mAtlas.prepareForFeature( i )
210198
self.mLabel1.adjustSizeToText()
211199

212-
checker = QgsCompositionChecker()
213-
res = checker.testComposition( "Atlas filtering test", self.mComposition, \
214-
self.TEST_DATA_DIR + QDir.separator() + \
215-
"control_images" + QDir.separator() + \
216-
"expected_composermapatlas" + QDir.separator() + \
217-
"filtering_%d.png" % i )
218-
assert res[0] == True
200+
checker = QgsCompositionChecker('atlas_filtering%d' % (i + 1), self.mComposition)
201+
myTestResult, myMessage = checker.testComposition()
202+
203+
assert myTestResult == True
219204
self.mAtlas.endRender()
220205

221206
if __name__ == '__main__':

‎tests/src/python/test_qgsblendmodes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ def __init__(self, methodName):
6666
# create polygon layer
6767
myShpFile = os.path.join(TEST_DATA_DIR, 'polys.shp')
6868
self.mPolygonLayer = QgsVectorLayer(myShpFile, 'Polygons', 'ogr')
69+
self.mPolygonLayer.setSimplifyDrawingHints(QgsVectorLayer.NoSimplification)
6970
self.mMapRegistry.addMapLayer(self.mPolygonLayer)
7071

7172
# create line layer
7273
myShpFile = os.path.join(TEST_DATA_DIR, 'lines.shp')
7374
self.mLineLayer = QgsVectorLayer(myShpFile, 'Lines', 'ogr')
75+
self.mLineLayer.setSimplifyDrawingHints(QgsVectorLayer.NoSimplification)
7476
self.mMapRegistry.addMapLayer(self.mLineLayer)
7577

7678
# create two raster layers

‎tests/src/python/test_qgscomposereffects.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,9 @@ def testBlendModes(self):
6161

6262
self.mComposerRect2.setBlendMode(QPainter.CompositionMode_Multiply)
6363

64-
checker = QgsCompositionChecker()
65-
myPath = os.path.join(TEST_DATA_DIR,
66-
'control_images',
67-
'expected_composereffects',
68-
'composereffect_blend.png')
69-
myTestResult, myMessage = checker.testComposition('Composer effects blending',
70-
self.mComposition, myPath)
64+
checker = QgsCompositionChecker('composereffects_blend', self.mComposition)
65+
myTestResult, myMessage = checker.testComposition()
66+
7167
self.mComposerRect2.setBlendMode(QPainter.CompositionMode_SourceOver)
7268

7369
assert myTestResult == True, myMessage
@@ -77,13 +73,9 @@ def testTransparency(self):
7773

7874
self.mComposerRect2.setTransparency( 50 )
7975

80-
checker = QgsCompositionChecker()
81-
myPath = os.path.join(TEST_DATA_DIR,
82-
'control_images',
83-
'expected_composereffects',
84-
'composereffect_transparency.png')
85-
myTestResult, myMessage = checker.testComposition('Composer effects transparency',
86-
self.mComposition, myPath)
76+
checker = QgsCompositionChecker('composereffects_transparency', self.mComposition)
77+
myTestResult, myMessage = checker.testComposition()
78+
8779
self.mComposerRect2.setTransparency( 100 )
8880

8981
assert myTestResult == True, myMessage

‎tests/src/python/test_qgscomposerhtml.py

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,28 @@ def tearDown(self):
4343
"""Run after each test."""
4444
print "Tear down"
4545

46-
def controlImagePath(self, theImageName):
47-
"""Helper to get the path to a control image."""
48-
myPath = os.path.join(TEST_DATA_DIR,
49-
"control_images",
50-
"expected_composerhtml",
51-
theImageName)
52-
assert os.path.exists(myPath)
53-
return myPath
54-
5546
def htmlUrl(self):
5647
"""Helper to get the url of the html doc."""
5748
myPath = os.path.join(TEST_DATA_DIR, "html_table.html")
58-
myUrl = QUrl("file:///%1").arg(myPath)
49+
myUrl = QUrl("file:///" + myPath)
5950
return myUrl
6051

61-
@expectedFailure
62-
def XtestTable(self):
52+
def testTable(self):
6353
"""Test we can render a html table in a single frame."""
6454
composerHtml = QgsComposerHtml(self.mComposition, False)
6555
htmlFrame = QgsComposerFrame(self.mComposition,
6656
composerHtml, 0, 0, 100, 200)
6757
htmlFrame.setFrameEnabled(True)
6858
composerHtml.addFrame(htmlFrame)
6959
composerHtml.setUrl(self.htmlUrl())
70-
checker = QgsCompositionChecker()
71-
myResult, myMessage = checker.testComposition(
72-
"Composer html table",
73-
self.mComposition,
74-
self.controlImagePath("composerhtml_table.png"))
60+
61+
checker = QgsCompositionChecker('composerhtml_table', self.mComposition)
62+
myTestResult, myMessage = checker.testComposition()
63+
7564
qDebug(myMessage)
76-
assert myResult, myMessage
65+
assert myTestResult, myMessage
7766

78-
@expectedFailure
79-
def XtestTableMultiFrame(self):
67+
def testTableMultiFrame(self):
8068
"""Test we can render to multiframes."""
8169
composerHtml = QgsComposerHtml(self.mComposition, False)
8270
htmlFrame = QgsComposerFrame(self.mComposition, composerHtml,
@@ -87,38 +75,23 @@ def XtestTableMultiFrame(self):
8775
composerHtml.setUrl(self.htmlUrl())
8876
composerHtml.frame(0).setFrameEnabled(True)
8977

90-
myPage = 0
91-
checker1 = QgsCompositionChecker()
92-
myControlImage = self.controlImagePath(
93-
"composerhtml_table_multiframe1.png")
9478
print "Checking page 1"
95-
myResult, myMessage = checker1.testComposition("Composer html table",
96-
self.mComposition,
97-
myControlImage,
98-
myPage)
99-
assert myResult, myMessage
79+
myPage = 0
80+
checker1 = QgsCompositionChecker('composerhtml_multiframe1', self.mComposition)
81+
myTestResult, myMessage = checker1.testComposition( myPage )
82+
assert myTestResult, myMessage
10083

101-
myPage = 1
102-
checker2 = QgsCompositionChecker()
103-
myControlImage = self.controlImagePath(
104-
"composerhtml_table_multiframe2.png")
10584
print "Checking page 2"
106-
myResult, myMessage = checker2.testComposition("Composer html table",
107-
self.mComposition,
108-
myControlImage,
109-
myPage)
110-
assert myResult, myMessage
85+
myPage = 1
86+
checker2 = QgsCompositionChecker('composerhtml_multiframe2', self.mComposition)
87+
myTestResult, myMessage = checker2.testComposition( myPage )
88+
assert myTestResult, myMessage
11189

112-
myPage = 2
113-
checker3 = QgsCompositionChecker()
114-
myControlImage = self.controlImagePath(
115-
"composerhtml_table_multiframe3.png")
116-
myResult, myMessage = checker3.testComposition("Composer html table",
117-
self.mComposition,
118-
myControlImage,
119-
myPage)
12090
print "Checking page 3"
121-
assert myResult, myMessage
91+
myPage = 2
92+
checker3 = QgsCompositionChecker('composerhtml_multiframe3', self.mComposition)
93+
myTestResult, myMessage = checker3.testComposition( myPage )
94+
assert myTestResult, myMessage
12295

12396
def testComposerHtmlAccessor(self):
12497
"""Test that we can retrieve the ComposerHtml instance given an item.

‎tests/src/python/test_qgscomposermap.py

Lines changed: 20 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,8 @@ def testGrid(self):
9595
QgsComposerMap.Bottom)
9696
self.mComposerMap.setAnnotationFontColor(QColor(255,0,0,150))
9797
self.mComposerMap.setGridBlendMode(QPainter.CompositionMode_Overlay)
98-
checker = QgsCompositionChecker()
99-
myPath = os.path.join(TEST_DATA_DIR,
100-
'control_images',
101-
'expected_composermap',
102-
'composermap_landsat_grid.png')
103-
myTestResult, myMessage = checker.testComposition('Composer map grid',
104-
self.mComposition, myPath)
98+
checker = QgsCompositionChecker('composermap_grid', self.mComposition)
99+
myTestResult, myMessage = checker.testComposition()
105100
self.mComposerMap.setGridEnabled(False)
106101
self.mComposerMap.setShowGridAnnotation(False)
107102

@@ -119,15 +114,8 @@ def testOverviewMap(self):
119114
793062.375, 3350923.125)
120115
overviewMap.setNewExtent(myRectangle2)
121116
overviewMap.setOverviewFrameMap(self.mComposerMap.id())
122-
checker = QgsCompositionChecker()
123-
myPngPath = os.path.join(TEST_DATA_DIR,
124-
'control_images',
125-
'expected_composermap',
126-
'composermap_landsat_overview.png')
127-
myTestResult, myMessage = checker.testComposition(
128-
'Composer map overview',
129-
self.mComposition,
130-
myPngPath)
117+
checker = QgsCompositionChecker('composermap_overview', self.mComposition)
118+
myTestResult, myMessage = checker.testComposition()
131119
self.mComposition.removeComposerItem(overviewMap)
132120
assert myTestResult == True, myMessage
133121

@@ -144,15 +132,8 @@ def testOverviewMapBlend(self):
144132
overviewMap.setNewExtent(myRectangle2)
145133
overviewMap.setOverviewFrameMap(self.mComposerMap.id())
146134
overviewMap.setOverviewBlendMode(QPainter.CompositionMode_Multiply)
147-
checker = QgsCompositionChecker()
148-
myPngPath = os.path.join(TEST_DATA_DIR,
149-
'control_images',
150-
'expected_composermap',
151-
'composermap_landsat_overview_blend.png')
152-
myTestResult, myMessage = checker.testComposition(
153-
'Composer map overview blending',
154-
self.mComposition,
155-
myPngPath)
135+
checker = QgsCompositionChecker('composermap_overview_blending', self.mComposition)
136+
myTestResult, myMessage = checker.testComposition()
156137
self.mComposition.removeComposerItem(overviewMap)
157138
assert myTestResult == True, myMessage
158139

@@ -169,15 +150,8 @@ def testOverviewMapInvert(self):
169150
overviewMap.setNewExtent(myRectangle2)
170151
overviewMap.setOverviewFrameMap(self.mComposerMap.id())
171152
overviewMap.setOverviewInverted(True)
172-
checker = QgsCompositionChecker()
173-
myPngPath = os.path.join(TEST_DATA_DIR,
174-
'control_images',
175-
'expected_composermap',
176-
'composermap_landsat_overview_invert.png')
177-
myTestResult, myMessage = checker.testComposition(
178-
'Composer map overview inverted',
179-
self.mComposition,
180-
myPngPath)
153+
checker = QgsCompositionChecker('composermap_overview_invert', self.mComposition)
154+
myTestResult, myMessage = checker.testComposition()
181155
self.mComposition.removeComposerItem(overviewMap)
182156
assert myTestResult == True, myMessage
183157

@@ -195,15 +169,8 @@ def testOverviewMapCenter(self):
195169
overviewMap.setOverviewFrameMap(self.mComposerMap.id())
196170
overviewMap.setOverviewInverted(False)
197171
overviewMap.setOverviewCentered(True)
198-
checker = QgsCompositionChecker()
199-
myPngPath = os.path.join(TEST_DATA_DIR,
200-
'control_images',
201-
'expected_composermap',
202-
'composermap_landsat_overview_center.png')
203-
myTestResult, myMessage = checker.testComposition(
204-
'Composer map overview centered',
205-
self.mComposition,
206-
myPngPath)
172+
checker = QgsCompositionChecker('composermap_overview_center', self.mComposition)
173+
myTestResult, myMessage = checker.testComposition()
207174
self.mComposition.removeComposerItem(overviewMap)
208175
assert myTestResult == True, myMessage
209176

@@ -239,15 +206,16 @@ def testZebraStyle(self):
239206
self.mComposerMap.setGridEnabled(True)
240207
self.mComposerMap.setGridIntervalX(2000)
241208
self.mComposerMap.setGridIntervalY(2000)
242-
checker = QgsCompositionChecker()
243-
myPngPath = os.path.join(TEST_DATA_DIR,
244-
'control_images',
245-
'expected_composermap',
246-
'composermap_zebra_style.png')
247-
testResult, myMessage = checker.testComposition('Composer map zebra',
248-
self.mComposition,
249-
myPngPath)
250-
assert testResult == True, myMessage
209+
self.mComposerMap.setGridFrameWidth( 10 )
210+
self.mComposerMap.setGridFramePenSize( 1 )
211+
self.mComposerMap.setGridPenWidth( 0.5 )
212+
self.mComposerMap.setGridFramePenColor( QColor( 255, 100, 0, 200 ) )
213+
self.mComposerMap.setGridFrameFillColor1( QColor( 50, 90, 50, 100 ) )
214+
self.mComposerMap.setGridFrameFillColor2( QColor( 200, 220, 100, 60 ) )
215+
216+
checker = QgsCompositionChecker('composermap_zebrastyle', self.mComposition)
217+
myTestResult, myMessage = checker.testComposition()
218+
assert myTestResult == True, myMessage
251219

252220
def testWorldFileGeneration( self ):
253221
myRectangle = QgsRectangle(781662.375, 3339523.125, 793062.375, 3345223.125)

‎tests/src/python/test_qgscomposershapes.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,8 @@ def testRectangle(self):
5353

5454
self.mComposerShape.setShapeType(QgsComposerShape.Rectangle)
5555

56-
checker = QgsCompositionChecker()
57-
myPath = os.path.join(TEST_DATA_DIR,
58-
'control_images',
59-
'expected_composershapes',
60-
'composershape_rectangle.png')
61-
myTestResult, myMessage = checker.testComposition('Composer shapes rectangle',
62-
self.mComposition, myPath)
56+
checker = QgsCompositionChecker('composershapes_rectangle', self.mComposition)
57+
myTestResult, myMessage = checker.testComposition()
6358

6459
assert myTestResult == True, myMessage
6560

@@ -68,13 +63,8 @@ def testEllipse(self):
6863

6964
self.mComposerShape.setShapeType(QgsComposerShape.Ellipse)
7065

71-
checker = QgsCompositionChecker()
72-
myPath = os.path.join(TEST_DATA_DIR,
73-
'control_images',
74-
'expected_composershapes',
75-
'composershape_ellipse.png')
76-
myTestResult, myMessage = checker.testComposition('Composer shapes ellipse',
77-
self.mComposition, myPath)
66+
checker = QgsCompositionChecker('composershapes_ellipse', self.mComposition)
67+
myTestResult, myMessage = checker.testComposition()
7868

7969
assert myTestResult == True, myMessage
8070

@@ -83,13 +73,8 @@ def testTriangle(self):
8373

8474
self.mComposerShape.setShapeType(QgsComposerShape.Triangle)
8575

86-
checker = QgsCompositionChecker()
87-
myPath = os.path.join(TEST_DATA_DIR,
88-
'control_images',
89-
'expected_composershapes',
90-
'composershape_triangle.png')
91-
myTestResult, myMessage = checker.testComposition('Composer shapes triangle',
92-
self.mComposition, myPath)
76+
checker = QgsCompositionChecker('composershapes_triangle', self.mComposition)
77+
myTestResult, myMessage = checker.testComposition()
9378

9479
assert myTestResult == True, myMessage
9580

@@ -99,13 +84,8 @@ def testRoundedRectangle(self):
9984
self.mComposerShape.setShapeType(QgsComposerShape.Rectangle)
10085
self.mComposerShape.setCornerRadius(30)
10186

102-
checker = QgsCompositionChecker()
103-
myPath = os.path.join(TEST_DATA_DIR,
104-
'control_images',
105-
'expected_composershapes',
106-
'composershape_roundedrectangle.png')
107-
myTestResult, myMessage = checker.testComposition('Composer shapes rounded rectangle',
108-
self.mComposition, myPath)
87+
checker = QgsCompositionChecker('composershapes_roundedrect', self.mComposition)
88+
myTestResult, myMessage = checker.testComposition()
10989

11090
self.mComposerShape.setCornerRadius(0)
11191
assert myTestResult == True, myMessage
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.