Files
troupe-standup/wizard-work/spark/verify_csv.py
T

33 lines
1.0 KiB
Python

#!/usr/bin/env python3
"""Verify CSV output is valid."""
import csv
import json
def _check(cond, msg):
"""A failure path `-O` cannot compile away (Q63: assert-only files exit 0 under -O)."""
if not cond:
raise RuntimeError(msg)
# Verify CSV is valid
with open('/root/.hermes/wizard-outputs/spark/output.csv', 'r') as f:
# subject: /root/.hermes/wizard-outputs/spark/output.csv -- grades the live tree outside the repo by design (not a repo fixture)
reader = csv.DictReader(f)
rows = list(reader)
_check(len(rows) == 2, f"Expected 2 rows, got {len(rows)}")
_check('name' in rows[0], "Missing 'name' column")
_check(rows[0]['name'] == 'Alice Smith', f"Wrong name: {rows[0]['name']}")
# Verify the JSON source was correctly processed
with open('/root/.hermes/wizard-outputs/spark/sample_data.json', 'r') as f:
source = json.load(f)
_check(len(source) == 2, "Source JSON should have 2 records")
print("PASS: CSV is valid with correct data structure")
print(f"Records: {len(rows)}")
print(f"Columns: {sorted(rows[0].keys())}")