2026-10-07 00:47:42 +04:00

33 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""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 src.normalizer import OcrNormalizer
from src.normalizer.rules import load_rules
from tests.golden_update import GOLDEN_DIR, REAL_FIXTURES, golden_cases, outcome_to_json, real_set
API_DIR = Path(__file__).resolve().parents[3]
RULES = load_rules(API_DIR / "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")
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).normalize(real_set(name)))
assert actual == expected, f"эталон {name} разошёлся: make golden-update и git diff в fixtures"