"""Pruebas reproducibles; ejecutar desde cualquier carpeta con Python 3.11+ y dependencias.""" import subprocess,sys,tempfile,json from pathlib import Path ROOT=Path(__file__).resolve().parents[1]/'proyectos' CASES={ 'ciberseguridad':('auditoria.py',['demo']), 'iot':('sensor.py',['--samples','40','--output','sensor.csv']), 'cientifico':('pendulo.py',['--output','pendulo.csv']), 'vision-artificial':('vision.py',['demo']), 'geoespacial':('mapa.py',[str(ROOT/'geoespacial/puntos.csv'),'--output','ruta.geojson']), 'redes':('diagnostico.py',[]), 'documentos':('documentos.py',['demo']), 'ia-local':('modelos.py',[])} def main(): reports={} with tempfile.TemporaryDirectory() as d: for slug,(script,args) in CASES.items(): try: p=subprocess.run([sys.executable,str(ROOT/slug/script),*args],cwd=d,capture_output=True,text=True,timeout=120) if p.returncode:raise RuntimeError(p.stderr.strip()) result=json.loads(p.stdout) if slug=='ciberseguridad':assert result['original_valid'] and result['tampered_rejected'] and result['certificate_demo_valid_now'] and result['sha256_abc']=='ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' if slug=='iot':assert result['samples']==40 and (Path(d)/'sensor.csv').read_text().count('\n')==41 if slug=='vision-artificial':assert result['components']==2 and 'APPINITDEV' in result['ocr'] and result['faces_in_synthetic_shapes']==0 if slug=='redes':assert result['status']==200 and result['headers']['cache-control']=='no-store' if slug=='documentos':assert result['merged_pages']==2 and 'APPINITDEV' in result['text'] and 'APPINITDEV' in result['ocr'] and result['png_bytes']>0 if slug=='cientifico':assert abs(result['period_measured_s']-result['period_small_angle_s'])<.01 and result['max_relative_energy_drift']<.001 if slug=='geoespacial':assert abs(result['distance_km']-222.39016)<.001 if slug=='ia-local':assert result['train']+result['test']==1797 and all(m['accuracy']>.85 and sum(map(sum,m['confusion_matrix']))==result['test'] for m in result['models'].values()) reports[slug]={'status':'PASS','result':result} except Exception as e:reports[slug]={'status':'FAIL','error':str(e)} print(slug,reports[slug]['status'],flush=True) target=Path(__file__).with_name('proyectos')/'resultados.json';target.parent.mkdir(exist_ok=True);target.write_text(json.dumps(reports,ensure_ascii=False,indent=2),encoding='utf-8') return int(any(r['status']!='PASS' for r in reports.values())) if __name__=='__main__':raise SystemExit(main())