Spaces:
Running
Running
| from __future__ import annotations | |
| import importlib.util | |
| import json | |
| import sys | |
| from pathlib import Path | |
| import cv2 | |
| ROOT = Path(__file__).resolve().parents[1] | |
| spec = importlib.util.spec_from_file_location('dse_omr_v31_app', ROOT / 'app.py') | |
| if spec is None or spec.loader is None: | |
| raise RuntimeError('Cannot load app.py') | |
| app = importlib.util.module_from_spec(spec) | |
| sys.modules['dse_omr_v31_app'] = app | |
| spec.loader.exec_module(app) | |
| config = json.loads((ROOT / 'marker_config.json').read_text(encoding='utf-8')) | |
| tests = [ | |
| ('strict_clean', ROOT / 'samples/sample_phone_perspective.jpg', 'strict_pass'), | |
| ('shadow_rescue', ROOT / 'samples/sample_phone_shadow_rescue.jpg', 'rescue_pass'), | |
| ('missing_tl', ROOT / 'samples/sample_phone_missing_tl.jpg', 'reject'), | |
| ] | |
| failed = False | |
| for name, path, expected in tests: | |
| image = cv2.imread(str(path)) | |
| if image is None: | |
| print(f'{name}: FAIL cannot read {path}') | |
| failed = True | |
| continue | |
| try: | |
| _, _, rescue_used = app._detect_large_corner_markers(image, config) | |
| actual = 'rescue_pass' if rescue_used else 'strict_pass' | |
| except app.MarkerDetectionError: | |
| actual = 'reject' | |
| ok = actual == expected | |
| print(f'{name}: {"PASS" if ok else "FAIL"} expected={expected} actual={actual}') | |
| failed = failed or not ok | |
| if failed: | |
| raise SystemExit(1) | |
| print('V3.1 FUNCTIONAL MARKER TESTS PASSED') | |