Beispiel #1
0
 def test_init(self):
     # should only allow things that can be mapped (e.g. dictionary)
     # and that have a copy() function
     with self.assertRaises(AssertionError):
         x = ro_types.ReadOnlyDict([])
     # should work with a dictionary
     x = ro_types.ReadOnlyDict({'a': 1, 'b': 2})
     # should work with an OrderedDict
     x = ro_types.ReadOnlyDict(collections.OrderedDict([('a', 1),
                                                        ('b', 2)]))
     # check that the data is copied
     b = {'a': 1}
     x = ro_types.ReadOnlyDict(b)
     b['a'] = 2
     self.assertEqual(x['a'], 1)
Beispiel #2
0
 def test_serialize(self):
     x = ro_types.ReadOnlyDict({'a': 1})
     self.assertEqual(x.__serialize__(), {'a': 1})
Beispiel #3
0
 def test_iter(self):
     x = ro_types.ReadOnlyDict(collections.OrderedDict([('a', 1),
                                                        ('b', 5)]))
     self.assertEqual(list(iter(x)), ['a', 'b'])
Beispiel #4
0
 def test_setitem(self):
     x = ro_types.ReadOnlyDict({'a': 1, 'b': 5})
     with self.assertRaises(TypeError):
         x['c'] = 1
Beispiel #5
0
 def test_setattr(self):
     x = ro_types.ReadOnlyDict({'a': 1, 'b': 5})
     with self.assertRaises(TypeError):
         x.c = 1
Beispiel #6
0
 def test_getattr(self):
     x = ro_types.ReadOnlyDict({'a': 1, 'b': 5})
     self.assertEqual(x.a, 1)
     self.assertEqual(x.b, 5)
     with self.assertRaises(KeyError):
         x.c
Beispiel #7
0
 def test_getitem(self):
     x = ro_types.ReadOnlyDict({'a': 1, 'b': 5})
     self.assertEqual(x['a'], 1)
     self.assertEqual(x['b'], 5)
     with self.assertRaises(KeyError):
         x['c']