readonly also prevents deletion

This commit is contained in:
Jakob Ketterl 2021-03-20 00:54:45 +01:00
parent c50473fea5
commit c58ebfa657
2 changed files with 11 additions and 0 deletions

View File

@ -264,6 +264,9 @@ class PropertyReadOnly(PropertyDelegator):
def __setitem__(self, key, value): def __setitem__(self, key, value):
raise PropertyWriteError(key) raise PropertyWriteError(key)
def __delitem__(self, key):
raise PropertyWriteError(key)
class PropertyStack(PropertyManager): class PropertyStack(PropertyManager):
def __init__(self): def __init__(self):

View File

@ -13,3 +13,11 @@ class PropertyReadOnlyTest(TestCase):
ro["otherkey"] = "testvalue" ro["otherkey"] = "testvalue"
self.assertEqual(ro["testkey"], "initial value") self.assertEqual(ro["testkey"], "initial value")
self.assertNotIn("otherkey", ro) self.assertNotIn("otherkey", ro)
def testPreventsDeletes(self):
layer = PropertyLayer(testkey="some value")
ro = PropertyReadOnly(layer)
with self.assertRaises(PropertyWriteError):
del ro["testkey"]
self.assertEqual(ro["testkey"], "some value")
self.assertEqual(layer["testkey"], "some value")