def test__delitem__(self): d = LockableDict({'a': -1}) d.is_writeable = False with self.assertRaises(WriteableError): del d['a']
def test_setdefault(self): d = LockableDict() d.setdefault('a') self.assertEqual(d.setdefault('b', 5), 5) self.assertEqual(d, {'a': None, 'b': 5}) d.is_writeable = False with self.assertRaises(WriteableError): d.setdefault('c', None)
def test_clear(self): d = LockableDict({'a': -1}) d.is_writeable = False with self.assertRaises(WriteableError): d.clear() d.is_writeable = True d.clear() self.assertEqual(d, {})
def test_update(self): d = LockableDict() # check that it works normally d.update({'a': 1}) self.assertEqual(d, {'a': 1}) d.is_writeable = False with self.assertRaises(WriteableError): d.update({'b': -1})
def test_popitem(self): d = LockableDict({'a': -1, 'b': 2}) d.popitem() self.assertEqual(len(d), 1) d.is_writeable = False with self.assertRaises(WriteableError): d.popitem()
def test_pop_locked(self): d = LockableDict({'a': -1}) d.is_writeable = False with self.assertRaises(WriteableError): d.pop('a')
def test_pop(self): d = LockableDict({'a': -1}) self.assertEqual(d.pop('a'), -1)
def __setitem__(self, v, bias): adj = self._adj if v in adj: adj[v][v] = bias else: adj[v] = LockableDict({v: bias})