30 خطوط
1.5 KiB
Python
30 خطوط
1.5 KiB
Python
"""Validate the regression harness; these synthetic images are not Altium references."""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
from PIL import Image, ImageDraw
|
|
|
|
ROOT=Path(__file__).resolve().parents[2]
|
|
|
|
def test_visual_harness_detects_pixel_changes(tmp_path,ascii_schematic):
|
|
source=tmp_path/'unit.SchDoc';source.write_bytes(ascii_schematic)
|
|
first=tmp_path/'initial'
|
|
command=[sys.executable,str(ROOT/'scripts/validate.py'),str(source)]
|
|
run=subprocess.run(command+['--width','400','--output',str(first)],capture_output=True,text=True)
|
|
assert run.returncode==0,run.stderr
|
|
reference=first/'rendered.png'
|
|
equal=tmp_path/'equal'
|
|
run=subprocess.run(command+['--reference',str(reference),'--output',str(equal),'--max-mae','0','--max-changed-fraction','0'],capture_output=True,text=True)
|
|
assert run.returncode==0,run.stderr
|
|
report=json.loads((equal/'report.json').read_text())
|
|
assert report['mae']==0 and report['regression_passed'] and not report['fidelity_verified']
|
|
image=Image.open(reference).convert('RGB');ImageDraw.Draw(image).rectangle((0,0,80,80),fill='black')
|
|
altered=tmp_path/'changed.png';image.save(altered)
|
|
changed=tmp_path/'different'
|
|
run=subprocess.run(command+['--reference',str(altered),'--output',str(changed)],capture_output=True,text=True)
|
|
assert run.returncode==1,run.stderr
|
|
assert not json.loads((changed/'report.json').read_text())['regression_passed']
|
|
assert (changed/'difference.png').exists() and (changed/'overlay.png').exists()
|