Files
dvc/tests/unit/remote/test_index.py
T
Peter Rowlands (변기호) 3d84df930b objects: migrate remote push/pull to objects.transfer (#6308)
* objects: migrate remote status to objects.status

* data_cloud: use objects.status

* objects: migrate remote._process to objects.transfer

* data_cloud: use objects.transfer

* objects: handle memfs staging objects in transfer

* fetch/import: use unified transfer()

* update get_remote and transfer exception usage

* update tests

* objects.transfer: use src ODB verify rules after xfer

* odb: move index from remote into odb

* objects.transfer: skip src status check when possible

* update tests

* remove dvc.remote

* odb.index: migrate to diskcache

* objects: fix status/transfer optimization

* update index usage

* state: remove dead sqlite related code

* update cloud tests

* drop unnecessary remove in tests

* use abstract base class in odb index

* status: load trees from local cache instead of remote odb when possible

* handle status when dir cache is explicitly removed
2021-07-20 13:30:01 +03:00

53 lines
1.3 KiB
Python

import os
import pytest
from funcy import first
from dvc.objects.db.index import ObjectDBIndex
@pytest.fixture
def index(dvc):
index_ = ObjectDBIndex(dvc.tmp_dir, "foo")
yield index_
def test_init(dvc, index):
assert str(index.index_dir) == os.path.join(dvc.tmp_dir, "index", "foo")
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)
new_index = ObjectDBIndex(dvc.tmp_dir, "foo")
assert set(new_index.dir_hashes()) == expected_dir
assert set(new_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