Esempio n. 1
0
    def test_freeze_thaw_cycle(self):
        # freeze then thaw
        d = FreezableDict(a=1).freeze().thaw()
        self.assertRaises(TypeError, lambda: {d: 1})

        d['b'] = 2

        # then refreeze
        d.freeze()
        self.assertEqual({d: 1}[d], 1)
Esempio n. 2
0
    def test_frozen_delitem(self):
        d = FreezableDict(a=1).freeze()

        def f():
            del d['a']

        self.assertRaises(TypeError, f)
Esempio n. 3
0
    def test_frozen_setitem(self):
        d = FreezableDict(a=2).freeze()

        def f():
            d['a'] = 1

        self.assertRaises(TypeError, f)
Esempio n. 4
0
 def test_dict_methods(self):
     fd = FreezableDict(a=1, b=2)
     d = dict(a=1, b=2)
     for method in ['items', 'keys', 'values']:
         self.assertEqual(
             list(getattr(d, method)()),
             list(getattr(fd, method)()),
         )
Esempio n. 5
0
 def test_thawed_setitem(self):
     d = FreezableDict(a=2)
     d['a'] = 1
     self.assertEqual(d['a'], 1)
Esempio n. 6
0
 def test_thawed_unhashability(self):
     d = FreezableDict(a=1)
     self.assertRaises(TypeError, lambda: {d: 1})
Esempio n. 7
0
 def test_frozen_hashability(self):
     d = FreezableDict(a=1).freeze()
     self.assertEqual({d: 1, 'b': 2}[d], 1)
Esempio n. 8
0
 def test_thawed_delitem(self):
     d = FreezableDict(a=1)
     del d['a']
     self.assertRaises(KeyError, lambda: d['a'])