From be623cd697eeffe78b5c42e74bd5f868146535a9 Mon Sep 17 00:00:00 2001 From: spark Date: Sat, 24 Oct 2026 18:26:48 +0000 Subject: [PATCH] q63: ledger/verify_arxiv_csv -- asserts to _check(), so -O cannot print rows_ok=20 over a 3-row CSV --- wizard-work/ledger/verify_arxiv_csv.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/wizard-work/ledger/verify_arxiv_csv.py b/wizard-work/ledger/verify_arxiv_csv.py index 619d22f..cc898af 100644 --- a/wizard-work/ledger/verify_arxiv_csv.py +++ b/wizard-work/ledger/verify_arxiv_csv.py @@ -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])