Skip to content
Permalink
Browse files
[Atlas] Add Python unit tests for feature sorting and filtering
  • Loading branch information
Hugo Mercier committed Feb 6, 2013
1 parent 12f85af commit 78e2222f5bfdfac7392d5244655a8d6dbc2e9c8d
Showing with 48 additions and 0 deletions.
  1. +48 −0 tests/src/python/test_qgsatlascomposition.py
@@ -164,6 +164,54 @@ def hidden_render_test( self ):
assert res[0] == True
self.mAtlas.endRender()

def sorting_render_test( self ):
self.mAtlasMap.setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
self.mAtlas.setFixedScale( True )
self.mAtlas.setHideCoverage( False )

self.mAtlas.setSortFeatures( True )
self.mAtlas.setSortKeyAttributeIndex( 4 ) # departement name
self.mAtlas.setSortAscending( False )

self.mAtlas.beginRender()

for i in range(0, 2):
self.mAtlas.prepareForFeature( i )
self.mLabel1.adjustSizeToText()

checker = QgsCompositionChecker()
res = checker.testComposition( "Atlas sorting test", self.mComposition, \
QString( self.TEST_DATA_DIR ) + QDir.separator() + \
"control_images" + QDir.separator() + \
"expected_composermapatlas" + QDir.separator() + \
QString( "sorting_%1.png" ).arg( i ) )
assert res[0] == True
self.mAtlas.endRender()

def filtering_render_test( self ):
self.mAtlasMap.setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
self.mAtlas.setFixedScale( True )
self.mAtlas.setHideCoverage( False )

self.mAtlas.setSortFeatures( False )

self.mAtlas.setFeatureFilter( "substr(NAME_1,1,1)='P'" ) # select only 'Pays de la loire'

self.mAtlas.beginRender()

for i in range(0, 1):
self.mAtlas.prepareForFeature( i )
self.mLabel1.adjustSizeToText()

checker = QgsCompositionChecker()
res = checker.testComposition( "Atlas filtering test", self.mComposition, \
QString( self.TEST_DATA_DIR ) + QDir.separator() + \
"control_images" + QDir.separator() + \
"expected_composermapatlas" + QDir.separator() + \
QString( "filtering_%1.png" ).arg( i ) )
assert res[0] == True
self.mAtlas.endRender()

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

0 comments on commit 78e2222

Please sign in to comment.