Skip to content

Commit 1ebf282

Browse files
committed
fix: fix unit tests
1 parent 3a734d9 commit 1ebf282

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/strands/agent/agent.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import os
1515
import random
1616
from concurrent.futures import ThreadPoolExecutor
17-
from typing import Any, AsyncIterator, Callable, Generator, Mapping, Optional, Type, TypeVar, Union, cast
17+
from typing import Any, AsyncIterator, Callable, Generator, List, Mapping, Optional, Type, TypeVar, Union, cast
1818

1919
from opentelemetry import trace
2020
from pydantic import BaseModel
@@ -512,10 +512,10 @@ def _execute_event_loop_cycle(
512512

513513
def _record_tool_execution(
514514
self,
515-
tool: dict[str, Any],
516-
tool_result: dict[str, Any],
515+
tool: ToolUse,
516+
tool_result: ToolResult,
517517
user_message_override: Optional[str],
518-
messages: list[dict[str, Any]],
518+
messages: Messages,
519519
) -> None:
520520
"""Record a tool execution in the message history.
521521

tests/strands/models/test_bedrock.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,11 @@ def test__init__default_model_id(bedrock_client):
121121

122122
def test__init__with_default_region(session_cls, mock_client_method):
123123
"""Test that BedrockModel uses the provided region."""
124-
BedrockModel()
125-
126-
session_cls.return_value.client.assert_called_with(region_name=DEFAULT_BEDROCK_REGION, config=ANY, service_name=ANY)
124+
with unittest.mock.patch.object(os, "environ", {}):
125+
BedrockModel()
126+
session_cls.return_value.client.assert_called_with(
127+
region_name=DEFAULT_BEDROCK_REGION, config=ANY, service_name=ANY
128+
)
127129

128130

129131
def test__init__with_session_region(session_cls, mock_client_method):
@@ -152,7 +154,7 @@ def test__init__with_default_environment_variable_region(mock_client_method):
152154

153155
def test__init__region_precedence(mock_client_method, session_cls):
154156
"""Test that BedrockModel uses the correct ordering of precedence when determining region."""
155-
with unittest.mock.patch.object(os, "environ", {"AWS_REGION": "us-environment-1"}):
157+
with unittest.mock.patch.object(os, "environ", {"AWS_REGION": "us-environment-1"}) as mock_os_environ:
156158
session_cls.return_value.region_name = "us-session-1"
157159

158160
# specifying a region always wins out
@@ -168,9 +170,10 @@ def test__init__region_precedence(mock_client_method, session_cls):
168170
BedrockModel()
169171
mock_client_method.assert_called_with(region_name="us-environment-1", config=ANY, service_name=ANY)
170172

171-
# Finally default
172-
BedrockModel()
173-
mock_client_method.assert_called_with(region_name=DEFAULT_BEDROCK_REGION, config=ANY, service_name=ANY)
173+
mock_os_environ.pop("AWS_REGION")
174+
session_cls.return_value.region_name = None # No session region
175+
BedrockModel()
176+
mock_client_method.assert_called_with(region_name=DEFAULT_BEDROCK_REGION, config=ANY, service_name=ANY)
174177

175178

176179
def test__init__with_region_and_session_raises_value_error():

0 commit comments

Comments
 (0)