D7UX, langues et accessibilité
Audit accessibilité automatisé
Un script pa11y/WCAG2AA avec sortie JSON ; il ne remplace pas une revue humaine.
import subprocess,os,json,time,argparse,shutil
from pathlib import Path
root=Path(__file__).resolve().parents[1]
parser=argparse.ArgumentParser(description="Read-only automated WCAG2AA audit; not a human screen-reader review")
parser.add_argument('--origin', default='http://127.0.0.1:8894')
parser.add_argument('--output', required=True, type=Path)
parser.add_argument('--routes', nargs='+', help='Optional route subset; defaults to all configured views')
args=parser.parse_args()
out=args.output
out.mkdir(parents=True, exist_ok=True)
routes=['home','article','graph','problems','solutions','decision-chain','governance','research-agenda','dossiers','events','images','coverage','claims','sources','methodology','visualizations','dossier/mieux-decider-fenetres-decision','dossier/fraser-nooksack-decisions-2021','dossier/fraser-nooksack-decisions-2025','dossier/capacites-prevision-canada']
if args.routes:
unknown=set(args.routes)-set(routes)
if unknown: parser.error('Unknown route subset')
routes=args.routes
results=[]
env=dict(os.environ,CHROMIUM_BIN=os.environ.get('CHROMIUM_BIN') or shutil.which('chromium') or 'chromium')
for lang in ['fr','en','both']:
for route in routes:
url=f'{args.origin.rstrip("/")}/?lang={lang}#{route}'
p=subprocess.run(['pa11y','--config','pa11y.config.cjs','--reporter','json',url],cwd=root,env=env,capture_output=True,text=True,timeout=90)
try: issues=json.loads(p.stdout)
except ValueError:issues=None
record=dict(language=lang,route=route,url=url,exit_code=p.returncode,issues=issues,stderr=p.stderr.strip())
results.append(record)
(out/'results.json').write_text(json.dumps(dict(standard='WCAG2AA',runner='htmlcs',scope='Automated checks; not a human screen-reader review',results=results),ensure_ascii=False,indent=2)+'\n')
print(lang,route,'OK' if p.returncode==0 else f'FAIL {len(issues) if issues is not None else p.stderr[:100]}',flush=True)
print('Complete',len(results),'views;',sum(r['exit_code']!=0 for r in results),'failures',flush=True)
raise SystemExit(1 if any(r['exit_code'] != 0 for r in results) else 0)