Skip to content

Commit da0a69a

Browse files
test(bedrock): cover beta.messages.stream parity
1 parent c9104ec commit da0a69a

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

tests/lib/test_bedrock.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import typing as t
33
import inspect
44
import tempfile
5+
from contextlib import AbstractAsyncContextManager, AbstractContextManager
56
from typing import Any, TypedDict, cast
67
from typing_extensions import Protocol
78

@@ -175,20 +176,25 @@ def test_region_infer_from_profile(
175176
assert client.aws_region == profiles[0]["region"]
176177

177178

178-
def test_bedrock_beta_messages_stream_exists() -> None:
179-
"""Regression test: Bedrock beta.messages.stream should exist and be callable.
179+
def test_beta_messages_stream_exists_sync() -> None:
180+
stream_ctx = sync_client.beta.messages.stream(
181+
max_tokens=1,
182+
messages=[{"role": "user", "content": "hello"}],
183+
model="anthropic.claude-3-5-sonnet-20241022-v2:0",
184+
)
180185

181-
This ensures parity with first-party SDK's beta.messages.stream method.
182-
Previously, Bedrock clients lacked the stream() method on beta.messages,
183-
causing breakage when switching from Anthropic() to AnthropicBedrock().
184-
"""
185-
# Check sync client
186-
assert hasattr(sync_client.beta.messages, "stream"), "sync client beta.messages.stream not found"
187-
assert callable(sync_client.beta.messages.stream), "sync client beta.messages.stream is not callable"
186+
assert isinstance(stream_ctx, AbstractContextManager)
187+
188+
189+
@pytest.mark.asyncio()
190+
async def test_beta_messages_stream_exists_async() -> None:
191+
stream_ctx = async_client.beta.messages.stream(
192+
max_tokens=1,
193+
messages=[{"role": "user", "content": "hello"}],
194+
model="anthropic.claude-3-5-sonnet-20241022-v2:0",
195+
)
188196

189-
# Check async client
190-
assert hasattr(async_client.beta.messages, "stream"), "async client beta.messages.stream not found"
191-
assert callable(async_client.beta.messages.stream), "async client beta.messages.stream is not callable"
197+
assert isinstance(stream_ctx, AbstractAsyncContextManager)
192198

193199

194200
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)