2 # Allow direct execution
8 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
11 from test
.helper
import FakeYDL
13 from yt_dlp
.cache
import Cache
17 return not bool(os
.listdir(d
))
21 if not os
.path
.exists(d
):
25 class TestCache(unittest
.TestCase
):
27 TEST_DIR
= os
.path
.dirname(os
.path
.abspath(__file__
))
28 TESTDATA_DIR
= os
.path
.join(TEST_DIR
, 'testdata')
30 self
.test_dir
= os
.path
.join(TESTDATA_DIR
, 'cache_test')
34 if os
.path
.exists(self
.test_dir
):
35 shutil
.rmtree(self
.test_dir
)
39 'cachedir': self
.test_dir
,
42 obj
= {'x': 1, 'y': ['รค', '\\a', True]}
43 self
.assertEqual(c
.load('test_cache', 'k.'), None)
44 c
.store('test_cache', 'k.', obj
)
45 self
.assertEqual(c
.load('test_cache', 'k2'), None)
46 self
.assertFalse(_is_empty(self
.test_dir
))
47 self
.assertEqual(c
.load('test_cache', 'k.'), obj
)
48 self
.assertEqual(c
.load('test_cache', 'y'), None)
49 self
.assertEqual(c
.load('test_cache2', 'k.'), None)
51 self
.assertFalse(os
.path
.exists(self
.test_dir
))
52 self
.assertEqual(c
.load('test_cache', 'k.'), None)
55 if __name__
== '__main__':