From 57a57545a038e09036afc78f2f7b86c43e265c50 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Mon, 31 Oct 2016 13:42:53 +0100 Subject: [PATCH] Add test for QgsFeatureRequest.setLimit and feature variable --- tests/src/python/providertestbase.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/src/python/providertestbase.py b/tests/src/python/providertestbase.py index a10ad0bae23..a492ac1d58f 100644 --- a/tests/src/python/providertestbase.py +++ b/tests/src/python/providertestbase.py @@ -15,7 +15,16 @@ __copyright__ = 'Copyright 2015, The QGIS Project' # 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 @@ class ProviderTestCase(object): # 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: