def test_file_store_load(self): with TempDir() as cache_dir, TempDir() as d: cache = Directory(path=cache_dir) foo_file = os.path.join(d, 'foo_file') bar_file = os.path.join(d, 'bar_file') with open(foo_file, 'w') as f: f.write('foo') with open(bar_file, 'w') as f: f.write('bar') self.assertFalse(os.listdir(cache_dir)) cache.store_file(foo_file, 'foo_key') cache.store_file(bar_file, 'bar_key') self.assertTrue(os.listdir(cache_dir)) os.remove(foo_file) os.remove(bar_file) cache.load_file('foo_key', foo_file) cache.load_file('bar_key', bar_file) with open(foo_file, 'r') as f: self.assertEqual(f.read(), 'foo') with open(bar_file, 'r') as f: self.assertEqual(f.read(), 'bar')
def test_load_raise_error_on_invalid_key(self): with TempDir() as cache_dir, TempDir() as d: cache = Directory(path=cache_dir) destination = os.path.join(d, 'build_directory') self.assertRaises(KeyNotFound, lambda: cache.load_file('key', destination))