AttrCtrl: fix __delattr__ bug, add test
This commit is contained in:
parent
6620db4158
commit
79985e2280
2 changed files with 6 additions and 2 deletions
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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 ),
|
||||
))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue