from pathlib import Path import csv,json,hashlib,sys,platform,datetime HERE=Path(__file__).resolve().parent def read_csv(name): with (HERE/'input'/f'{name}.csv').open(encoding='utf-8-sig',newline='') as f:return list(csv.DictReader(f)) def hashfile(path):return hashlib.sha256(path.read_bytes()).hexdigest() summary=read_csv('original-example');register=read_csv('source_register');by_id={r['원본번호']:r for r in summary};missing=[r['request'] for r in register if r['request'] not in by_id];mismatch=[r['request'] for r in register if r['request'] in by_id and r['status']!=by_id[r['request']]['이달 상태']];decisions=[r['원본번호'] for r in summary if r['결정 필요']!='없음'];counts={} for r in summary:counts[r['이달 상태']]=counts.get(r['이달 상태'],0)+1 actual={'source_requests':len(register),'summary_rows':len(summary),'status_counts':counts,'unreported_requests':missing,'status_mismatches':mismatch,'decision_needed':decisions} import datetime as _lab_clock expected=json.loads((HERE/'expected/report.json').read_text()) checks=[{'field':k,'pass':actual.get(k)==v,'actual':actual.get(k),'expected':v} for k,v in expected.items()] passed=all(x['pass'] for x in checks) and set(actual)==set(expected) report={'lab_id':HERE.name,'synthetic_fixture':True,'environment':{'python':platform.python_version(),'platform':platform.system(),'processor':'Python standard library; PNG rendering only uses ImageMagick during artifact preparation'},'run_utc':_lab_clock.datetime.now(_lab_clock.timezone.utc).isoformat(),'status':'PASS' if passed else 'FAIL','assertion_count':len(checks),'actual':actual,'assertions':checks,'limits':'Synthetic test data only; not a real building inspection, legal/safety verdict, or Excel application execution.'} (HERE/'results.json').write_text(json.dumps(report,ensure_ascii=False,indent=2)) print(json.dumps(report,ensure_ascii=False,indent=2)) if not passed:raise SystemExit(1)