Skip to content
Permalink
Browse files

Add extra checks to provider test:

- test that fetching subset of attributes results in nulls for
all other fields
- test that geometry is fetched by default, but empty when
NoGeometry flag is passed
  • Loading branch information
nyalldawson committed Mar 5, 2016
1 parent c8a73da commit 1e7eae77e1444f3e0fdb27bcbd05e741bc21ebea
Showing with 48 additions and 0 deletions.
  1. +24 −0 tests/src/python/providertestbase.py
  2. +24 −0 tests/src/python/test_provider_memory.py
@@ -395,3 +395,27 @@ def testGetFeaturesSubsetAttributes(self):
for field, expected in tests.iteritems():
result = set([f[field] for f in self.provider.getFeatures(QgsFeatureRequest().setSubsetOfAttributes([field], self.provider.fields()))])
self.assertEqual(result, expected, 'Expected {}, got {}'.format(expected, result))

def testGetFeaturesSubsetAttributes2(self):
""" Test that other fields are NULL wen fetching subsets of attributes """

for field_to_fetch in ['pk', 'cnt', 'name', 'name2']:
for f in self.provider.getFeatures(QgsFeatureRequest().setSubsetOfAttributes([field_to_fetch], self.provider.fields())):
# Check that all other fields are NULL
for other_field in [field.name() for field in self.provider.fields() if field.name() != field_to_fetch]:
self.assertEqual(f[other_field], NULL, 'Value for field "{}" was present when it should not have been fetched by request'.format(other_field))

def testGetFeaturesNoGeometry(self):
""" Test that no geometry is present when fetching features without geometry"""

for f in self.provider.getFeatures(QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry)):
self.assertFalse(f.constGeometry(), 'Expected no geometry, got one')

def testGetFeaturesNoGeometry(self):
""" Test that geometry is present when fetching features without setting NoGeometry flag"""
for f in self.provider.getFeatures(QgsFeatureRequest()):
if f['pk'] == 3:
# no geometry for this feature
continue

assert f.constGeometry(), 'Expected geometry, got none'
@@ -106,6 +106,18 @@ def setUpClass(cls):
def tearDownClass(cls):
"""Run after all tests"""

def testGetFeaturesSubsetAttributes2(self):
""" Override and skip this test for memory provider, as it's actually more efficient for the memory provider to return
its features as direct copies (due to implicit sharing of QgsFeature)
"""
pass

def testGetFeaturesNoGeometry(self):
""" Override and skip this test for memory provider, as it's actually more efficient for the memory provider to return
its features as direct copies (due to implicit sharing of QgsFeature)
"""
pass

def testCtors(self):
testVectors = ["Point", "LineString", "Polygon", "MultiPoint", "MultiLineString", "MultiPolygon", "None"]
for v in testVectors:
@@ -317,5 +329,17 @@ def setUpClass(cls):
def tearDownClass(cls):
"""Run after all tests"""

def testGetFeaturesSubsetAttributes2(self):
""" Override and skip this test for memory provider, as it's actually more efficient for the memory provider to return
its features as direct copies (due to implicit sharing of QgsFeature)
"""
pass

def testGetFeaturesNoGeometry(self):
""" Override and skip this test for memory provider, as it's actually more efficient for the memory provider to return
its features as direct copies (due to implicit sharing of QgsFeature)
"""
pass

if __name__ == '__main__':
unittest.main()

0 comments on commit 1e7eae7

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