Skip to content

Commit

Permalink
Add test for QgsFeatureRequest.setLimit and feature variable
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn authored and nyalldawson committed Nov 1, 2016
1 parent fb84962 commit 57a5754
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/src/python/providertestbase.py
Expand Up @@ -15,7 +15,16 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from qgis.core import QgsRectangle, QgsFeatureRequest, QgsFeature, QgsGeometry, QgsAbstractFeatureIterator, NULL
from qgis.core import (
QgsRectangle,
QgsFeatureRequest,
QgsFeature,
QgsGeometry,
QgsAbstractFeatureIterator,
QgsExpressionContextScope,
QgsExpressionContext,
NULL
)

from utilities import(
compareWkt
Expand Down Expand Up @@ -190,6 +199,21 @@ def runGetFeatureTests(self, provider):
# geometry
self.assert_query(provider, 'intersects($geometry,geom_from_wkt( \'Polygon ((-72.2 66.1, -65.2 66.1, -65.2 72.0, -72.2 72.0, -72.2 66.1))\'))', [1, 2])

# combination of an uncompilable expression and limit
feature = next(self.vl.getFeatures('pk=4'))
context = QgsExpressionContext()
scope = QgsExpressionContextScope()
scope.setVariable('parent', feature)
context.appendScope(scope)

request = QgsFeatureRequest()
request.setExpressionContext(context)
request.setFilterExpression('"pk" = attribute(@parent, \'pk\')')
request.setLimit(1)

values = [f['pk'] for f in self.vl.getFeatures(request)]
self.assertEqual(values, [4])

def testGetFeaturesUncompiled(self):
self.compiled = False
try:
Expand Down

0 comments on commit 57a5754

Please sign in to comment.