Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/tests/test_revision_content_layer.py
Show All 9 Lines | |||||
from typing_extensions import TypedDict | from typing_extensions import TypedDict | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.model import Sha1Git | from swh.model.model import Sha1Git | ||||
from swh.provenance.archive import ArchiveInterface | from swh.provenance.archive import ArchiveInterface | ||||
from swh.provenance.interface import EntityType, ProvenanceInterface, RelationType | from swh.provenance.interface import EntityType, ProvenanceInterface, RelationType | ||||
from swh.provenance.model import RevisionEntry | from swh.provenance.model import 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, | |||||
) | |||||
class SynthRelation(TypedDict): | class SynthRelation(TypedDict): | ||||
prefix: Optional[str] | prefix: Optional[str] | ||||
path: str | path: str | ||||
src: Sha1Git | src: Sha1Git | ||||
dst: Sha1Git | dst: Sha1Git | ||||
rel_ts: float | rel_ts: float | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | ( | ||||
("cmdbts2", False, 1), | ("cmdbts2", False, 1), | ||||
("cmdbts2", True, 2), | ("cmdbts2", True, 2), | ||||
("cmdbts2", False, 2), | ("cmdbts2", False, 2), | ||||
("out-of-order", True, 1), | ("out-of-order", True, 1), | ||||
), | ), | ||||
) | ) | ||||
def test_revision_content_result( | def test_revision_content_result( | ||||
provenance: ProvenanceInterface, | provenance: ProvenanceInterface, | ||||
swh_storage: Storage, | |||||
archive: ArchiveInterface, | archive: ArchiveInterface, | ||||
repo: str, | repo: str, | ||||
lower: bool, | lower: bool, | ||||
mindepth: int, | mindepth: int, | ||||
) -> 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) | ||||
syntheticfile = get_datafile( | syntheticfile = get_datafile( | ||||
f"synthetic_{repo}_{'lower' if lower else 'upper'}_{mindepth}.txt" | f"synthetic_{repo}_{'lower' if lower else 'upper'}_{mindepth}.txt" | ||||
) | ) | ||||
revisions = {rev["id"]: rev for rev in data["revision"]} | revisions = {rev["id"]: rev for rev in data["revision"]} | ||||
rows: Dict[str, Set[Any]] = { | rows: Dict[str, Set[Any]] = { | ||||
"content": set(), | "content": set(), | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 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_provenance_heuristics_content_find_all( | def test_provenance_heuristics_content_find_all( | ||||
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 = [ | revisions = [ | ||||
RevisionEntry( | RevisionEntry( | ||||
id=revision["id"], | id=revision["id"], | ||||
date=ts2dt(revision["date"]), | date=ts2dt(revision["date"]), | ||||
root=revision["directory"], | root=revision["directory"], | ||||
) | ) | ||||
for revision in data["revision"] | for revision in data["revision"] | ||||
] | ] | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 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_provenance_heuristics_content_find_first( | def test_provenance_heuristics_content_find_first( | ||||
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 = [ | revisions = [ | ||||
RevisionEntry( | RevisionEntry( | ||||
id=revision["id"], | id=revision["id"], | ||||
date=ts2dt(revision["date"]), | date=ts2dt(revision["date"]), | ||||
root=revision["directory"], | root=revision["directory"], | ||||
) | ) | ||||
for revision in data["revision"] | for revision in data["revision"] | ||||
] | ] | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |