Beispiel #1
0
    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"]
Beispiel #2
0
 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)
Beispiel #3
0
 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"]
Beispiel #4
0
    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"])
Beispiel #5
0
    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)
Beispiel #6
0
 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)
Beispiel #7
0
 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())
Beispiel #8
0
 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)
Beispiel #9
0
 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)