fix(normalizer): код ошибки набора от первого ошибочного json только если успешных нет (#46)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BJKMLHdxMwSUeYcdkwqX4W
This commit is contained in:
parent
4acb0b83b8
commit
3b9e1f6e19
@ -61,19 +61,21 @@ def normalize_answer_set(raw: object, rules: Rules) -> AnswerSetResult:
|
||||
documents: list[StatementDocument] = []
|
||||
warnings: list[StatementWarning] = []
|
||||
first_error: FileError | None = None
|
||||
succeeded = 0
|
||||
for index, entry in enumerate(files):
|
||||
error = file_error(index, entry)
|
||||
if error is not None:
|
||||
warnings.append(error.to_warning(rules))
|
||||
first_error = first_error or error
|
||||
continue
|
||||
succeeded += 1
|
||||
assert isinstance(entry, dict) # проверено file_error
|
||||
_normalize_file(entry, rules, documents, warnings)
|
||||
|
||||
status = envelope_status([d.status for d in documents], warnings)
|
||||
if status is not EnvelopeStatus.ERROR:
|
||||
return AnswerSetResult(status, tuple(documents), tuple(warnings), None)
|
||||
if first_error is not None:
|
||||
if first_error is not None and not succeeded: # Р-33: код первого ошибочного, только когда все json ошибочны
|
||||
error_info = SetError(first_error.code, first_error.summary)
|
||||
else:
|
||||
error_info = SetError(ErrorCode.RECOGNITION_FAILED, NO_TABLES_MESSAGE)
|
||||
|
||||
@ -149,3 +149,11 @@ def test_ocr_column_dates_end_to_end(label: str, expected: date) -> None:
|
||||
doc = res.documents[0]
|
||||
assert [(c.period_kind, c.period_date) for c in doc.columns] == [(PeriodKind.ABSOLUTE, expected)]
|
||||
assert doc.header.report_date.value == date(2024, 12, 31)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("second", [response(), response(ocr_table("", [("Руководитель", "Иванов")]))])
|
||||
def test_one_failed_one_successful_without_documents_is_recognition_failed(second: dict[str, Any]) -> None:
|
||||
res = normalize_answer_set(merged(("j.json", response(error=BAD)), ("j_ofr.json", second)), RULES)
|
||||
assert res.status is EnvelopeStatus.ERROR and res.documents == ()
|
||||
assert (res.error.code, res.error.message) == (ErrorCode.RECOGNITION_FAILED, NO_TABLES_MESSAGE)
|
||||
assert ("JSON_FAILED", "file:j.json") in [(w.code, w.locator) for w in res.file_warnings]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user