12
12
# This will get replaced with a git SHA1 when you do a git archive
13
13
__revision__ = '$Format:%H$'
14
14
15
- from qgis .core import QgsRectangle , QgsFeatureRequest , QgsFeature , QgsGeometry , NULL
15
+ from qgis .core import QgsRectangle , QgsFeatureRequest , QgsFeature , QgsGeometry , QgsAbstractFeatureIterator , NULL
16
16
17
17
from utilities import (
18
18
compareWkt
@@ -61,10 +61,31 @@ def testGetFeatures(self):
61
61
else :
62
62
self .assertFalse (geometries [pk ], 'Expected null geometry for {}' .format (pk ))
63
63
64
+ def uncompiledFilters (self ):
65
+ """ Individual derived provider tests should override this to return a list of expressions which
66
+ cannot be compiled """
67
+ return set ()
68
+
69
+ def partiallyCompiledFilters (self ):
70
+ """ Individual derived provider tests should override this to return a list of expressions which
71
+ should be partially compiled """
72
+ return set ()
73
+
64
74
def assert_query (self , provider , expression , expected ):
65
75
result = set ([f ['pk' ] for f in provider .getFeatures (QgsFeatureRequest ().setFilterExpression (expression ))])
66
76
assert set (expected ) == result , 'Expected {} and got {} when testing expression "{}"' .format (set (expected ), result , expression )
67
77
78
+ if self .compiled :
79
+ # Check compilation status
80
+ it = provider .getFeatures (QgsFeatureRequest ().setFilterExpression (expression ))
81
+
82
+ if expression in self .uncompiledFilters ():
83
+ self .assertEqual (it .compileStatus (), QgsAbstractFeatureIterator .NoCompilation )
84
+ elif expression in self .partiallyCompiledFilters ():
85
+ self .assertEqual (it .compileStatus (), QgsAbstractFeatureIterator .PartiallyCompiled )
86
+ else :
87
+ self .assertEqual (it .compileStatus (), QgsAbstractFeatureIterator .Compiled )
88
+
68
89
# Also check that filter works when referenced fields are not being retrieved by request
69
90
result = set ([f ['pk' ] for f in provider .getFeatures (QgsFeatureRequest ().setFilterExpression (expression ).setSubsetOfAttributes ([0 ]))])
70
91
assert set (expected ) == result , 'Expected {} and got {} when testing expression "{}" using empty attribute subset' .format (set (expected ), result , expression )
@@ -155,6 +176,7 @@ def runGetFeatureTests(self, provider):
155
176
self .assert_query (provider , 'num_char IN (2, 4, 5)' , [2 , 4 , 5 ])
156
177
157
178
def testGetFeaturesUncompiled (self ):
179
+ self .compiled = False
158
180
try :
159
181
self .disableCompiler ()
160
182
except AttributeError :
@@ -164,6 +186,7 @@ def testGetFeaturesUncompiled(self):
164
186
def testGetFeaturesCompiled (self ):
165
187
try :
166
188
self .enableCompiler ()
189
+ self .compiled = True
167
190
self .runGetFeatureTests (self .provider )
168
191
except AttributeError :
169
192
print ('Provider does not support compiling' )
0 commit comments