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() from decimal import Decimal,InvalidOperation source=read_csv('original-example');comparisons=[];held=[] for r in source: try: if r['단위']=='미확인':raise ValueError('unit_unknown') before=Decimal(r['직전 기록']);after=Decimal(r['현재 표시']);comparisons.append({'point':r['표시점'],'delta':str(after-before),'unit':r['단위']}) except (InvalidOperation,ValueError):held.append(r['표시점']) unit_rejected=[r['point'] for r in read_csv('mixed_unit') if r['before_unit']!=r['after_unit']] actual={'numeric_differences':comparisons,'not_compared':held,'mixed_unit_rejected':unit_rejected,'safety_verdict':'not_performed'} 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)