|
2 | 2 | import typing as t |
3 | 3 | import inspect |
4 | 4 | import tempfile |
| 5 | +from contextlib import AbstractAsyncContextManager, AbstractContextManager |
5 | 6 | from typing import Any, TypedDict, cast |
6 | 7 | from typing_extensions import Protocol |
7 | 8 |
|
@@ -175,20 +176,25 @@ def test_region_infer_from_profile( |
175 | 176 | assert client.aws_region == profiles[0]["region"] |
176 | 177 |
|
177 | 178 |
|
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 | + ) |
180 | 185 |
|
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 | + ) |
188 | 196 |
|
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) |
192 | 198 |
|
193 | 199 |
|
194 | 200 | @pytest.mark.parametrize( |
|
0 commit comments