def test_get_item(self): proxy = aggregates.TwoWayDict({12: "12", "bar": [1, 2, 3]}) self.assertEqual("12", proxy[12]) self.assertEqual([1, 2, 3], proxy["bar"]) with self.assertRaises(KeyError): _ = proxy["lol"]
def test_iter(self): proxy = aggregates.TwoWayDict({12: "12", "bar": [1, 2, 3]}) i = iter(proxy) li = list(i) self.assertIn(12, li) self.assertIn("bar", li) self.assertNotIn("potato", li)
def test_del_item(self): proxy = aggregates.TwoWayDict({12: "12", "bar": [1, 2, 3]}) del proxy[12] with self.assertRaises(KeyError): _ = proxy[12] del proxy["bar"] with self.assertRaises(KeyError): _ = proxy["bar"]
def test_set_item(self): proxy = aggregates.TwoWayDict({12: "12", "bar": [1, 2, 3]}) proxy["foo"] = 13 proxy["bar"] = 14 self.assertEqual("12", proxy[12]) self.assertEqual(13, proxy["foo"]) self.assertEqual(14, proxy["bar"])
def test_cache_gets_cached_and_then_uncached(self): twd = aggregates.TwoWayDict({12: "12", "bar": [1, 2, 3]}) cached = reversed(twd) cached2 = reversed(twd) self.assertIs(cached, cached2) # Uncache twd["xyz"] = ... cached3 = reversed(twd) self.assertIsNot(cached, cached3)
def test_reversal(self): twd = aggregates.TwoWayDict({12: "12", "bar": [1, 2, 3]}) dwt = reversed(twd) self.assertDictEqual({"12": 12, 1: "bar", 2: "bar", 3: "bar"}, dwt)
def test_keys(self): proxy = aggregates.TwoWayDict({12: "12", "bar": [1, 2, 3]}) self.assertIn(12, proxy.keys()) self.assertIn("bar", proxy.keys()) self.assertNotIn("potato", proxy.keys())
def test_init_kwargs(self): proxy = aggregates.TwoWayDict(foo="12", bar=[1, 2, 3]) test = {"bar": [1, 2, 3], "foo": "12"} self.assertCountEqual(proxy, test) self.assertDictEqual(proxy, test)
def test_init_dict(self): proxy = aggregates.TwoWayDict({12: "12", "bar": [1, 2, 3]}) test = {12: "12", "bar": [1, 2, 3]} self.assertCountEqual(proxy, test) self.assertDictEqual(proxy, test)