def test_force_argument_to_update(self):
     d = PermaDict({1: 2, 3: 4}, silent=True)
     d.update([(5, 6), (1, 8), (7, 8)], force=True)
     self.assertEqual(d, {1: 8, 3: 4, 5: 6, 7: 8})
     e = PermaDict()
     e.update(a=1, b=2, force=True)
     self.assertEqual(e, {'a': 1, 'b': 2})
Exemplo n.º 2
0
 def test_raise_exception(self):
     locations = PermaDict([('Cos', "Houston"), ('Bla', 1)])
     with pytest.raises(KeyError) as e_info:
         locations["Cos"] = 33
     assert e_info.value.args[0] == "'Cos' already in dictionary."
     with pytest.raises(KeyError) as update_error:
         locations.update(Cos=55)
     assert update_error.value.args[0] == "'Cos' already in dictionary."
 def test_silent_flag_to_initializer(self):
     d = PermaDict({1: 2, 3: 4}, silent=True)
     d.update([(5, 6), (1, 8), (7, 8)])
     self.assertEqual(d, {1: 2, 3: 4, 5: 6, 7: 8})
     d[3] = 6
     d[9] = 10
     self.assertEqual(d, {1: 2, 3: 4, 5: 6, 7: 8, 9: 10})
     e = PermaDict(silent=True, not_silent=False, super_silent=True)
     self.assertEqual(e, {'not_silent': False, 'super_silent': True})
 def test_can_update_with_new_keys(self):
     d = PermaDict()
     d.update({'a': 1})
     self.assertEqual(d, {'a': 1})
     d.update([('b', 2)])
     self.assertEqual(d, {'a': 1, 'b': 2})
     d.update(c=3)
     self.assertEqual(d, {'a': 1, 'b': 2, 'c': 3})
 def test_error_when_updating_value(self):
     d = PermaDict({1: 2, 3: 4})
     with self.assertRaises(KeyError):
         d.update([(5, 6), (1, 8), (7, 8)])
     self.assertEqual(d, {1: 2, 3: 4, 5: 6})
Exemplo n.º 6
0
 def test_forced_update(self):
     locations = PermaDict({'David': "Boston"})
     locations.update([('David', 'Amsterdam'), ('Asheesh', 'SF')],
                      force=True)
     assert dict(locations) == {'David': 'Amsterdam', 'Asheesh': 'SF'}