예제 #1
0
    def test__delitem__(self):
        d = LockableDict({'a': -1})

        d.is_writeable = False

        with self.assertRaises(WriteableError):
            del d['a']
예제 #2
0
    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)
예제 #3
0
    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, {})
예제 #4
0
    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})
예제 #5
0
    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()
예제 #6
0
    def test_pop_locked(self):
        d = LockableDict({'a': -1})
        d.is_writeable = False

        with self.assertRaises(WriteableError):
            d.pop('a')
예제 #7
0
 def test_pop(self):
     d = LockableDict({'a': -1})
     self.assertEqual(d.pop('a'), -1)
예제 #8
0
 def __setitem__(self, v, bias):
     adj = self._adj
     if v in adj:
         adj[v][v] = bias
     else:
         adj[v] = LockableDict({v: bias})