From 79985e228007d303b47075a36cc2078be1ef31a6 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 4 May 2023 18:06:09 +0000 Subject: [PATCH] AttrCtrl: fix __delattr__ bug, add test --- mmgen/base_obj.py | 6 ++++-- test/unit_tests_d/ut_lockable.py | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mmgen/base_obj.py b/mmgen/base_obj.py index dccb3660..3086250b 100755 --- a/mmgen/base_obj.py +++ b/mmgen/base_obj.py @@ -87,8 +87,10 @@ class AttrCtrl(metaclass=AttrCtrlMeta): return object.__setattr__(self,name,value) - def __delattr__(self,name,value): - raise AttributeError('attribute cannot be deleted') + def __delattr__(self,name): + if self._locked: + raise AttributeError('attribute cannot be deleted') + return object.__delattr__(self,name) class Lockable(AttrCtrl): """ diff --git a/test/unit_tests_d/ut_lockable.py b/test/unit_tests_d/ut_lockable.py index a17065d1..d5cd6af4 100755 --- a/test/unit_tests_d/ut_lockable.py +++ b/test/unit_tests_d/ut_lockable.py @@ -153,6 +153,7 @@ class unit_test(object): def bad19(): acdn.baz = None def bad20(): lcdn.foo = 1 def bad21(): lcdn.bar = None + def bad22(): del lcdn.foo ut.process_bad_data(( ('attr (1)', 'AttributeError', 'has no attr', bad1 ), @@ -175,6 +176,7 @@ class unit_test(object): ("attr (can't reset)", 'AttributeError', 'reset', bad15 ), ("attr (can't set)", 'AttributeError', 'read-only', bad16 ), ("attr (bad _set_ok)", 'AssertionError', 'not found in',bad17 ), + ("attr (can’t delete)",'AttributeError', 'not be delet',bad22 ), ("call to _lock()", 'AssertionError', 'only once', bad18 ), ))