Exemple #1
0
def test_writeablecacheindex_setitem(tmp_path):
    index = WriteableCacheIndex(cache_dir=str(tmp_path))

    with pytest.raises(ValueError):
        index[0] = "file0"
    with pytest.raises(ValueError):
        index[0] = ("file0", 0)
    with pytest.raises(ValueError):
        index[0] = ("file0", 0, 0, 0)
Exemple #2
0
def test_writeablecacheindex_warning(monkeypatch, tmp_path):
    with pytest.warns(CacheIOWarning):
        with WriteableCacheIndex(cache_dir=str(tmp_path)) as idx:

            class RaiseError(type(idx.cache_dir)):
                def replace(self, *args, **kwargs):
                    raise CalledProcessError(-1, "move")

            monkeypatch.setattr(idx, "cache_dir", RaiseError(idx.cache_dir))
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
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"
Exemple #6
0
def test_writeablecacheindex_reinit(tmp_path):
    with WriteableCacheIndex(cache_dir=str(tmp_path)) as idx:
        subdir = idx.cache_dir / "subdir"
        subdir.mkdir()
        file1 = idx.cache_dir / "file1"
        file2 = subdir / "file2"
        with file1.open("w") as fh:
            fh.write("contents1")
        with file2.open("w") as fh:
            fh.write("contents2")

        assert subdir.exists() and file1.exists() and file2.exists()

        idx._reinit()
        assert not (subdir.exists() or file1.exists() or file2.exists())
Exemple #7
0
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"