Skip to content

Commit ffd3724

Browse files
committed
add more unit tests
1 parent c959dd5 commit ffd3724

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_instrumentation_patch.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ def _run_patch_behaviour_tests(self):
8484
self._test_unpatched_botocore_propagator()
8585
self._test_unpatched_gevent_instrumentation()
8686
self._test_unpatched_starlette_instrumentation()
87-
self._test_unpatched_bedrock_runtime_instrumentation()
87+
# TODO: remove these tests once we bump botocore instrumentation version to 0.56b0
88+
# Bedrock Runtime tests
89+
self._test_unpatched_converse_stream_wrapper()
90+
self._test_unpatched_extract_tool_calls()
8891

8992
# Apply patches
9093
apply_instrumentation_patches()
@@ -220,8 +223,10 @@ def _test_patched_botocore_instrumentation(self):
220223
# Bedrock Agent Operation
221224
self._test_patched_bedrock_agent_instrumentation()
222225

226+
# TODO: remove these tests once we bump botocore instrumentation version to 0.56b0
223227
# Bedrock Runtime
224-
self._test_patched_bedrock_runtime_instrumentation()
228+
self._test_patched_converse_stream_wrapper()
229+
self._test_patched_extract_tool_calls()
225230

226231
# Bedrock Agent Runtime
227232
self.assertTrue("bedrock-agent-runtime" in _KNOWN_EXTENSIONS)
@@ -474,7 +479,13 @@ def _test_patched_bedrock_instrumentation(self):
474479
self.assertEqual(len(bedrock_sucess_attributes), 1)
475480
self.assertEqual(bedrock_sucess_attributes["aws.bedrock.guardrail.id"], _BEDROCK_GUARDRAIL_ID)
476481

477-
def _test_unpatched_bedrock_runtime_instrumentation(self):
482+
def _test_unpatched_extract_tool_calls(self):
483+
"""Test unpatched extract_tool_calls with string content throws AttributeError"""
484+
message_with_string_content = {"role": "assistant", "content": "{"}
485+
with self.assertRaises(AttributeError) as context:
486+
bedrock_utils.extract_tool_calls(message_with_string_content, True)
487+
488+
def _test_unpatched_converse_stream_wrapper(self):
478489
"""Test unpatched bedrock-runtime where input values remain as numbers"""
479490

480491
mock_stream = MagicMock()
@@ -518,7 +529,7 @@ def _test_unpatched_bedrock_runtime_instrumentation(self):
518529
self.assertEqual(len(wrapper._message["content"]), 1)
519530
self.assertEqual(wrapper._message["content"][0]["toolUse"], expected_tool_use)
520531

521-
def _test_patched_bedrock_runtime_instrumentation(self):
532+
def _test_patched_converse_stream_wrapper(self):
522533
"""Test patched bedrock-runtime"""
523534

524535
# Create mock arguments for ConverseStreamWrapper
@@ -581,6 +592,14 @@ def _test_patched_bedrock_runtime_instrumentation(self):
581592
self.assertEqual(len(wrapper._message["content"]), 1)
582593
self.assertEqual(wrapper._message["content"][0]["toolUse"], expected_tool_use)
583594

595+
def _test_patched_extract_tool_calls(self):
596+
"""Test patched extract_tool_calls with string content"""
597+
598+
# Test extract_tool_calls with string content (should return None)
599+
message_with_string_content = {"role": "assistant", "content": "{"}
600+
result = bedrock_utils.extract_tool_calls(message_with_string_content, True)
601+
self.assertIsNone(result)
602+
584603
def _test_patched_bedrock_agent_instrumentation(self):
585604
"""For bedrock-agent service, both extract_attributes and on_success provides attributes,
586605
the attributes depend on the API being invoked."""

0 commit comments

Comments
 (0)