Files
dvc/tests/unit/remote/test_index.py
T
Ruslan Kuprieiev f64018b75e dvc: separate data and objects
Initial simple separation to get the process of extracting dvc-objects
and dvc-data packages out of dvc.

dvc-objects is for:
 * defining base Object (aka HashFile) and ObjectDB
 * providing tools to work with those objects (check/transfer/etc)
 * etc

dvc-data is for:
 * defining higher level objects (e.g. Tree)
 * bulding objects from the workspace (aka staging)
 * projecting objects back into the workspace (aka checkout)
 * comparing Tree objects (aka diff)
 * defining misc object databases (e.g LocalObjectDB)
 * higher-level transfer (e.g. with Tree indexes)
 * etc

For example, the objects we use in run-cache are based on dvc-objects
and not on dvc-data, as they have absolutely nothing to do with data
management.

There are still some mixups in the code that will be addressed in the
followups.
2022-01-11 00:47:38 +02:00

48 lines
1.2 KiB
Python

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