From c58ebfa657f91aa7d922555bc04dcd9081deea4c Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sat, 20 Mar 2021 00:54:45 +0100 Subject: [PATCH] readonly also prevents deletion --- owrx/property/__init__.py | 3 +++ test/property/test_property_readonly.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/owrx/property/__init__.py b/owrx/property/__init__.py index f04b115..88d80f4 100644 --- a/owrx/property/__init__.py +++ b/owrx/property/__init__.py @@ -264,6 +264,9 @@ class PropertyReadOnly(PropertyDelegator): def __setitem__(self, key, value): raise PropertyWriteError(key) + def __delitem__(self, key): + raise PropertyWriteError(key) + class PropertyStack(PropertyManager): def __init__(self): diff --git a/test/property/test_property_readonly.py b/test/property/test_property_readonly.py index a6e74f7..09d57ee 100644 --- a/test/property/test_property_readonly.py +++ b/test/property/test_property_readonly.py @@ -13,3 +13,11 @@ class PropertyReadOnlyTest(TestCase): ro["otherkey"] = "testvalue" self.assertEqual(ro["testkey"], "initial value") 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")