Skip to content

Commit 342897c

Browse files
committed
Add source test for vector layer with deleted features in buffer
1 parent 3f81fc0 commit 342897c

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

tests/src/python/test_qgsvectorlayer.py

+86
Original file line numberDiff line numberDiff line change
@@ -2572,10 +2572,96 @@ def testOrderBy(self):
25722572
"""
25732573
pass
25742574

2575+
2576+
class TestQgsVectorLayerSourceDeletedFeaturesInBuffer(unittest.TestCase, FeatureSourceTestCase):
2577+
2578+
@classmethod
2579+
def getSource(cls):
2580+
vl = QgsVectorLayer(
2581+
'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk',
2582+
'test', 'memory')
2583+
assert (vl.isValid())
2584+
2585+
# add a bunch of similar features to the provider
2586+
b1 = QgsFeature()
2587+
b1.setAttributes([5, -300, 'Apple', 'PEaR', '1'])
2588+
b1.setGeometry(QgsGeometry.fromWkt('Point (-70.332 66.33)'))
2589+
2590+
b2 = QgsFeature()
2591+
b2.setAttributes([3, 100, 'Orange', 'NuLl', '2'])
2592+
b2.setGeometry(QgsGeometry.fromWkt('Point (-71.123 78.23)'))
2593+
2594+
b3 = QgsFeature()
2595+
b3.setAttributes([1, -200, 'Honey', 'oranGe', '5'])
2596+
2597+
b4 = QgsFeature()
2598+
b4.setAttributes([2, 400, 'Pear', 'Honey', '3'])
2599+
b4.setGeometry(QgsGeometry.fromWkt('Point (-65.32 78.3)'))
2600+
2601+
b5 = QgsFeature()
2602+
b5.setAttributes([4, 200, NULL, 'oranGe', '3'])
2603+
b5.setGeometry(QgsGeometry.fromWkt('Point (-68.2 70.8)'))
2604+
2605+
vl.dataProvider().addFeatures([b1, b2, b3, b4, b5])
2606+
2607+
bad_ids = [f['pk'] for f in vl.getFeatures()]
2608+
2609+
# here's our good features
2610+
f1 = QgsFeature()
2611+
f1.setAttributes([5, -200, NULL, 'NuLl', '5'])
2612+
f1.setGeometry(QgsGeometry.fromWkt('Point (-71.123 78.23)'))
2613+
2614+
f2 = QgsFeature()
2615+
f2.setAttributes([3, 300, 'Pear', 'PEaR', '3'])
2616+
2617+
f3 = QgsFeature()
2618+
f3.setAttributes([1, 100, 'Orange', 'oranGe', '1'])
2619+
f3.setGeometry(QgsGeometry.fromWkt('Point (-70.332 66.33)'))
2620+
2621+
f4 = QgsFeature()
2622+
f4.setAttributes([2, 200, 'Apple', 'Apple', '2'])
2623+
f4.setGeometry(QgsGeometry.fromWkt('Point (-68.2 70.8)'))
2624+
2625+
f5 = QgsFeature()
2626+
f5.setAttributes([4, 400, 'Honey', 'Honey', '4'])
2627+
f5.setGeometry(QgsGeometry.fromWkt('Point (-65.32 78.3)'))
2628+
2629+
vl.dataProvider().addFeatures([f1, f2, f3, f4, f5])
2630+
2631+
# delete the bad features, but don't commit
2632+
vl.startEditing()
2633+
vl.deleteFeatures(bad_ids)
2634+
return vl
2635+
2636+
@classmethod
2637+
def setUpClass(cls):
2638+
"""Run before all tests"""
2639+
# Create test layer for FeatureSourceTestCase
2640+
cls.source = cls.getSource()
2641+
2642+
def testGetFeaturesSubsetAttributes2(self):
2643+
""" Override and skip this QgsFeatureSource test. We are using a memory provider, and it's actually more efficient for the memory provider to return
2644+
its features as direct copies (due to implicit sharing of QgsFeature)
2645+
"""
2646+
pass
2647+
2648+
def testGetFeaturesNoGeometry(self):
2649+
""" Override and skip this QgsFeatureSource test. We are using a memory provider, and it's actually more efficient for the memory provider to return
2650+
its features as direct copies (due to implicit sharing of QgsFeature)
2651+
"""
2652+
pass
2653+
2654+
def testOrderBy(self):
2655+
""" Skip order by tests - edited features are not sorted in iterators.
2656+
(Maybe they should be??)
2657+
"""
2658+
pass
2659+
25752660
# TODO:
25762661
# - fetch rect: feat with changed geometry: 1. in rect, 2. out of rect
25772662
# - more join tests
25782663
# - import
25792664

2665+
25802666
if __name__ == '__main__':
25812667
unittest.main()

0 commit comments

Comments
 (0)