File size: 1,842 Bytes
77fc6d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Read-only validation for the corrected GlycoDA-Bench dataset."""

from __future__ import annotations

import argparse
import hashlib
from pathlib import Path

from generate_benchmark import SCRIPT_ROOT, validate_dataset


def _verify_checksums(root: Path) -> tuple[int, list[str]]:
    checksum_path = root / "checksums.sha256"
    if not checksum_path.is_file():
        return 0, ["checksums.sha256 is missing"]
    checked = 0
    errors: list[str] = []
    for line in checksum_path.read_text(encoding="utf-8").splitlines():
        if not line.strip():
            continue
        expected, relative = line.split("  ", 1)
        path = root / relative
        if not path.is_file():
            errors.append(f"missing: {relative}")
            continue
        digest = hashlib.sha256()
        with path.open("rb") as handle:
            for chunk in iter(lambda: handle.read(1024 * 1024), b""):
                digest.update(chunk)
        actual = digest.hexdigest()
        checked += 1
        if actual != expected:
            errors.append(f"checksum mismatch: {relative}")
    return checked, errors


def main() -> None:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--root", default=str(SCRIPT_ROOT / "dataset"))
    parser.add_argument("--expected-cases", type=int, default=648)
    parser.add_argument("--verify-checksums", action="store_true")
    args = parser.parse_args()

    root = Path(args.root).resolve()
    report = validate_dataset(root, expected_cases=args.expected_cases)
    if args.verify_checksums:
        checked, errors = _verify_checksums(root)
        if errors:
            raise AssertionError("Checksum validation failed:\n" + "\n".join(errors[:50]))
        report["checksums_verified"] = checked
    print(report)


if __name__ == "__main__":
    main()