Skip to content
Permalink
Browse files

Add test that providers always accept features with null geometry

  • Loading branch information
nyalldawson committed Feb 17, 2018
1 parent 0e68a3e commit 141caddb62e10df34bab7e0f33330d6eba9d5d3a
Showing with 16 additions and 3 deletions.
  1. +16 −3 tests/src/python/providertestbase.py
@@ -488,7 +488,7 @@ def testAddFeatureExtraAttributes(self):
self.assertTrue(result,
'Provider returned False to addFeatures with extra attributes. Providers should accept these features but truncate the extra attributes.')

# make sure feature was added correctyl
# make sure feature was added correctly
added = [f for f in l.dataProvider().getFeatures() if f['pk'] == 7][0]
self.assertEqual(added.attributes(), [7, -230, NULL, 'String', '15'])

@@ -506,15 +506,28 @@ def testAddFeatureWrongGeomType(self):
# we be more tricky and also add a valid feature to stress test the provider
f1 = QgsFeature()
f1.setGeometry(QgsGeometry.fromWkt('LineString (-72.345 71.987, -80 80)'))
f1.setAttributes([7])
f2 = QgsFeature()
f2.setGeometry(QgsGeometry.fromWkt('Point (-72.345 71.987)'))
f2.setAttributes([8])

result, added = l.dataProvider().addFeatures([f1, f2])
self.assertFalse(result, 'Provider returned True to addFeatures with incorrect geometry type. Providers should reject these features.')

# make sure feature was not added
added = [f for f in l.dataProvider().getFeatures() if f['pk'] == 7]
self.assertFalse(added)
added = [f for f in l.dataProvider().getFeatures() if f['pk'] == 8]
self.assertTrue(added)

# yet providers MUST always accept null geometries
f3 = QgsFeature()
f3.setAttributes([9])
result, added = l.dataProvider().addFeatures([f3])
self.assertTrue(result,
'Provider returned False to addFeatures with null geometry. Providers should always accept these features.')

# make sure feature was added correctly
added = [f for f in l.dataProvider().getFeatures() if f['pk'] == 9][0]
self.assertFalse(added.hasGeometry())

def testAddFeaturesUpdateExtent(self):
if not getattr(self, 'getEditableLayer', None):

0 comments on commit 141cadd

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