Skip to content

Commit af315e3

Browse files
committed
mock asyncio sleep
1 parent a18c648 commit af315e3

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

tests/strands/event_loop/test_event_loop.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727

2828
@pytest.fixture
29-
def mock_asyncio():
29+
def mock_sleep():
3030
with unittest.mock.patch.object(
31-
strands.event_loop.event_loop, "asyncio", new_callable=unittest.mock.AsyncMock
31+
strands.event_loop.event_loop.asyncio, "sleep", new_callable=unittest.mock.AsyncMock
3232
) as mock:
3333
yield mock
3434

@@ -188,7 +188,7 @@ async def test_event_loop_cycle_text_response(
188188

189189
@pytest.mark.asyncio
190190
async def test_event_loop_cycle_text_response_throttling(
191-
mock_asyncio,
191+
mock_sleep,
192192
agent,
193193
model,
194194
agenerator,
@@ -217,12 +217,12 @@ async def test_event_loop_cycle_text_response_throttling(
217217

218218
assert tru_stop_reason == exp_stop_reason and tru_message == exp_message and tru_request_state == exp_request_state
219219
# Verify that sleep was called once with the initial delay
220-
mock_asyncio.sleep.assert_called_once()
220+
mock_sleep.assert_called_once()
221221

222222

223223
@pytest.mark.asyncio
224224
async def test_event_loop_cycle_exponential_backoff(
225-
mock_asyncio,
225+
mock_sleep,
226226
agent,
227227
model,
228228
agenerator,
@@ -256,13 +256,13 @@ async def test_event_loop_cycle_exponential_backoff(
256256

257257
# Verify that sleep was called with increasing delays
258258
# Initial delay is 4, then 8, then 16
259-
assert mock_asyncio.sleep.call_count == 3
260-
assert mock_asyncio.sleep.call_args_list == [call(4), call(8), call(16)]
259+
assert mock_sleep.call_count == 3
260+
assert mock_sleep.call_args_list == [call(4), call(8), call(16)]
261261

262262

263263
@pytest.mark.asyncio
264264
async def test_event_loop_cycle_text_response_throttling_exceeded(
265-
mock_asyncio,
265+
mock_sleep,
266266
agent,
267267
model,
268268
alist,
@@ -283,7 +283,7 @@ async def test_event_loop_cycle_text_response_throttling_exceeded(
283283
)
284284
await alist(stream)
285285

286-
mock_asyncio.sleep.assert_has_calls(
286+
mock_sleep.assert_has_calls(
287287
[
288288
call(4),
289289
call(8),
@@ -818,7 +818,7 @@ async def test_prepare_next_cycle_in_tool_execution(agent, model, tool_stream, a
818818

819819

820820
@pytest.mark.asyncio
821-
async def test_event_loop_cycle_exception_model_hooks(mock_asyncio, agent, model, agenerator, alist, hook_provider):
821+
async def test_event_loop_cycle_exception_model_hooks(mock_sleep, agent, model, agenerator, alist, hook_provider):
822822
"""Test that model hooks are correctly emitted even when throttled."""
823823
# Set up the model to raise throttling exceptions multiple times before succeeding
824824
exception = ModelThrottledException("ThrottlingException | ConverseStream")

0 commit comments

Comments
 (0)