Browse Source

AttrCtrl: fix __delattr__ bug, add test

The MMGen Project 1 year ago
parent
commit
79985e2280
2 changed files with 6 additions and 2 deletions
  1. 4 2
      mmgen/base_obj.py
  2. 2 0
      test/unit_tests_d/ut_lockable.py

+ 4 - 2
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):
 	"""

+ 2 - 0
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 ),
 		))