arm-core/api/tests/test_domain_quality_attribution.py
Andrey Epifancev 5603dd1898 feat(#190): атрибуция правки сервис/наш разбор (§14.2)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-11-05 18:37:57 +04:00

63 lines
3.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

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.

"""Атрибуция правки «сервис / наш разбор» (§14.2)."""
from src.domain.quality_attribution import (
attribute_added_row,
attribute_code_fix,
attribute_header_fix,
attribute_value_fix,
)
def test_attribute_value_fix_ours_when_raw_matches_after_lookalikes():
# сырой текст "1OOO.00" (O вместо 0), подтверждено 1000.00 — цифры совпадают после замены двойников → "ours"
assert attribute_value_fix("1000.00", "1OOO.00") == "ours"
def test_attribute_value_fix_service_when_raw_differs():
assert attribute_value_fix("1000.00", "999.00") == "service"
def test_attribute_value_fix_ignores_sign_difference():
# знак — наша зона ответственности (скобки/минус разобраны неверно), цифры сошлись → "ours"
assert attribute_value_fix("-1000.00", "(1000.00)") == "ours"
def test_attribute_code_fix_ours_when_code_in_raw_text():
# код найден среди кодов склейки "1250\n1260" (две строки сырого line_code_text) → наш разбор, не сервис
# (имя теста в брифе и его ассерт противоречили таблице §14.2 — исправлено по дизайну, см. отчёт задачи)
assert attribute_code_fix("1250", "1250\n1260") == "ours"
def test_attribute_code_fix_service_when_code_not_in_raw_text():
assert attribute_code_fix("1250", "9999\n9998") == "service"
def test_attribute_added_row_excel_always_ours():
assert attribute_added_row("1250", raw_line_codes=["1250"], is_excel=True) == "ours"
def test_attribute_added_row_excel_always_ours_even_if_code_absent():
# для Excel правило не смотрит на raw_line_codes вовсе — ошибка всегда наша (наш tabular-parser)
assert attribute_added_row("1250", raw_line_codes=[], is_excel=True) == "ours"
def test_attribute_added_row_pdf_ours_when_code_in_raw_tokens():
assert attribute_added_row("1250", raw_line_codes=["1100", "1250", "1600"], is_excel=False) == "ours"
def test_attribute_added_row_pdf_service_when_code_absent():
assert attribute_added_row("1250", raw_line_codes=["1100", "1600"], is_excel=False) == "service"
def test_attribute_header_fix_ours_when_confirmed_in_source_text():
assert attribute_header_fix("Рога и копыта", "ООО «Рога и копыта»") == "ours"
def test_attribute_header_fix_service_when_confirmed_not_in_source_text():
assert attribute_header_fix("Рога и копыта", "ООО «Другая компания»") == "service"
def test_attribute_header_fix_ours_after_lookalikes_for_inn():
# ИНН — цифровое поле шапки: двойник буквы рядом с цифрой (О вместо 0) исправляется §11.3 перед сравнением
assert attribute_header_fix("7000112233", "7OOO112233") == "ours"