Пример #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})