Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/tests/conftest.py
Show First 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | def CMDBTS_data(): | ||||
# o - [1610644122] R0013 4c5551b4969eb2160824494d40b8e1f6187fc01e | # o - [1610644122] R0013 4c5551b4969eb2160824494d40b8e1f6187fc01e | ||||
# |- Paris/Berlin/Purple/f 94ba40161084e8b80943accd9d24e1f9dd47189b | # |- Paris/Berlin/Purple/f 94ba40161084e8b80943accd9d24e1f9dd47189b | ||||
# |- Paris/Berlin/Purple/g 94ba40161084e8b80943accd9d24e1f9dd47189b | # |- Paris/Berlin/Purple/g 94ba40161084e8b80943accd9d24e1f9dd47189b | ||||
# |- Paris/Munich/Purple/f 94ba40161084e8b80943accd9d24e1f9dd47189b | # |- Paris/Munich/Purple/f 94ba40161084e8b80943accd9d24e1f9dd47189b | ||||
# |- Paris/Munich/Purple/g 94ba40161084e8b80943accd9d24e1f9dd47189b | # |- Paris/Munich/Purple/g 94ba40161084e8b80943accd9d24e1f9dd47189b | ||||
# |- Paris/Purple/f 94ba40161084e8b80943accd9d24e1f9dd47189b | # |- Paris/Purple/f 94ba40161084e8b80943accd9d24e1f9dd47189b | ||||
# |- Paris/Purple/g 94ba40161084e8b80943accd9d24e1f9dd47189b | # |- Paris/Purple/g 94ba40161084e8b80943accd9d24e1f9dd47189b | ||||
# `- Paris/k * cb79b39935c9392fa5193d9f84a6c35dc9c22c75 | # `- Paris/k * cb79b39935c9392fa5193d9f84a6c35dc9c22c75 | ||||
return load_repo_data("CMDBTS") | |||||
def load_repo_data(repo): | |||||
data = {"revision": [], "directory": [], "content": []} | data = {"revision": [], "directory": [], "content": []} | ||||
with open(get_datafile("CMDBTS.msgpack"), "rb") as fobj: | with open(get_datafile(f"{repo}.msgpack"), "rb") as fobj: | ||||
for etype, value in msgpack_loads(fobj.read()): | for etype, value in msgpack_loads(fobj.read()): | ||||
data[etype].append(value) | data[etype].append(value) | ||||
return data | return data | ||||
def filter_dict(d, keys): | def filter_dict(d, keys): | ||||
return {k: v for (k, v) in d.items() if k in keys} | return {k: v for (k, v) in d.items() if k in keys} | ||||
@pytest.fixture | @pytest.fixture | ||||
def storage_and_CMDBTS(swh_storage, CMDBTS_data): | def storage_and_CMDBTS(swh_storage, CMDBTS_data): | ||||
swh_storage.content_add_metadata( | fill_storage(swh_storage, CMDBTS_data) | ||||
Content.from_dict(content) for content in CMDBTS_data["content"] | return swh_storage, CMDBTS_data | ||||
def fill_storage(storage, data): | |||||
storage.content_add_metadata( | |||||
Content.from_dict(content) for content in data["content"] | |||||
) | ) | ||||
swh_storage.directory_add( | storage.directory_add( | ||||
[ | [ | ||||
Directory( | Directory( | ||||
entries=tuple( | entries=tuple( | ||||
[ | [ | ||||
DirectoryEntry.from_dict( | DirectoryEntry.from_dict( | ||||
filter_dict(entry, ("name", "type", "target", "perms")) | filter_dict(entry, ("name", "type", "target", "perms")) | ||||
) | ) | ||||
for entry in dir["entries"] | for entry in dir["entries"] | ||||
] | ] | ||||
) | ) | ||||
) | ) | ||||
for dir in CMDBTS_data["directory"] | for dir in data["directory"] | ||||
] | ] | ||||
) | ) | ||||
swh_storage.revision_add( | storage.revision_add(Revision.from_dict(revision) for revision in data["revision"]) | ||||
Revision.from_dict(revision) for revision in CMDBTS_data["revision"] | |||||
) | |||||
return swh_storage, CMDBTS_data | |||||
class SynthRelation(TypedDict): | class SynthRelation(TypedDict): | ||||
path: str | path: str | ||||
src: bytes | src: bytes | ||||
dst: bytes | dst: bytes | ||||
rel_ts: float | rel_ts: float | ||||
Show All 34 Lines | with open(get_datafile(filename), "r") as fobj: | ||||
yield from _parse_synthetic_file(fobj) | yield from _parse_synthetic_file(fobj) | ||||
def _parse_synthetic_file(fobj: Iterable[str]) -> Iterator[SynthRevision]: | def _parse_synthetic_file(fobj: Iterable[str]) -> Iterator[SynthRevision]: | ||||
"""Read a 'synthetic' file and generate a dict representation of the synthetic | """Read a 'synthetic' file and generate a dict representation of the synthetic | ||||
revision for each revision listed in the synthetic file. | revision for each revision listed in the synthetic file. | ||||
""" | """ | ||||
regs = [ | regs = [ | ||||
"(?P<revname>R[0-9]{4})?", | "(?P<revname>R[0-9]{2,4})?", | ||||
"(?P<reltype>[^| ]*)", | "(?P<reltype>[^| ]*)", | ||||
"([+] )?(?P<path>[^| +]*?)[/]?", | "([+] )?(?P<path>[^| +]*?)[/]?", | ||||
"(?P<type>[RDC]) (?P<sha1>[0-9a-z]{40})", | "(?P<type>[RDC]) (?P<sha1>[0-9a-z]{40})", | ||||
"(?P<ts>-?[0-9]+(.[0-9]+)?)", | "(?P<ts>-?[0-9]+(.[0-9]+)?)", | ||||
] | ] | ||||
regex = re.compile("^ *" + r" *[|] *".join(regs) + r" *$") | regex = re.compile("^ *" + r" *[|] *".join(regs) + r" *$") | ||||
current_rev: List[dict] = [] | current_rev: List[dict] = [] | ||||
for m in (regex.match(line) for line in fobj): | for m in (regex.match(line) for line in fobj): | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |