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() import xml.etree.ElementTree as ET original=read_csv('original-example');checks=[];hashes=[] for r in original: image=ET.parse(HERE/'images'/f"{r['사진 번호']}.svg");root=image.getroot();vx,vy,vw,vh=map(float,root.attrib['viewBox'].split());stain=next(n for n in root.iter() if n.attrib.get('id')=='stain');x,y,w,h=(float(stain.attrib[k]) for k in ['x','y','width','height']);area=max(0,min(x+w,vx+vw)-max(x,vx))*max(0,min(y+h,vy+vh)-max(y,vy));checks.append({'photo':r['사진 번호'],'role':r['역할'],'stain_bbox_area':int(w*h),'visible_bbox_area':int(area),'whole_boundary_visible':area==w*h});hashes.append(hashlib.sha256(ET.tostring(stain)).hexdigest()) actual={'views':checks,'same_stain_geometry':len(set(hashes))==1,'needs_wider_context':[r['photo'] for r in checks if not r['whole_boundary_visible']]} 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)