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');r=read_csv('visit')[0] def minute(t):h,m=map(int,t.split(':'));return h*60+m unreturned=int(r['tools_out'])-int(r['tools_back']);pending=[] if unreturned:pending.append('tool_return') if r['extra_scope_decided']!='yes':pending.append('scope_reply') actual={'source_stages':[r['단계'] for r in source],'visit_minutes':minute(r['exit'])-minute(r['entry']),'unreturned_tools':unreturned,'pending_items':pending,'handover_closed':not pending} 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)