Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/tests/conftest.py
Show First 20 Lines • Show All 233 Lines • ▼ Show 20 Lines | |||||
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]{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): | ||||
if m: | if m: | ||||
d = m.groupdict() | d = m.groupdict() | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |