q63: ledger/verify_arxiv_csv -- asserts to _check(), so -O cannot print rows_ok=20 over a 3-row CSV

This commit is contained in:
spark committed 2026-10-24 18:26:48 +00:00
1 parent 80a2e3687f
commit be623cd697
1 file changed
+13 -6
+13 -6
View File
@@ -9,6 +9,13 @@ import csv
import re
import sys
def _check(cond, msg="check failed"):
"""Explicit failure path -- survives `python3 -O`, where `assert` is compiled away."""
if not cond:
raise SystemExit(f"FAIL: {msg}")
EXPECTED_HEADER = ["arxiv_id", "title", "authors", "published", "abstract"]
ID_RE = re.compile(r"^[0-9]{4}\.[0-9]{4,5}$")
DATE_RE = re.compile(r"^[0-9]{4}-[0-9]{2}-[0-9]{2}$")
@@ -17,14 +24,14 @@ def main():
path = sys.argv[1] if len(sys.argv) > 1 else "/root/troupe-standup/wizard-work/ledger/arxiv-lg-recent.csv"
with open(path, newline="", encoding="utf-8") as f:
rows = list(csv.DictReader(f))
assert rows, "no data rows"
assert list(rows[0].keys()) == EXPECTED_HEADER, f"bad header {list(rows[0].keys())}"
assert len(rows) == 20, f"expected 20 rows, got {len(rows)}"
_check(rows, "no data rows")
_check(list(rows[0].keys()) == EXPECTED_HEADER, f"bad header {list(rows[0].keys())}")
_check(len(rows) == 20, f"expected 20 rows, got {len(rows)}")
for i, r in enumerate(rows, start=1):
assert ID_RE.match(r["arxiv_id"].strip()), f"row {i} bad arxiv_id {r['arxiv_id']!r}"
assert DATE_RE.match(r["published"].strip()), f"row {i} bad date {r['published']!r}"
_check(ID_RE.match(r["arxiv_id"].strip()), f"row {i} bad arxiv_id {r['arxiv_id']!r}")
_check(DATE_RE.match(r["published"].strip()), f"row {i} bad date {r['published']!r}")
for col in ("title", "authors", "abstract"):
assert (r[col] or "").strip(), f"row {i} empty {col}"
_check((r[col] or "").strip(), f"row {i} empty {col}")
dates = sorted({r["published"] for r in rows})
print(f"rows_ok=20 header_ok=1 ids_ok=1 dates_ok=1 date_range={dates[0]}..{dates[-1]}")
print("sample=" + rows[0]["arxiv_id"] + " " + rows[0]["title"][:50])