arm-tabular-parser/api/tests/statement_helpers.py
Andrey Epifancev 6cd2ea8a7a test(statements): failed_relations в манифесте, статус документа по критерию парсера, строгая шапка (T14.I2)
Refs #14

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

43 lines
1.5 KiB
Python

"""Манифест ожиданий по реальным формам `fixtures/statements-xlsx/**` (`statements_manifest.yaml`)."""
from functools import cache
from pathlib import Path
from typing import Literal
import yaml
from fixtures_helpers import STATEMENTS_DIR
from pydantic import BaseModel, ConfigDict
MANIFEST_PATH = Path(__file__).resolve().parent / "statements_manifest.yaml"
class DocumentExpectation(BaseModel):
model_config = ConfigDict(extra="forbid", frozen=True)
type: Literal["BALANCE", "INCOME", "DISCLOSURE"]
status: Literal["done", "needs_check"]
complete: bool
reason: str | None = None
sheets: int | None = None
failed_relations: list[str] | None = None # None — не проверяется; список — точное множество relations_failed
class Expectation(BaseModel):
model_config = ConfigDict(extra="forbid", frozen=True)
organization: str | None = None
inn: str | None = None
inn_optional_for: tuple[str, ...] = ()
documents: list[DocumentExpectation]
@cache
def load_manifest() -> dict[str, Expectation]:
"""Ожидания по файлам; ключ — путь относительно `statements-xlsx/` (posix)."""
raw = yaml.safe_load(MANIFEST_PATH.read_text(encoding="utf-8"))
return {key: Expectation.model_validate(value) for key, value in raw["files"].items()}
def relative_key(fixtures_dir: Path, path: Path) -> str:
return path.relative_to(fixtures_dir / STATEMENTS_DIR).as_posix()