class TestDictCache(BaseTest): """ DictCache test class """ def setUp(self): self.c = DictCache() self.c.set(*self.ex_str) self.c.set(*self.ex_int) self.c.set(*self.ex_cpx) def test_dict_cache_set(self): self.assertEqual(self.c._dict[self.ex_str[0]][0], self.ex_str[1]) self.assertEqual(self.c._dict[self.ex_int[0]][0], self.ex_int[1]) self.assertEqual(self.c._dict[self.ex_cpx[0]][0], self.ex_cpx[1]) def test_dict_cache_get(self): self.check_complex(self.c.get(self.ex_cpx[0])) def test_dict_cache_invalidate(self): self.c.invalidate(self.ex_cpx[0]) self.assertIsNone(self.c.get(self.ex_cpx[0])) def test_dict_cache_expiry(self): self.check_complex(self.c.get(self.ex_cpx[0])) self.c._dict[self.ex_cpx[0]] = (self.ex_cpx[1], time.time() - 1) self.assertIsNone(self.c.get(self.ex_cpx[0])) self.assertNotIn(self.ex_cpx[0], self.c._dict)
class TestDictCache(BaseTest): """ DictCache test class """ def setUp(self): self.c = DictCache() self.c.set(*self.ex_str) self.c.set(*self.ex_int) self.c.set(*self.ex_cpx) def tearDown(self): self.c.invalidate(self.ex_str[0]) self.c.invalidate(self.ex_int[0]) self.c.invalidate(self.ex_cpx[0]) def test_dict_cache_set(self): self.assertEqual(self.c._dict[self.ex_str[0]], self.ex_str[1]) self.assertEqual(self.c._dict[self.ex_int[0]], self.ex_int[1]) self.assertEqual(self.c._dict[self.ex_cpx[0]], self.ex_cpx[1]) def test_dict_cache_get(self): self.check_complex(self.c.get(self.ex_cpx[0])) def test_dict_cache_invalidate(self): self.c.invalidate(self.ex_cpx[0]) self.assertIsNone(self.c.get(self.ex_cpx[0])) def test_dict_cache_clear(self): self.assertEqual(self.c._dict[self.ex_str[0]], self.ex_str[1]) self.assertEqual(len(self.c._dict), 3) self.c.clear() self.assertEqual(len(self.c._dict), 0)