Skip to content
Permalink
Browse files

More tests

  • Loading branch information
nyalldawson committed Jun 2, 2018
1 parent 314942d commit 477fb89fdff075ca05c22ea07d1fff31d2178796
Showing with 34 additions and 1 deletion.
  1. +34 −1 tests/src/python/test_provider_ogr_sqlite.py
@@ -19,7 +19,13 @@
import shutil
from osgeo import gdal, ogr

from qgis.core import QgsVectorLayer, QgsFeature, QgsFeatureRequest, QgsFieldConstraints, QgsFieldConstraints, QgsPointXY, NULL
from qgis.core import (QgsVectorLayer,
QgsFeature,
QgsFeatureRequest,
QgsFieldConstraints,
QgsPointXY,
NULL,
QgsRectangle)
from qgis.testing import start_app, unittest
from qgis.PyQt.QtCore import QDate, QTime, QDateTime

@@ -260,6 +266,7 @@ def testSubsetStringFids(self):
def run_checks():
self.assertEqual([f.name() for f in vl.fields()], ['fid', 'type', 'value'])

# expression
req = QgsFeatureRequest()
req.setFilterExpression("value=16")
it = vl.getFeatures(req)
@@ -270,6 +277,7 @@ def run_checks():
self.assertEqual([field.name() for field in f.fields()], ['fid', 'type', 'value'])
self.assertEqual(f.geometry().asWkt(), 'Point (5 5)')

# filter fid
req = QgsFeatureRequest()
req.setFilterFid(5)
it = vl.getFeatures(req)
@@ -280,6 +288,7 @@ def run_checks():
self.assertEqual([field.name() for field in f.fields()], ['fid', 'type', 'value'])
self.assertEqual(f.geometry().asWkt(), 'Point (5 5)')

# filter fids
req = QgsFeatureRequest()
req.setFilterFids([5])
it = vl.getFeatures(req)
@@ -290,6 +299,30 @@ def run_checks():
self.assertEqual([field.name() for field in f.fields()], ['fid', 'type', 'value'])
self.assertEqual(f.geometry().asWkt(), 'Point (5 5)')

# check with subset of attributes
req = QgsFeatureRequest()
req.setFilterFids([5])
req.setSubsetOfAttributes([2])
it = vl.getFeatures(req)
f = QgsFeature()
self.assertTrue(it.nextFeature(f))
self.assertEqual(f.id(), 5)
self.assertEqual(f.attributes()[2], 16)
self.assertEqual([field.name() for field in f.fields()], ['fid', 'type', 'value'])
self.assertEqual(f.geometry().asWkt(), 'Point (5 5)')

# filter rect and expression
req = QgsFeatureRequest()
req.setFilterExpression("value=16 or value=14")
req.setFilterRect(QgsRectangle(4.5, 4.5, 5.5, 5.5))
it = vl.getFeatures(req)
f = QgsFeature()
self.assertTrue(it.nextFeature(f))
self.assertEqual(f.id(), 5)
self.assertEqual(f.attributes(), [5, 2, 16])
self.assertEqual([field.name() for field in f.fields()], ['fid', 'type', 'value'])
self.assertEqual(f.geometry().asWkt(), 'Point (5 5)')

# Ensure that orig_ogc_fid is still retrieved even if attribute subset is passed
req = QgsFeatureRequest()
req.setSubsetOfAttributes([])

0 comments on commit 477fb89

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