Skip to content

Commit

Permalink
debugging ImmutableConfigValue
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbynum committed Mar 31, 2020
1 parent b5c7dd9 commit 00a211b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pyutilib/misc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,17 @@ class ImmutableConfigValue(ConfigValue):
def set_value(self, value):
raise RuntimeError(str(self) + ' is currently immutable')

def reset(self):
try:
super(ImmutableConfigValue, self).set_value(self._default)
except:
if hasattr(self._default, '__call__'):
super(ImmutableConfigValue, self).set_value(self._default())
else:
raise
self._userAccessed = False
self._userSet = False


class MarkImmutable(object):
"""
Expand Down
12 changes: 12 additions & 0 deletions pyutilib/misc/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ def test_immutable_config_value(self):
config.a = 6
self.assertEqual(config.a, 6)

config.declare('c', ConfigValue(default=-1, domain=int))
locker = MarkImmutable(config.get('a'), config.get('b'))
config2 = config({'c': -2})
self.assertEqual(config2.a, 6)
self.assertEqual(config2.b, 5)
self.assertEqual(config2.c, -2)
with self.assertRaises(Exception):
config3 = config({'a': 1})
locker.release_lock()
config3 = config({'a': 1})
self.assertEqual(config3.a, 1)


class Test(unittest.TestCase):

Expand Down

0 comments on commit 00a211b

Please sign in to comment.