46 lines
1.7 KiB
Python
Raw Permalink 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 arm_statements import default_rules
from src.contract import ResultStatus
from src.normalizer import OcrNormalizer
from tests.golden_update import (
GOLDEN_DIR,
GOLDEN_VERSION,
REAL_FIXTURES,
full_payload,
golden_cases,
outcome_to_json,
real_set,
)
from tests.unit.test_contract import VALIDATORS
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")
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"))
outcome = OcrNormalizer(RULES, version=GOLDEN_VERSION).normalize(real_set(name))
if outcome.status is not ResultStatus.ERROR:
VALIDATORS["result"].validate(full_payload(outcome))
actual = outcome_to_json(outcome)
assert actual == expected, f"эталон {name} разошёлся: make golden-update и git diff в fixtures"