arm-tabular-parser/api/tests/fixtures/test_osv_property.py
Andrey Epifancev 7738221b5a docs: README/CLAUDE.md Среза 2a, tasks.md, спека-дельты
- README: парсер по модулям, статусы и коды, словари и добавление синонима, лимиты, golden-процесс, настройки PARSE_*
- CLAUDE.md: раздел «Добавлено в Срезе 2a» (модули, правила расширения, линтер, R-21); api/rules/README.md: ключи словарей
- openspec: tasks.md (5.1), design.md (D-1…D-7, O-7/O-8), спека-дельты osv-parsing (R-12…R-22) и tabular-recognition-service («Результат по контракту»)
- tests: check_snapshot в golden_helpers + тесты «нет снимка»/«регрессия»; locator в property-тесте; пример needs_check синхронизирован с docs

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vJkmBGKKqMoEMzvsXG3y2
2026-10-05 15:53:11 +04:00

55 lines
2.6 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.

"""Property-тест парсера на всех реальных ОСВ `../fixtures/osv/**` (design D-10; spec «Золотые снимки и
property-тесты», «Контрольные суммы определяют статус», «Пустая ОСВ», «Форматы, лимиты, время»).
Инварианты проверяются независимо от снимков: статус `done`, один документ, контрольные суммы §1.4 сошлись, корень =
счёт шапки, период распознан, разбор быстрее 5 с, результат валиден по контракту v1.1. Пустая ОСВ (R-13) определяется
свойством — в `rows` только TOTAL, — а не списком файлов.
"""
import time
from pathlib import Path
from typing import cast
import pytest
from result_contract import assert_valid_result
from src.contract import FileType, OsvDocument, ResultStatus
from src.parser import get_parser
MAX_PARSE_SECONDS = 5
@pytest.mark.fixtures
def test_real_osv_parses_done_with_invariants(osv_file: Path) -> None:
parser = get_parser()
data = osv_file.read_bytes()
started = time.monotonic()
outcome = parser.parse(data, cast(FileType, osv_file.suffix.lstrip(".").upper()))
seconds = time.monotonic() - started
assert outcome.error is None, outcome.error
assert outcome.status is ResultStatus.DONE, outcome.metrics
(document,) = outcome.documents
assert isinstance(document, OsvDocument)
assert document.locator == "sheet:Лист_1" # spec «Один лист — одна ОСВ»: имя листа берётся из файла, не ищется
checks = document.checks
assert checks is not None
assert checks.total_row_matches_root is True
assert checks.balance_identity_violations == []
assert checks.parent_sum_violations == []
assert document.header.period_quarter is not None
data_rows = [row for row in document.rows if row.group_type != "TOTAL"]
assert outcome.metrics is not None
assert outcome.metrics.rows == len(data_rows)
if data_rows:
assert outcome.metrics.rows > 0
assert document.header.account_code_raw == document.rows[0].account_code_raw
else:
# Пустая ОСВ (R-13): только «Итого»
assert [row.group_type for row in document.rows] == ["TOTAL"]
assert outcome.metrics.warnings is not None
assert "нет строк данных" in outcome.metrics.warnings
assert seconds < MAX_PARSE_SECONDS, f"{osv_file.name}: {seconds:.2f} с"
assert_valid_result(outcome)