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() p=HERE/'input/import.csv';raw=p.read_bytes();table=read_csv('import');naive=[line.split(',') for line in raw.decode('utf-8-sig').splitlines()];proper_cols=[len(r) for r in table];numeric=[str(int(r['location_id'])) for r in table] actual={'has_utf8_bom':raw.startswith(b'\xef\xbb\xbf'),'row_count':len(table),'ids_as_text':[r['location_id'] for r in table],'date_texts':[r['date_text'] for r in table],'first_label':table[0]['label'],'naive_first_row_columns':len(naive[1]),'proper_column_counts':proper_cols,'numeric_conversion_ids':numeric,'ids_damaged_by_numeric':sum(a['location_id']!=b for a,b in zip(table,numeric)),'count_total':sum(int(r['count']) for r in table)} 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)