def test_incorrect_prefix_exception(self): with self.assertRaises(ValueError) as context: cacher.Cacher('/root') self.assertEqual('Incorrect cache prefix', str(context.exception)) with self.assertRaises(ValueError) as context: cacher.Cacher('..root') self.assertEqual('Incorrect cache prefix', str(context.exception)) with self.assertRaises(ValueError) as context: cacher.Cacher('root/') self.assertEqual('Incorrect cache prefix', str(context.exception)) with self.assertRaises(ValueError) as context: cacher.Cacher('../root') self.assertEqual('Incorrect cache prefix', str(context.exception))
def test_cache_int(self): self.c._directory_path = self.test_dir self.c.put('f', 1) c2 = cacher.Cacher(self.cache_prefix) c2._directory_path = self.test_dir val = c2.get('f') self.assertEqual(1, val)
def test_cache_set(self): self.c._directory_path = self.test_dir self.c.put('f', {1, 2, 3}) c2 = cacher.Cacher(self.cache_prefix) c2._directory_path = self.test_dir val = c2.get('f') self.assertEqual({1, 2, 3}, val)
def test_cache_tuple(self): self.c._directory_path = self.test_dir self.c.put('f', tuple([1, 2, 3])) c2 = cacher.Cacher(self.cache_prefix) c2._directory_path = self.test_dir val = c2.get('f') self.assertEqual(tuple([1, 2, 3]), val)
def test_cache_list(self): self.c._directory_path = self.test_dir self.c.put('f', [1, 2, 3]) c2 = cacher.Cacher(self.cache_prefix) c2._directory_path = self.test_dir val = c2.get('f') self.assertEqual([1, 2, 3], val)
def test_cache_dict(self): self.c._directory_path = self.test_dir self.c.put('f', {'test1': 1, 'test2': 2}) c2 = cacher.Cacher(self.cache_prefix) c2._directory_path = self.test_dir val = c2.get('f') self.assertEqual({'test1': 1, 'test2': 2}, val)
def test_has(self): self.c._directory_path = self.test_dir self.c.put('f', 'test') c2 = cacher.Cacher(self.cache_prefix) c2._directory_path = self.test_dir self.assertTrue(c2.has('f')) self.assertFalse(c2.has('f2'))
def test_delete(self): self.c._directory_path = self.test_dir self.c.put('f', 'test') self.assertEqual(1, len(os.listdir(self.test_dir))) c2 = cacher.Cacher(self.cache_prefix) c2._directory_path = self.test_dir c2.delete('f') self.assertEqual(0, len(os.listdir(self.test_dir)))
def setUp(self): self.c = cacher.Cacher(self.cache_prefix) self.test_dir = self.c._directory_path