def test_writeablecacheindex_writes(tmpdir): index = WriteableCacheIndex(cache_dir=str(tmpdir)) with index: index[0] = ("file0", 0, 0) index[1] = ("file1", 0, 0) del index[1] # Verify with readonly cacheindex index = CacheIndex(cache_dir=str(tmpdir)) with index: assert index[0] == ("file0", 0, 0) assert 1 not in index
def test_writeablecacheindex_removes(tmpdir): index = WriteableCacheIndex(cache_dir=str(tmpdir)) with index: index[0] = ("file0", 0, 0) index[1] = ("file1", 0, 0) index.remove_file_entry("file0") index.remove_file_entry(os.path.join(str(tmpdir), "file1")) # Verify with readonly cacheindex index = CacheIndex(cache_dir=str(tmpdir)) with index: assert 0 not in index, "Fails on relative paths" assert 1 not in index, "Fails on absolute paths"
def test_cacheindex_cannot_write(tmpdir): index = WriteableCacheIndex(cache_dir=str(tmpdir)) with index: index[0] = ("file0", 0, 0) mtime = os.stat(index.index_path).st_mtime index = CacheIndex(cache_dir=str(tmpdir)) with index: with pytest.raises(TypeError): index[0] = ("file", 0, 0) with pytest.raises(TypeError): del index[0] assert index[0] == ("file0", 0, 0) assert os.stat(index.index_path).st_mtime == mtime