57 lines
3.0 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from datetime import date
from arm_statements.header import continuation_type, is_continuation, parse_header, type_hint
from arm_statements.loader import Rules
from arm_statements.model import DocumentType, HeaderCells
from tests.builders import hdr
def test_inn_digits_only_without_lookalikes(rules: Rules) -> None:
head = parse_header(hdr(inn="|7700000000|"), rules)
assert head.inn.value == "7700000000"
dirty = parse_header(hdr(inn=("3|1 21 2|", 80.0)), rules)
assert dirty.inn.value is None
assert (dirty.inn.text, dirty.inn.confidence) == ("3|1 21 2|", 80.0)
def test_units_by_text_then_okei(rules: Rules) -> None:
assert parse_header(hdr(units="в тыс. рублей"), rules).units.value == "тыс. руб."
by_okei = parse_header(hdr(okei="384"), rules)
assert (by_okei.units.value, by_okei.okei.value, by_okei.units.text) == ("тыс. руб.", "384", None)
assert parse_header(hdr(units="руб."), rules).units.value == "руб."
def test_report_date_and_codes(rules: Rules) -> None:
head = parse_header(hdr(report_date="30.09.2О25", okud="Форма по ОКУД 0710001", okopf="12267"), rules)
assert head.report_date.value == date(2025, 9, 30)
assert (head.okud.value, head.okopf.value) == ("0710001", "12267")
def test_type_hint_okud_wins(rules: Rules) -> None:
assert type_hint("0710002", "Бухгалтерский баланс", rules) is DocumentType.INCOME
assert type_hint("Форма по ОКУД 0710001", None, rules) is DocumentType.BALANCE
assert type_hint("0710005", None, rules) is DocumentType.DISCLOSURE
assert type_hint(None, "Пояснения к бухгалтерскому балансу", rules) is DocumentType.DISCLOSURE
assert type_hint(None, "Отчет о прибылях и убытках", rules) is DocumentType.INCOME
assert type_hint(None, "Бухгалтерская отчетность", rules) is None
def test_continuation_marker(rules: Rules) -> None:
assert continuation_type("Форма 0710002 с.2", rules) is DocumentType.INCOME
assert continuation_type("Бухгалтерский баланс", rules) is None
assert is_continuation("Форма 0710000 с. 3", rules) and continuation_type("Форма 0710000 с. 3", rules) is None
assert not is_continuation("Бухгалтерский баланс", rules) and not is_continuation(None, rules)
def test_type_hint_uses_label_normalization(rules: Rules) -> None:
assert type_hint(None, "ОТЧЁТ О ФИНАНСОВЫХ\nРЕЗУЛЬТАТАХ", rules) is DocumentType.INCOME
def test_absent_cells_and_empty_values(rules: Rules) -> None:
head = parse_header(HeaderCells(), rules)
assert (head.inn.text, head.inn.confidence, head.inn.value) == (None, None, None)
assert head.report_date.value is None and head.needs_review_fields == ()
blank = parse_header(hdr(okpo=" ", organization_name=" ООО «Пример» "), rules)
assert blank.okpo.value is None
assert blank.organization_name.value == "ООО «Пример»"