Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BJKMLHdxMwSUeYcdkwqX4W
104 lines
4.8 KiB
Python
104 lines
4.8 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", 38, "1105", "1700"),
|
|
("fsbu4", "INCOME", 24, "2110", "2910"),
|
|
],
|
|
)
|
|
def test_edition_composition(edition: str, form: str, count: int, first: str, last: str) -> None:
|
|
lines = CATALOG.template_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.template_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.template_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.template_lines("fsbu4", "INCOME")}
|
|
assert "2420" in income and "2460" in income
|
|
assert all(
|
|
"\n" not in line.name
|
|
for e in ("66n", "fsbu4")
|
|
for f in ("BALANCE", "INCOME")
|
|
for line in CATALOG.template_lines(e, f)
|
|
)
|
|
|
|
|
|
def test_no_edition_means_no_lines() -> None:
|
|
assert CATALOG.template_lines(None, "BALANCE") == ()
|
|
assert CATALOG.template_lines("unknown", "BALANCE") == ()
|
|
assert CATALOG.template_lines("66n", "OSV") == ()
|
|
|
|
|
|
def test_catalog_two_names_one_template_line(tmp_path: Path) -> None:
|
|
lines = CATALOG.template_lines("fsbu4", "BALANCE")
|
|
assert [line.code for line in lines].count("1520") == 1
|
|
assert {line.code: line.name for line in lines}["1520"] == "Кредиторская задолженность"
|
|
assert CATALOG.names("BALANCE", "1520") == ("Кредиторская задолженность", "Обязательство по аренде")
|
|
assert CATALOG.reference_name("fsbu4", "BALANCE", "1520") == "Кредиторская задолженность"
|
|
assert CATALOG.reference_name("fsbu4", "BALANCE", "9999") is None
|
|
assert "1520" in CATALOG.edition_codes("fsbu4", "BALANCE") and "9999" not in CATALOG.edition_codes("66n", "INCOME")
|
|
path = tmp_path / "statement_lines.yaml"
|
|
path.write_text(
|
|
"editions:\n - id: x\n forms:\n BALANCE: [{code: '1110', name: a}, {code: '1110', name: b}]\n"
|
|
" INCOME: []\n",
|
|
encoding="utf-8",
|
|
)
|
|
own = load_line_catalog(path)
|
|
assert [line.name for line in own.template_lines("x", "BALANCE")] == ["a"]
|
|
assert own.names("BALANCE", "1110") == ("a", "b")
|
|
|
|
|
|
def test_catalog_fsbu4_additions() -> None:
|
|
assert "НДС, начисленный по отгрузке" in CATALOG.names("BALANCE", "1220")
|
|
assert "Налог при упрощенной системе налогообложения" in CATALOG.names("INCOME", "2410")
|
|
expected = {
|
|
"1105": "Гудвил",
|
|
"1130": "Нематериальные поисковые активы",
|
|
"1140": "Материальные поисковые активы",
|
|
"1530": "Доходы будущих периодов",
|
|
}
|
|
for code, name in expected.items():
|
|
assert CATALOG.reference_name("fsbu4", "BALANCE", code) == name
|
|
assert CATALOG.reference_name("fsbu4", "INCOME", "2460") == "Прочее"
|
|
|
|
|
|
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: []\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)
|