def test_preload_error_not_found(): with tempfile.TemporaryDirectory() as d: cache = MultiprocessFileCache(10, dir=d, do_pickle=True) with pytest.raises(ValueError): cache.preload('preserved') cache.close()
def test_preload_error_not_found(): with tempfile.TemporaryDirectory() as d: cache = MultiprocessFileCache(10, dir=d, do_pickle=True) assert cache.preload('preserved') is False cache.close()
def test_preservation_interoperability(): with tempfile.TemporaryDirectory() as d: cache = FileCache(10, dir=d, do_pickle=True) for i in range(10): cache.put(i, str(i)) cache.preserve('preserved') for i in range(10): assert str(i) == cache.get(i) cache.close() cache2 = MultiprocessFileCache(10, dir=d, do_pickle=True) cache2.preload('preserved') for i in range(10): assert str(i) == cache2.get(i)
def test_preservation(): with tempfile.TemporaryDirectory() as d: cache = MultiprocessFileCache(10, dir=d, do_pickle=True) for i in range(10): cache.put(i, str(i)) cache.preserve('preserved') cache.close() # Imitating a new process, fresh load cache2 = MultiprocessFileCache(10, dir=d, do_pickle=True) cache2.preload('preserved') for i in range(10): assert str(i) == cache2.get(i) cache2.close() # No temporary cache file should remain, # and the preserved cache should be kept. assert os.listdir(d) == ['preserved.cached', 'preserved.cachei']