"""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) == []