4 from __future__ import unicode_literals
8 # Allow direct execution
12 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
15 from test.helper import FakeYDL
16 from youtube_dl.cache import Cache
20 return not bool(os.listdir(d))
24 if not os.path.exists(d):
28 class TestCache(unittest.TestCase):
30 TEST_DIR = os.path.dirname(os.path.abspath(__file__))
31 TESTDATA_DIR = os.path.join(TEST_DIR, 'testdata')
33 self.test_dir = os.path.join(TESTDATA_DIR, 'cache_test')
37 if os.path.exists(self.test_dir):
38 shutil.rmtree(self.test_dir)
42 'cachedir': self.test_dir,
45 obj = {'x': 1, 'y': ['รค', '\\a', True]}
46 self.assertEqual(c.load('test_cache', 'k.'), None)
47 c.store('test_cache', 'k.', obj)
48 self.assertEqual(c.load('test_cache', 'k2'), None)
49 self.assertFalse(_is_empty(self.test_dir))
50 self.assertEqual(c.load('test_cache', 'k.'), obj)
51 self.assertEqual(c.load('test_cache', 'y'), None)
52 self.assertEqual(c.load('test_cache2', 'k.'), None)
54 self.assertFalse(os.path.exists(self.test_dir))
55 self.assertEqual(c.load('test_cache', 'k.'), None)
58 if __name__ == '__main__':