Skip to content
Permalink
Browse files

Add test for QgsFeatureRequest.setLimit and feature variable

  • Loading branch information
m-kuhn authored and nyalldawson committed Nov 1, 2016
1 parent fb84962 commit 57a57545a038e09036afc78f2f7b86c43e265c50
Showing with 25 additions and 1 deletion.
  1. +25 −1 tests/src/python/providertestbase.py
@@ -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
@@ -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:

0 comments on commit 57a5754

Please sign in to comment.
You can’t perform that action at this time.