예제 #1
0
 def test_equal_to_dict(self):
     d = PermaDict()
     self.assertNotEqual(d, {4: "the number four"})
     d[4] = "the number four"
     self.assertEqual(d, {4: "the number four"})
     self.assertNotEqual(d, {4: "the number five"})
     self.assertEqual(PermaDict({1: 2, 3: 4}), {1: 2, 3: 4})
예제 #2
0
 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})
예제 #3
0
 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})
예제 #4
0
 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})
예제 #5
0
 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})
예제 #6
0
 def test_force_set_method(self):
     d = PermaDict({1: 2, 3: 4})
     d.force_set(3, 6)
     d.force_set(5, 6)
     self.assertEqual(d, {1: 2, 3: 6, 5: 6})
예제 #7
0
 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})
예제 #8
0
 def test_error_when_changing_value(self):
     d = PermaDict()
     d[4] = "the number four"
     with self.assertRaises(KeyError):
         d[4] = "the number 4"
     self.assertEqual(d, {4: "the number four"})
예제 #9
0
 def test_can_pop_key(self):
     d = PermaDict()
     d[4] = "the number four"
     self.assertEqual(d, {4: "the number four"})
     self.assertEqual(d.pop(4), "the number four")
     self.assertEqual(d, {})
예제 #10
0
 def test_has_keys_values_and_items(self):
     d = PermaDict({'a': 'b', 'c': 'd'})
     self.assertEqual(set(d.keys()), {'a', 'c'})
     self.assertEqual(set(d.values()), {'b', 'd'})
     self.assertEqual(set(d.items()), {('a', 'b'), ('c', 'd')})
예제 #11
0
 def test_can_iterate(self):
     d = PermaDict({'a': 'b', 'c': 'd'})
     self.assertEqual(set(d), {'a', 'c'})
예제 #12
0
 def test_can_add_key(self):
     d = PermaDict()
     with self.assertRaises(KeyError):
         d[4]
     d[4] = "the number four"
     self.assertEqual(d[4], "the number four")
예제 #13
0
 def test_can_pop_key(self):
     d = PermaDict()
     self.assertNotEqual(d, {4: "the number four"})
     d[4] = "the number four"
     self.assertEqual(d, {4: "the number four"})
     self.assertNotEqual(d, {4: "the number five"})
예제 #14
0
 def test_has_keys_values_and_items(self):
     d = PermaDict({"a": "b", "c": "d"})
     self.assertEqual(set(d.keys()), {"a", "c"})
     self.assertEqual(set(d.values()), {"b", "d"})
     self.assertEqual(set(d.items()), {("a", "b"), ("c", "d")})
예제 #15
0
 def test_can_iterate(self):
     d = PermaDict({"a": "b", "c": "d"})
     self.assertEqual(set(d), {"a", "c"})
 def test_error_when_changing_value_after_force(self):
     d = PermaDict()
     d[4] = "the number four"
     d.update([(5, 6), (1, 8), (7, 8)], force=True)
     with self.assertRaises(KeyError):
         d[4] = "the number 4"