提交 70f2010d 编写于 作者: J Julia Medina

Change error type when updating frozen settings

上级 3547ca6e
......@@ -88,7 +88,7 @@ class Settings(object):
return dict(value)
def set(self, name, value, priority='project'):
assert not self.frozen, "Trying to modify an immutable Settings object"
self._assert_mutability()
if isinstance(priority, six.string_types):
priority = SETTINGS_PRIORITIES[priority]
if name not in self.attributes:
......@@ -97,18 +97,22 @@ class Settings(object):
self.attributes[name].set(value, priority)
def setdict(self, values, priority='project'):
assert not self.frozen, "Trying to modify an immutable Settings object"
self._assert_mutability()
for name, value in six.iteritems(values):
self.set(name, value, priority)
def setmodule(self, module, priority='project'):
assert not self.frozen, "Trying to modify an immutable Settings object"
self._assert_mutability()
if isinstance(module, six.string_types):
module = import_module(module)
for key in dir(module):
if key.isupper():
self.set(key, getattr(module, key), priority)
def _assert_mutability(self):
if self.frozen:
raise TypeError("Trying to modify an immutable Settings object")
def copy(self):
return copy.deepcopy(self)
......
......@@ -213,7 +213,7 @@ class SettingsTest(unittest.TestCase):
def test_freeze(self):
self.settings.freeze()
with self.assertRaises(AssertionError) as cm:
with self.assertRaises(TypeError) as cm:
self.settings.set('TEST_BOOL', False)
self.assertEqual(str(cm.exception),
"Trying to modify an immutable Settings object")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册