def test_load_increases_lifetime(self): with TempDir() as cache_dir, TempDir() as d: build_cache = BuildCache(Directory(path=cache_dir), lifetime=5) build_cache.store_artifacts(d, 'foo') previous_use_time = build_cache.manifest()['foo'].use_time self.assertNotEqual(previous_use_time, 0) sleep(3) build_cache.load_artifacts('foo', os.path.join(d, 'temp')) self.assertGreater(build_cache.manifest()['foo'].use_time, previous_use_time)
def test_store_load_artifacts(self): with TempDir() as cache_dir: build_cache = BuildCache(Directory(path=cache_dir)) with TempDir() as build_dir: for name in ['f1', 'f2', 'dir1/f3']: path = os.path.join(build_dir, name) try: os.makedirs(os.path.dirname(path)) except: pass with open(path, 'w') as f: f.write(name) build_cache.store_artifacts(build_dir, 'foo') with TempDir() as temp: build_cache.load_artifacts('foo', os.path.join(temp, 'build_dir')) for name in ['f1', 'f2', 'dir1/f3']: path = os.path.join(temp, 'build_dir', name) with open(path, 'r') as f: self.assertEqual(f.read(), name)
def test_load_raises_with_invalid_key(self): with TempDir() as cache_dir: build_cache = BuildCache(Directory(path=cache_dir)) with TempDir() as d: self.assertRaises(KeyNotFound, lambda: build_cache.load_artifacts('foo', os.path.join(d, 'dest')))