|
2 | 2 |
|
3 | 3 | import os |
4 | 4 | import json |
5 | | -import inspect |
6 | 5 | from typing import Any, Set, Dict, TypeVar, cast |
7 | 6 | from unittest import TestCase |
8 | 7 |
|
|
11 | 10 | from respx import MockRouter |
12 | 11 |
|
13 | 12 | from anthropic import Anthropic, AsyncAnthropic |
| 13 | +from anthropic._utils import assert_overloads_in_sync, assert_signatures_in_sync |
14 | 14 | from anthropic._compat import PYDANTIC_V1 |
15 | 15 | from anthropic.types.beta.beta_message import BetaMessage |
16 | 16 | from anthropic.lib.streaming._beta_types import ParsedBetaMessageStreamEvent |
@@ -376,36 +376,31 @@ async def test_incomplete_response(self, respx_mock: MockRouter) -> None: |
376 | 376 | @pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) |
377 | 377 | def test_stream_method_definition_in_sync(sync: bool) -> None: |
378 | 378 | client: Anthropic | AsyncAnthropic = sync_client if sync else async_client |
| 379 | + assert_signatures_in_sync( |
| 380 | + client.beta.messages.create, |
| 381 | + client.beta.messages.stream, |
| 382 | + exclude_params={"stream", "output_format"}, |
| 383 | + ) |
379 | 384 |
|
380 | | - sig = inspect.signature(client.beta.messages.stream) |
381 | | - generated_sig = inspect.signature(client.beta.messages.create) |
382 | | - |
383 | | - errors: list[str] = [] |
384 | | - |
385 | | - for name, generated_param in generated_sig.parameters.items(): |
386 | | - if name == "stream": |
387 | | - # intentionally excluded |
388 | | - continue |
389 | | - |
390 | | - if name == "output_format": |
391 | | - continue |
392 | 385 |
|
393 | | - custom_param = sig.parameters.get(name) |
394 | | - if not custom_param: |
395 | | - errors.append(f"the `{name}` param is missing") |
396 | | - continue |
| 386 | +@pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) |
| 387 | +def test_parse_method_definition_in_sync(sync: bool) -> None: |
| 388 | + client: Anthropic | AsyncAnthropic = sync_client if sync else async_client |
| 389 | + assert_signatures_in_sync( |
| 390 | + client.beta.messages.create, |
| 391 | + client.beta.messages.parse, |
| 392 | + exclude_params={"stream", "output_format"}, |
| 393 | + ) |
397 | 394 |
|
398 | | - if custom_param.annotation != generated_param.annotation: |
399 | | - errors.append( |
400 | | - f"types for the `{name}` param are do not match; generated={repr(generated_param.annotation)} custom={repr(custom_param.annotation)}" |
401 | | - ) |
402 | | - continue |
403 | 395 |
|
404 | | - if errors: |
405 | | - raise AssertionError( |
406 | | - f"{len(errors)} errors encountered with the {'sync' if sync else 'async'} client `messages.stream()` method:\n\n" |
407 | | - + "\n\n".join(errors) |
408 | | - ) |
| 396 | +@pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) |
| 397 | +def test_tool_runner_method_definition_in_sync(sync: bool) -> None: |
| 398 | + client: Anthropic | AsyncAnthropic = sync_client if sync else async_client |
| 399 | + assert_overloads_in_sync( |
| 400 | + client.beta.messages.create, |
| 401 | + client.beta.messages.tool_runner, |
| 402 | + exclude_params={"stream", "tools", "max_iterations", "compaction_control", "output_format"}, |
| 403 | + ) |
409 | 404 |
|
410 | 405 |
|
411 | 406 | # go through all the ContentBlock types to make sure the type alias is up to date |
|
0 commit comments