Andrey Epifancev 2973cc7966 Документирование warnings адаптера, тест листа-продолжения, обезличенная фамилия (M-2, M-3, M-4)
M-2: README и docstring normalize_candidate — при отсутствии документа
candidate.warnings хост обрабатывает сам. M-3: тесты сопоставления
по дате (переставленные даты) и по порядку (дубль даты).
M-4: «Косарев» заменён на «Иванов» в тестах и docstring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BJKMLHdxMwSUeYcdkwqX4W
2026-10-18 14:29:10 +04:00

75 lines
3.5 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.

import pytest
from arm_statements.codes import is_code_cell, majority_section, parse_code, sheet_joins
from arm_statements.loader import CodeSection, Rules
from arm_statements.model import DocumentType
from arm_statements.text import fix_lookalikes, is_disguised_digit, normalize_caption, normalize_label
@pytest.mark.parametrize(
("raw", "code", "fixed"),
[
("1220 ,", "1220", False),
("| 140", "1140", True),
("I1О0", "1100", True),
("1110.0", "1110", False),
("12301", "12301", False),
("3450", "3450", False),
("2024", None, False),
("1050", None, False),
("7450", None, False),
("ИЧ,250", None, False),
("изо :", None, False),
("НИ", None, False),
("1500\n1700", None, False),
("2", None, False),
],
)
def test_parse_code(rules: Rules, raw: str, code: str | None, fixed: bool) -> None:
assert parse_code(raw, rules) == (code, fixed)
def test_multiline_code_cell(rules: Rules) -> None:
assert is_code_cell("1500\n1700", rules)
assert not is_code_cell("44 30\nI |", rules)
def test_lookalikes_only_near_digit(rules: Rules) -> None:
assert fix_lookalikes("2ОО5", rules.lookalikes) == "2005"
assert fix_lookalikes("2|0|2|4|", rules.lookalikes).split() == ["2", "0", "2", "4"]
assert fix_lookalikes("Основные средства", rules.lookalikes) == "Основные средства"
assert fix_lookalikes("З", rules.lookalikes) == "З"
assert fix_lookalikes("З", rules.lookalikes, anywhere=True) == "3"
def test_disguised_digit(rules: Rules) -> None:
assert is_disguised_digit("I", rules.lookalikes) and is_disguised_digit("| О", rules.lookalikes)
assert not is_disguised_digit("Иванов", rules.lookalikes)
assert not is_disguised_digit("(расшифровка подписи)", rules.lookalikes)
def test_caption_normalization() -> None:
assert normalize_caption("Код строки") == "код строки"
assert normalize_caption("Изменение, %") == "изменение %"
assert normalize_caption("Наименование\nпоказателя") == "наименование показателя"
def test_label_normalization_keeps_punctuation(rules: Rules) -> None:
assert normalize_label("Местонахождение (адрес)") == "местонахождение (адрес)"
assert normalize_label("по ОКОПФ / ОКФС") == "по окопф / окфс"
assert normalize_label("Форма 0710001 с.2") == "форма 0710001 с.2"
assert normalize_label("Отчёт о финансовых\nрезультатах") == "отчет о финансовых результатах"
assert normalize_label("за­дол­жен—ность") == "задолжен ность"
assert normalize_label(None) == ""
for key, patterns in rules.headers.labels.items():
assert patterns, key
assert any(p.search(normalize_label("Местонахождение (адрес)")) for p in rules.headers.labels["address"])
assert any(p.search(normalize_label("по ОКОПФ / ОКФС")) for p in rules.headers.labels["okopf_okfs"])
def test_majority_section_and_join(rules: Rules) -> None:
assert majority_section(["1110", "1150", "2110"], rules) is CodeSection.BALANCE
assert sheet_joins(DocumentType.INCOME, ["2400"], 1, 3, rules)
assert not sheet_joins(DocumentType.BALANCE, ["1110", "1150", "1100"], 4, 3, rules)
assert not sheet_joins(DocumentType.BALANCE, ["2110"], 3, 3, rules)