Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BJKMLHdxMwSUeYcdkwqX4W
34 lines
1.6 KiB
Python
34 lines
1.6 KiB
Python
"""Golden нормализатора на реальных ответах ИС (D-8).
|
||
|
||
`../fixtures/ocr/<name>.json` → `../fixtures/ocr/expected_normalize/<name>.json`.
|
||
Обновление эталонов — `make golden-update` (не автоматически)."""
|
||
|
||
import json
|
||
from pathlib import Path
|
||
|
||
import pytest
|
||
|
||
from arm_statements import default_rules
|
||
from src.normalizer import OcrNormalizer
|
||
from tests.golden_update import GOLDEN_DIR, GOLDEN_VERSION, REAL_FIXTURES, golden_cases, outcome_to_json, real_set
|
||
|
||
API_DIR = Path(__file__).resolve().parents[3]
|
||
RULES = default_rules()
|
||
pytestmark = pytest.mark.fixtures
|
||
|
||
|
||
def _cases() -> list[str]:
|
||
return golden_cases() if REAL_FIXTURES.is_dir() else []
|
||
|
||
|
||
@pytest.mark.parametrize("name", _cases() or ["<нет fixtures>"])
|
||
def test_matches_golden(name: str) -> None:
|
||
if not REAL_FIXTURES.is_dir():
|
||
pytest.skip("fixtures недоступен: положите репозиторий fixtures рядом с workspace")
|
||
pytest.skip("golden v2 пересобирается в задаче 6 (эталоны в fixtures пока прежнего формата)")
|
||
expected_path = GOLDEN_DIR / f"{name}.json"
|
||
assert expected_path.is_file(), f"нет эталона {expected_path}: выполните make golden-update и проверьте diff"
|
||
expected = json.loads(expected_path.read_text(encoding="utf-8"))
|
||
actual = outcome_to_json(OcrNormalizer(RULES, version=GOLDEN_VERSION).normalize(real_set(name)))
|
||
assert actual == expected, f"эталон {name} разошёлся: make golden-update и git diff в fixtures"
|