Andrey Epifancev 07d57cbd07 test(statements): манифест реальных форм, property-тест, golden форм, покрытие словарей форм
Манифест statements_manifest.yaml по 18 реальным файлам statements-xlsx (сверен
прогоном парсера, R-13, OQ-137), property-тест по манифесту, снимки форм в
golden_helpers/golden_update/test_golden, словари форм в покрытии, синтетика
st06 для вариантов заголовков. Мёртвые записи словаря удалены (name_caption,
метки okved и okud_label) либо покрыты st06.

Refs #14

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: cedd7915-2efe-41e5-988c-a9117033598b
2026-10-06 20:50:25 +04:00

73 lines
3.1 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-снимки разбора (design D-10): результат парсера для каждого файла `fixtures/osv/**`, синтетики и файлов
`fixtures/osv-dkb/**` до `GOLDEN_MAX_BYTES` равен снимку в `fixtures/golden/expected_osv_parse/` (зеркало дерева
`osv/`, пакет ДКБ — в подкаталоге `osv-dkb/`), без volatile-полей.
Снимок — регрессия, а не оракул (оракулы — ручная сверка «Итого» и property-тест). Обновление — `make golden-update`,
отдельным коммитом в репозиторий fixtures с просмотром diff.
"""
from pathlib import Path
import pytest
from golden_helpers import check_snapshot, golden_path
from src.parser import Parser, get_parser
pytestmark = pytest.mark.fixtures
@pytest.fixture(scope="module")
def parser() -> Parser:
return get_parser()
def test_osv_file_matches_golden_snapshot(fixtures_dir: Path, osv_file: Path, parser: Parser) -> None:
check_snapshot(fixtures_dir, osv_file, parser)
def test_dkb_file_matches_golden_snapshot(fixtures_dir: Path, dkb_golden_file: Path, parser: Parser) -> None:
"""Пакет ДКБ: снимки только у файлов не больше `GOLDEN_MAX_BYTES` (большие — property-тесты `test_osv_dkb.py`)."""
check_snapshot(fixtures_dir, dkb_golden_file, parser)
def test_synthetic_file_matches_golden_snapshot(fixtures_dir: Path, synthetic_file: Path, parser: Parser) -> None:
check_snapshot(fixtures_dir, synthetic_file, parser)
def test_statement_file_matches_golden_snapshot(fixtures_dir: Path, statement_file: Path, parser: Parser) -> None:
"""Реальные формы `statements-xlsx/**`: снимки в `golden/expected_statement_parse/`."""
check_snapshot(fixtures_dir, statement_file, parser)
def test_statement_synthetic_matches_golden_snapshot(
fixtures_dir: Path, statement_synthetic_file: Path, parser: Parser
) -> None:
check_snapshot(fixtures_dir, statement_synthetic_file, parser)
def test_every_snapshot_has_a_source_file(fixtures_dir: Path) -> None:
"""Лишний снимок (файл удалён или переименован) — ошибка: `make golden-update` его удаляет."""
from fixtures_helpers import ( # noqa: PLC0415 - один тест
osv_dkb_golden_files,
osv_fixture_files,
statement_files,
statement_synthetic_files,
synthetic_files,
)
sources = [
*osv_fixture_files(fixtures_dir),
*osv_dkb_golden_files(fixtures_dir),
*synthetic_files(fixtures_dir),
*statement_files(fixtures_dir),
*statement_synthetic_files(fixtures_dir),
]
expected = {golden_path(fixtures_dir, file) for file in sources}
present: set[Path] = set()
for name in ("expected_osv_parse", "expected_statement_parse"):
directory = fixtures_dir / "golden" / name
if directory.is_dir():
present |= set(directory.rglob("*.json"))
assert sorted(path.relative_to(fixtures_dir).as_posix() for path in present - expected) == []