Skip to content
Permalink
Browse files

Added tests for malformed subsetstrings on the ogr provider

  • Loading branch information
uclaros committed Feb 9, 2020
1 parent 0b4cc5a commit 5bf937f070ce363942ef20236cce6c9ce531e670
Showing with 21 additions and 0 deletions.
  1. +21 −0 tests/src/python/test_provider_shapefile.py
@@ -712,6 +712,27 @@ def _lessdigits(s):
self.assertEqual(_lessdigits(subSet_vl.extent().toString()), filtered_extent)
self.assertNotEqual(_lessdigits(subSet_vl.extent().toString()), unfiltered_extent)

def testMalformedSubsetStrings(self):
"""Test that invalid where clauses allways return false"""

testPath = TEST_DATA_DIR + '/' + 'lines.shp'

vl = QgsVectorLayer(testPath, 'subset_test', 'ogr')
self.assertTrue(vl.isValid())
self.assertTrue(vl.setSubsetString(''))
self.assertTrue(vl.setSubsetString('"Name" = \'Arterial\''))
self.assertTrue(vl.setSubsetString('select * from lines where "Name" = \'Arterial\''))
self.assertFalse(vl.setSubsetString('this is invalid sql'))
self.assertFalse(vl.setSubsetString('select * from lines where "NonExistantField" = \'someValue\''))
self.assertFalse(vl.setSubsetString('select * from lines where "Name" = \'Arte...'))
self.assertFalse(vl.setSubsetString('select * from lines where "Name" in (\'Arterial\', \'Highway\' '))
self.assertFalse(vl.setSubsetString('select * from NonExistingTable'))
self.assertFalse(vl.setSubsetString('select NonExistingField from lines'))
self.assertFalse(vl.setSubsetString('"NonExistantField" = \'someValue\''))
self.assertFalse(vl.setSubsetString('"Name" = \'Arte...'))
self.assertFalse(vl.setSubsetString('"Name" in (\'Arterial\', \'Highway\' '))
self.assertTrue(vl.setSubsetString(''))

def testMultipatch(self):
"""Check that we can deal with multipatch shapefiles, returned natively by OGR as GeometryCollection of TIN"""

0 comments on commit 5bf937f

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