AttrCtrl: fix __delattr__ bug, add test

This commit is contained in:
The MMGen Project 2023-05-04 18:06:09 +00:00
commit 79985e2280
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 6 additions and 2 deletions

View file

@ -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):
"""

View file

@ -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 ),
))