示例#1
0
 def test_setitem_TypeError(self):
     rgb = FixedKeyMap(red='rouge', green='forest', blue='azul')
     with self.assertRaises(TypeError) as context:
         rgb['grey'] = 'pewter'
     self.assertEqual(
         str(context.exception),
         "'FixedKeyMap' object does not support new item assignment")
示例#2
0
 def test_del_TypeError(self):
     rgb = FixedKeyMap(red='rouge', green='forest', blue='azul')
     with self.assertRaises(TypeError) as context:
         del rgb['red']
     self.assertEqual(
         str(context.exception),
         "'FixedKeyMap' object does not support item deletion")
示例#3
0
 def test_create(self):
     rgb = FixedKeyMap(red='rouge', green='forest', blue='azul')
     self.assertIsInstance(rgb, FixedKeyMap)
     self.assertIn('red', rgb)
     self.assertIn('green', rgb)
     self.assertIn('blue', rgb)
示例#4
0
 def test_iter(self):
     rgb = FixedKeyMap(red='rouge', green='forest', blue='azul')
     self.assertEqual(frozenset(iter(rgb)),
                      frozenset(['red', 'green', 'blue']))
示例#5
0
 def test_len(self):
     rgb = FixedKeyMap(red='rouge', green='forest', blue='azul')
     self.assertEqual(len(rgb), 3)
示例#6
0
 def test_setitem(self):
     rgb = FixedKeyMap(red='rouge', green='forest', blue='azul')
     rgb['blue'] = 'topaz'
     self.assertEqual(rgb['blue'], 'topaz')
示例#7
0
 def test_getitem_KeyError(self):
     rgb = FixedKeyMap(red='rouge', green='forest', blue='azul')
     with self.assertRaises(KeyError) as context:
         rgb['grey']
     self.assertEqual(str(context.exception), "'grey'")
示例#8
0
 def test_getitem(self):
     rgb = FixedKeyMap(red='rouge', green='forest', blue='azul')
     self.assertEqual(rgb['red'], 'rouge')