Bug 1053069 - Make mozbuild.util.ReadOnlyDefaultDict raise an exception on update() and del. r=gps

This commit is contained in:
Mike Hommey 2014-08-14 07:15:38 +09:00
parent 7df99e7ce4
commit 3bbfbdbb84
4 changed files with 29 additions and 5 deletions

View File

@ -27,9 +27,7 @@ class MockConfig(object):
'MOZ_BAR': 'bar',
'MOZ_TRUE': '1',
'MOZ_FALSE': '',
})
self.substs.update(extra_substs)
}, **extra_substs)
self.substs_unicode = ReadOnlyDict({k.decode('utf-8'): v.decode('utf-8',
'replace') for k, v in self.substs.items()})

View File

@ -220,7 +220,7 @@ class TestEmitterBasic(unittest.TestCase):
reader = self.reader('resources')
objs = self.read_topsrcdir(reader)
expected_defines = reader.config.defines
expected_defines = dict(reader.config.defines)
expected_defines.update({
'FOO': True,
'BAR': 'BAZ',

View File

@ -27,6 +27,26 @@ class TestReadOnlyDict(unittest.TestCase):
with self.assertRaises(Exception):
test['baz'] = True
def test_update(self):
original = {'foo': 1, 'bar': 2}
test = ReadOnlyDict(original)
with self.assertRaises(Exception):
test.update(foo=2)
self.assertEqual(original, test)
def test_del(self):
original = {'foo': 1, 'bar': 2}
test = ReadOnlyDict(original)
with self.assertRaises(Exception):
del test['foo']
self.assertEqual(original, test)
class TestReadOnlyDefaultDict(unittest.TestCase):
def test_simple(self):

View File

@ -53,9 +53,15 @@ class ReadOnlyDict(dict):
def __init__(self, *args, **kwargs):
dict.__init__(self, *args, **kwargs)
def __setitem__(self, name, value):
def __delitem__(self, key):
raise Exception('Object does not support deletion.')
def __setitem__(self, key, value):
raise Exception('Object does not support assignment.')
def update(self, *args, **kwargs):
raise Exception('Object does not support update.')
class undefined_default(object):
"""Represents an undefined argument value that isn't None."""