示例#1
0
 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))
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
    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)
示例#5
0
    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)
示例#6
0
    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)
示例#7
0
    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'))
示例#8
0
    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)))
示例#9
0
 def setUp(self):
     self.c = cacher.Cacher(self.cache_prefix)
     self.test_dir = self.c._directory_path