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() source=read_csv('original-example');checks=[] for r in source: calculated=int(r['시작 재고'])+int(r['입고'])-int(r['출고']);counted=int(r['실사 수량']);checks.append({'item':r['품목'],'unit':r['기록 단위'],'calculated':calculated,'written_expected':int(r['예상 잔량']),'variance':counted-calculated}) units={r['unit'] for r in checks} actual={'balances':checks,'formula_mismatches':[r['item'] for r in checks if r['calculated']!=r['written_expected']],'count_variances':[r['item'] for r in checks if r['variance']!=0],'mixed_unit_total_allowed':len(units)==1} 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)