Skip to content

Commit a993021

Browse files
committedOct 23, 2020
tests for custom property set / read and the signal customPropertyChanged
1 parent eaac69b commit a993021

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
 

‎tests/src/python/test_qgsvectorlayer.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,46 @@ def testSetDataSourceInvalidToValid(self):
399399
# should STILL have kept renderer!
400400
self.assertEqual(layer.renderer(), r)
401401

402+
def testSetCustomProperty(self):
403+
"""
404+
Test setting a custom property of the layer
405+
"""
406+
layer = createLayerWithOnePoint()
407+
layer.setCustomProperty('Key_0', 'Value_0')
408+
layer.setCustomProperty('Key_1', 'Value_1')
409+
410+
spy = QSignalSpy(layer.customPropertyChanged)
411+
412+
# change nothing by setting the same value
413+
layer.setCustomProperty('Key_0', 'Value_0')
414+
layer.setCustomProperty('Key_1', 'Value_1')
415+
self.assertEqual(len(spy), 0)
416+
417+
# change one
418+
layer.setCustomProperty('Key_0', 'Value zero')
419+
self.assertEqual(len(spy), 1)
420+
421+
# add one
422+
layer.setCustomProperty('Key_2', 'Value two')
423+
self.assertEqual(len(spy), 2)
424+
425+
# add a null one and an empty one
426+
layer.setCustomProperty('Key_3', None)
427+
layer.setCustomProperty('Key_4', '')
428+
self.assertEqual(len(spy), 4)
429+
430+
# remove one
431+
layer.removeCustomProperty('Key_0')
432+
self.assertEqual(len(spy), 5)
433+
434+
self.assertEqual(layer.customProperty('Key_0', 'no value'), 'no value')
435+
self.assertEqual(layer.customProperty('Key_1', 'no value'), 'Value_1')
436+
self.assertEqual(layer.customProperty('Key_2', 'no value'), 'Value two')
437+
self.assertEqual(layer.customProperty('Key_3', 'no value'), None)
438+
self.assertEqual(layer.customProperty('Key_4', 'no value'), '')
439+
440+
self.assertEqual(len(spy), 5)
441+
402442
def testStoreWkbTypeInvalidLayers(self):
403443
"""
404444
Test that layer wkb types are restored for projects with invalid layer paths

0 commit comments

Comments
 (0)
Please sign in to comment.