Skip to content

Commit 8c96c43

Browse files
committed
Address review: trim test docstring, add log+capture assertions
1 parent 8236f1a commit 8c96c43

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,9 @@ ignore_errors = True
922922
[mypy-opencontractserver.tests.test_openai_embedder]
923923
ignore_errors = True
924924

925+
[mypy-opencontractserver.tests.test_package_annotated_docs]
926+
ignore_errors = True
927+
925928
[mypy-opencontractserver.tests.test_page_imaging_tool]
926929
ignore_errors = True
927930

opencontractserver/tests/test_package_annotated_docs.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
"""
2-
Tests for :func:`opencontractserver.tasks.export_tasks.package_annotated_docs`.
3-
4-
Regression coverage for issue #1356:
5-
6-
``build_document_export()`` returns ``("", "", None, {}, {})`` for documents
7-
whose export failed (e.g. underlying file could not be loaded or all
8-
annotations were filtered out). Prior to the fix, ``package_annotated_docs``
9-
iterated those placeholder tuples without any guard, silently writing an
10-
empty-named file to the zip and inserting ``annotated_docs[""] = None`` into
11-
the final ``data.json``. The fix adds an explicit skip for failed
12-
placeholders. These tests verify that behavior.
13-
"""
1+
"""Regression tests for ``package_annotated_docs`` skipping failed placeholders."""
142

153
from __future__ import annotations
164

@@ -105,13 +93,20 @@ def test_skips_failed_placeholder_and_packages_successful_docs(self) -> None:
10593
with patch(
10694
"opencontractserver.tasks.export_tasks.finalize_export",
10795
side_effect=capture_fn,
108-
):
96+
), self.assertLogs(
97+
"opencontractserver.tasks.export_tasks", level="WARNING"
98+
) as log_cm:
10999
package_annotated_docs(
110100
burned_docs=(good_doc, failed_doc),
111101
export_id=self.export.id,
112102
corpus_pk=self.corpus.id,
113103
)
114104

105+
self.assertTrue(
106+
any("Skipping failed burned doc" in line for line in log_cm.output),
107+
f"Expected skip-warning log, got: {log_cm.output}",
108+
)
109+
self.assertIn("bytes", captured, "finalize_export was not called")
115110
zf = zipfile.ZipFile(io.BytesIO(captured["bytes"]))
116111
names = set(zf.namelist())
117112

@@ -148,6 +143,7 @@ def test_all_failed_produces_empty_annotated_docs_without_crashing(self) -> None
148143
corpus_pk=self.corpus.id,
149144
)
150145

146+
self.assertIn("bytes", captured, "finalize_export was not called")
151147
zf = zipfile.ZipFile(io.BytesIO(captured["bytes"]))
152148
# Only data.json, no empty-filename entry.
153149
self.assertEqual(set(zf.namelist()), {"data.json"})

0 commit comments

Comments
 (0)