2026-10-18 13:13:31 +04:00

38 lines
1.8 KiB
Python

import json
from datetime import date
from decimal import Decimal as D
from arm_statements.model import Cell, DocumentType, Evidence, FormCandidate, HeaderCells, Source
from arm_statements.serialize import candidate_from_dict, to_jsonable
from arm_statements.tests.builders import excel, ocr
def test_candidate_roundtrip_through_json() -> None:
cand = FormCandidate(
source=Source.EXCEL,
locator="sheet:Баланс",
type_hint=DocumentType.BALANCE,
evidence=Evidence(okud=Cell("0710001", None, 100.0, "Баланс!F3"), title=None),
header=HeaderCells(report_date=Cell("30.09.2025", date(2025, 9, 30), 100.0, "Баланс!C5")),
rows=((Cell("106 311", D("106311"), 100.0, "Баланс!D27"), None, Cell("да", True, 100.0, "Баланс!F27")),),
)
data = json.loads(json.dumps(to_jsonable(cand), ensure_ascii=False))
assert data["rows"][0][0]["value"] == {"decimal": "106311"}
assert data["header"]["report_date"]["value"] == {"date": "2025-09-30"}
assert candidate_from_dict(data) == cand
def test_excel_builder_refs_follow_excel_quoting() -> None:
cand = excel([("Баланс", [["", "", "", "1110"]]), ("Бухгалтерский баланс. Лист 1", [["", "", "1150"]])])
assert cand.rows[0][3] is not None and cand.rows[0][3].ref == "Баланс!D1"
assert cand.rows[1][2] is not None and cand.rows[1][2].ref == "'Бухгалтерский баланс. Лист 1'!C1"
assert cand.segment_breaks == (1,)
assert cand.locator == "sheet:Баланс,Бухгалтерский баланс. Лист 1"
def test_ocr_builder_cells() -> None:
cand = ocr([["Выручка", ("[190 :", 25.0), None]])
cell = cand.rows[0][1]
assert cell == Cell("[190 :", None, 25.0, "row:0")
assert cand.rows[0][2] is None and cand.source is Source.OCR