arm-core/api/tests/test_domain_statement_lines.py
Andrey Epifancev 438752f035 feat(statements): справочник строк форм ББ/ОФР по редакциям (#80)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-09 11:56:27 +04:00

73 lines
3.0 KiB
Python

"""Справочник строк форм ББ/ОФР по редакциям (spec documents-api «Форма ББ/ОФР для экрана проверки»; design D-2)."""
from pathlib import Path
import pytest
from src.domain.statement_lines import TemplateLine, load_line_catalog
CATALOG = load_line_catalog()
@pytest.mark.parametrize(
("edition", "form", "count", "first", "last"),
[
("66n", "BALANCE", 37, "1110", "1700"),
("66n", "INCOME", 22, "2110", "2910"),
("fsbu4", "BALANCE", 34, "1110", "1700"),
("fsbu4", "INCOME", 23, "2110", "2910"),
],
)
def test_edition_composition(edition: str, form: str, count: int, first: str, last: str) -> None:
lines = CATALOG.lines(edition, form)
assert len(lines) == count
assert lines[0].code == first and lines[-1].code == last
assert len({line.code for line in lines}) == count
def test_names_fixed_from_templates() -> None:
names = {line.code: line.name for line in CATALOG.lines("fsbu4", "BALANCE")}
assert names["1110"] == "Нематериальные активы"
assert names["1210"] == "Запасы"
assert names["1310"] == "Уставный капитал (складочный капитал, уставный фонд, вклады товарищей)"
assert names["1410"] == names["1510"] == "Заемные средства"
assert names["1600"] == names["1700"] == "БАЛАНС"
old = {line.code: line.name for line in CATALOG.lines("66n", "BALANCE")}
assert old["1160"] == "Доходные вложения в материальные ценности"
assert "1105" not in old and "1215" not in old and "1215" in names
income = {line.code: line.name for line in CATALOG.lines("fsbu4", "INCOME")}
assert "2420" in income and "2460" not in income
assert all(
"\n" not in line.name for e in ("66n", "fsbu4") for f in ("BALANCE", "INCOME") for line in CATALOG.lines(e, f)
)
def test_no_edition_means_no_lines() -> None:
assert CATALOG.lines(None, "BALANCE") == ()
assert CATALOG.lines("unknown", "BALANCE") == ()
assert CATALOG.lines("66n", "OSV") == ()
def test_template_line_is_value_object() -> None:
assert TemplateLine("1700", "БАЛАНС") == TemplateLine("1700", "БАЛАНС")
@pytest.mark.parametrize(
("body", "message"),
[
("editions:\n - id: x\n forms:\n BALANCE: [{code: '11', name: a}]\n INCOME: []\n", "код"),
(
"editions:\n - id: x\n forms:\n BALANCE: [{code: '1110', name: a}, {code: '1110', name: b}]\n"
" INCOME: []\n",
"повтор",
),
("editions:\n - id: x\n forms:\n BALANCE: []\n", "INCOME"),
("editions: [\n", "statement_lines"),
],
)
def test_invalid_catalog_is_value_error(tmp_path: Path, body: str, message: str) -> None:
path = tmp_path / "statement_lines.yaml"
path.write_text(body, encoding="utf-8")
with pytest.raises(ValueError, match=message):
load_line_catalog(path)