@@ -399,6 +399,46 @@ def testSetDataSourceInvalidToValid(self):
399
399
# should STILL have kept renderer!
400
400
self .assertEqual (layer .renderer (), r )
401
401
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
+
402
442
def testStoreWkbTypeInvalidLayers (self ):
403
443
"""
404
444
Test that layer wkb types are restored for projects with invalid layer paths
0 commit comments