Skip to content

Commit 92d0844

Browse files
author
Bob Strahan
committed
fix failing test cases
1 parent 4009b83 commit 92d0844

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

lib/idp_common_pkg/tests/unit/classification/test_classification_service.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,11 @@ def test_classify_page_bedrock_model_error(
270270
mock_get_text.return_value = "This is an invoice for $100"
271271
mock_invoke.side_effect = Exception("Model error")
272272

273-
# Call the method
274-
result = service.classify_page_bedrock(
275-
page_id="1", text_uri="s3://bucket/text.txt"
276-
)
277-
278-
# Verify results
279-
assert result.page_id == "1"
280-
assert result.classification.doc_type == "unclassified"
281-
assert result.classification.confidence == 0.0
282-
assert result.classification.metadata["error"] == "Model error"
273+
# Call the method and expect exception to be raised
274+
with pytest.raises(Exception, match="Model error"):
275+
service.classify_page_bedrock(
276+
page_id="1", text_uri="s3://bucket/text.txt"
277+
)
283278

284279
@patch("boto3.client")
285280
def test_classify_page_sagemaker_success(self, mock_boto_client, mock_config):

lib/idp_common_pkg/tests/unit/extraction/test_extraction_service.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,47 @@ def test_process_document_section_no_pages(
300300
assert "Section 2 has no page IDs" in result.errors[0]
301301

302302
@patch("idp_common.s3.get_text_content")
303+
@patch("idp_common.image.prepare_image")
304+
@patch("idp_common.image.prepare_bedrock_image_attachment")
305+
@patch("idp_common.bedrock.invoke_model")
306+
@patch("idp_common.s3.write_content")
307+
@patch("idp_common.utils.merge_metering_data")
303308
@patch("idp_common.metrics.put_metric")
304309
def test_process_document_section_missing_page(
305-
self, mock_put_metric, mock_get_text_content, service, sample_document
310+
self,
311+
mock_put_metric,
312+
mock_merge_metering,
313+
mock_write_content,
314+
mock_invoke_model,
315+
mock_prepare_bedrock_image,
316+
mock_prepare_image,
317+
mock_get_text_content,
318+
service,
319+
sample_document,
306320
):
307321
"""Test processing a document section with a missing page."""
308322
# Add a non-existent page ID to the section
309323
sample_document.sections[0].page_ids.append("999")
310324

311-
# Mock text content for existing pages
325+
# Mock responses
312326
mock_get_text_content.side_effect = ["Page 1 text", "Page 2 text"]
327+
mock_prepare_image.return_value = b"fake_image_data"
328+
mock_prepare_bedrock_image.return_value = {"type": "image", "source": {}}
329+
mock_invoke_model.return_value = {
330+
"response": {
331+
"output": {
332+
"message": {
333+
"content": [
334+
{
335+
"text": '{"invoice_number": "INV-123"}'
336+
}
337+
]
338+
}
339+
}
340+
},
341+
"metering": {"input_tokens": 100, "output_tokens": 50},
342+
}
343+
mock_merge_metering.return_value = {"total_tokens": 150}
313344

314345
# Process the section
315346
result = service.process_document_section(sample_document, "1")
@@ -326,12 +357,9 @@ def test_process_document_section_exception(
326357
# Mock an exception
327358
mock_get_text_content.side_effect = Exception("Test exception")
328359

329-
# Process the section
330-
result = service.process_document_section(sample_document, "1")
331-
332-
# Verify error was added
333-
assert len(result.errors) == 1
334-
assert "Error processing section 1: Test exception" in result.errors[0]
360+
# Process the section and expect exception to be raised
361+
with pytest.raises(Exception, match="Test exception"):
362+
service.process_document_section(sample_document, "1")
335363

336364
def test_extract_json_code_block(self, service):
337365
"""Test extracting JSON from code block."""

lib/idp_common_pkg/tests/unit/summarization/test_summarization_service.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,9 @@ def test_process_text_error(self, mock_invoke_model, service):
325325
# Configure mock to raise exception
326326
mock_invoke_model.side_effect = Exception("Test error")
327327

328-
result = service.process_text("Test document text")
329-
330-
# Verify result
331-
assert result.content["error"] == "Error generating summary"
332-
assert result.metadata["error"] == "Test error"
328+
# Expect exception to be raised
329+
with pytest.raises(Exception, match="Test error"):
330+
service.process_text("Test document text")
333331

334332
@patch("idp_common.s3.get_text_content")
335333
@patch("idp_common.s3.write_content")

0 commit comments

Comments
 (0)