Files
dvc/tests/unit/remote/test_index.py
T
Peter Rowlands (변기호) 0fb9870de6 remote: rename "checksum" -> "hash" (#4051)
* remote: s/get_checksum/get_hash/

* remote/tree: s/get_file_checksum/get_file_hash/

* remote: s/get_dir_checksum/get_dir_hash/

* remote: s/checksum_to_path/hash_to_path/

* remote: s/path_to_checksum/path_to_hash/

* remote: cleanup remaining checksum references

* remote.index: s/checksum/hash/

* note: does not rename "checksum" field in the index DB schema
2020-06-16 12:16:51 +03:00

58 lines
1.3 KiB
Python

import os
import pytest
from funcy import first
from dvc.remote.index import RemoteIndex
@pytest.fixture(scope="function")
def index(dvc):
index = RemoteIndex(dvc, "foo")
index.load()
yield index
index.dump()
os.unlink(index.path)
def test_init(dvc, index):
assert str(index.path) == os.path.join(dvc.index_dir, "foo.idx")
def test_is_dir_hash(dvc, index):
assert index.is_dir_hash("foo.dir")
assert not index.is_dir_hash("foo")
def test_roundtrip(dvc, index):
expected_dir = {"1234.dir"}
expected_file = {"5678"}
index.update(expected_dir, expected_file)
index.dump()
index.load()
assert set(index.dir_hashes()) == expected_dir
assert set(index.hashes()) == expected_dir | expected_file
def test_clear(dvc, index):
index.update(
["1234.dir"], ["5678"],
)
index.clear()
assert first(index.hashes()) is None
def test_update(dvc, index):
expected_dir = {"1234.dir"}
expected_file = {"5678"}
index.update(expected_dir, expected_file)
assert set(index.dir_hashes()) == expected_dir
assert set(index.hashes()) == expected_dir | expected_file
def test_intersection(dvc, index):
hashes = (str(i) for i in range(2000))
expected = {str(i) for i in range(1000)}
index.update([], hashes)
assert set(index.intersection(expected)) == expected