Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/tests/test_isochrone_graph.py
Show All 10 Lines | |||||
import yaml | import yaml | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.provenance.archive import ArchiveInterface | from swh.provenance.archive import ArchiveInterface | ||||
from swh.provenance.graph import IsochroneNode, build_isochrone_graph | from swh.provenance.graph import IsochroneNode, build_isochrone_graph | ||||
from swh.provenance.interface import ProvenanceInterface | from swh.provenance.interface import ProvenanceInterface | ||||
from swh.provenance.model import DirectoryEntry, RevisionEntry | from swh.provenance.model import DirectoryEntry, RevisionEntry | ||||
from swh.provenance.revision import revision_add | from swh.provenance.revision import revision_add | ||||
from swh.provenance.tests.conftest import fill_storage, get_datafile, load_repo_data | from swh.provenance.tests.conftest import ( | ||||
from swh.provenance.tests.test_provenance_db import ts2dt | fill_storage, | ||||
from swh.storage.postgresql.storage import Storage | get_datafile, | ||||
load_repo_data, | |||||
ts2dt, | |||||
) | |||||
def isochrone_graph_from_dict(d: Dict[str, Any], depth: int = 0) -> IsochroneNode: | def isochrone_graph_from_dict(d: Dict[str, Any], depth: int = 0) -> IsochroneNode: | ||||
"""Takes a dictionary representing a tree of IsochroneNode objects, and | """Takes a dictionary representing a tree of IsochroneNode objects, and | ||||
recursively builds the corresponding graph.""" | recursively builds the corresponding graph.""" | ||||
d = deepcopy(d) | d = deepcopy(d) | ||||
d["entry"]["id"] = hash_to_bytes(d["entry"]["id"]) | d["entry"]["id"] = hash_to_bytes(d["entry"]["id"]) | ||||
Show All 28 Lines | ( | ||||
("cmdbts2", True, 2), | ("cmdbts2", True, 2), | ||||
("cmdbts2", False, 2), | ("cmdbts2", False, 2), | ||||
("out-of-order", True, 1), | ("out-of-order", True, 1), | ||||
), | ), | ||||
) | ) | ||||
@pytest.mark.parametrize("batch", (True, False)) | @pytest.mark.parametrize("batch", (True, False)) | ||||
def test_isochrone_graph( | def test_isochrone_graph( | ||||
provenance: ProvenanceInterface, | provenance: ProvenanceInterface, | ||||
swh_storage: Storage, | |||||
archive: ArchiveInterface, | archive: ArchiveInterface, | ||||
repo: str, | repo: str, | ||||
lower: bool, | lower: bool, | ||||
mindepth: int, | mindepth: int, | ||||
batch: bool, | batch: bool, | ||||
) -> None: | ) -> None: | ||||
# read data/README.md for more details on how these datasets are generated | # read data/README.md for more details on how these datasets are generated | ||||
data = load_repo_data(repo) | data = load_repo_data(repo) | ||||
fill_storage(swh_storage, data) | fill_storage(archive.storage, data) | ||||
revisions = {rev["id"]: rev for rev in data["revision"]} | revisions = {rev["id"]: rev for rev in data["revision"]} | ||||
filename = f"graphs_{repo}_{'lower' if lower else 'upper'}_{mindepth}.yaml" | filename = f"graphs_{repo}_{'lower' if lower else 'upper'}_{mindepth}.yaml" | ||||
with open(get_datafile(filename)) as file: | with open(get_datafile(filename)) as file: | ||||
for expected in yaml.full_load(file): | for expected in yaml.full_load(file): | ||||
print("# Processing revision", expected["rev"]) | print("# Processing revision", expected["rev"]) | ||||
revision = revisions[hash_to_bytes(expected["rev"])] | revision = revisions[hash_to_bytes(expected["rev"])] | ||||
Show All 29 Lines |