Home / Class/ TestSyncRunTools Class — anthropic-sdk-python Architecture

TestSyncRunTools Class — anthropic-sdk-python Architecture

Architecture documentation for the TestSyncRunTools class in test_runners.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  6847e1ae_03a4_3e19_19ff_ea808e74d94c["TestSyncRunTools"]
  8ecd4321_1ed7_9c90_8d23_e61f807683d3["test_runners.py"]
  6847e1ae_03a4_3e19_19ff_ea808e74d94c -->|defined in| 8ecd4321_1ed7_9c90_8d23_e61f807683d3
  49e71ebb_20f4_087e_7d45_f025ccd02165["test_basic_call_sync()"]
  6847e1ae_03a4_3e19_19ff_ea808e74d94c -->|method| 49e71ebb_20f4_087e_7d45_f025ccd02165
  c6cb9700_00c6_527f_dcfd_c498f856fc40["test_tool_call_error()"]
  6847e1ae_03a4_3e19_19ff_ea808e74d94c -->|method| c6cb9700_00c6_527f_dcfd_c498f856fc40
  d58be04b_df6f_a0c1_5a21_2cb82fab496e["test_custom_message_handling()"]
  6847e1ae_03a4_3e19_19ff_ea808e74d94c -->|method| d58be04b_df6f_a0c1_5a21_2cb82fab496e
  eb9121ce_90c5_9e50_25e6_4cd4f45e879d["test_tool_call_caching()"]
  6847e1ae_03a4_3e19_19ff_ea808e74d94c -->|method| eb9121ce_90c5_9e50_25e6_4cd4f45e879d
  02207e27_836f_6963_15cf_0fc348ef6b62["test_streaming_call_sync()"]
  6847e1ae_03a4_3e19_19ff_ea808e74d94c -->|method| 02207e27_836f_6963_15cf_0fc348ef6b62
  02fd438c_68ab_e0a1_e789_e598f8598566["test_max_iterations()"]
  6847e1ae_03a4_3e19_19ff_ea808e74d94c -->|method| 02fd438c_68ab_e0a1_e789_e598f8598566
  e9798232_e45a_0fe8_021e_639088536658["test_streaming_call_sync_events()"]
  6847e1ae_03a4_3e19_19ff_ea808e74d94c -->|method| e9798232_e45a_0fe8_021e_639088536658
  dd0a9b14_98b5_81ba_de20_c96c8204e36f["test_compaction_control()"]
  6847e1ae_03a4_3e19_19ff_ea808e74d94c -->|method| dd0a9b14_98b5_81ba_de20_c96c8204e36f
  1c6ca369_cb5f_4c3d_c97c_9419f2c3dac6["test_server_side_tool()"]
  6847e1ae_03a4_3e19_19ff_ea808e74d94c -->|method| 1c6ca369_cb5f_4c3d_c97c_9419f2c3dac6

Relationship Graph

Source Code

tests/lib/tools/test_runners.py lines 79–548

class TestSyncRunTools:
    @pytest.mark.respx(base_url=base_url)
    def test_basic_call_sync(self, client: Anthropic, respx_mock: MockRouter, monkeypatch: pytest.MonkeyPatch) -> None:
        @beta_tool
        def get_weather(location: str, units: Literal["c", "f"]) -> BetaFunctionToolResultType:
            """Lookup the weather for a given city in either celsius or fahrenheit

            Args:
                location: The city and state, e.g. San Francisco, CA
                units: Unit for the output, either 'c' for celsius or 'f' for fahrenheit
            Returns:
                A dictionary containing the location, temperature, and weather condition.
            """
            return json.dumps(_get_weather(location, units))

        message = make_snapshot_request(
            lambda c: c.beta.messages.tool_runner(
                max_tokens=1024,
                model="claude-haiku-4-5",
                tools=[get_weather],
                messages=[{"role": "user", "content": "What is the weather in SF?"}],
            ).until_done(),
            content_snapshot=snapshots["basic"]["responses"],
            path="/v1/messages",
            mock_client=client,
            respx_mock=respx_mock,
        )

        assert print_obj(message, monkeypatch) == snapshots["basic"]["result"]

    @pytest.mark.respx(base_url=base_url)
    def test_tool_call_error(
        self,
        client: Anthropic,
        respx_mock: MockRouter,
        monkeypatch: pytest.MonkeyPatch,
        caplog: pytest.LogCaptureFixture,
    ) -> None:
        called = None

        @beta_tool
        def get_weather(location: str, units: Literal["c", "f"]) -> BetaFunctionToolResultType:
            """Lookup the weather for a given city in either celsius or fahrenheit

            Args:
                location: The city and state, e.g. San Francisco, CA
                units: Unit for the output, either 'c' for celsius or 'f' for fahrenheit
            Returns:
                A dictionary containing the location, temperature, and weather condition.
            """
            nonlocal called

            if called is None:
                called = True
                raise RuntimeError("Unexpected error, try again")
            return json.dumps(_get_weather(location, units))

        def tool_runner(client: Anthropic) -> List[Union[BetaMessageParam, None]]:
            runner = client.beta.messages.tool_runner(
                max_tokens=1024,
                model="claude-haiku-4-5",
                tools=[get_weather],
                messages=[{"role": "user", "content": "What is the weather in SF?"}],
            )

            actual_responses: List[Union[BetaMessageParam, None]] = []
            for _ in runner:
                tool_call_response = runner.generate_tool_call_response()
                if tool_call_response is not None:
                    actual_responses.append(tool_call_response)

            return actual_responses

        with caplog.at_level(logging.ERROR):
            message = make_snapshot_request(
                tool_runner,
                content_snapshot=snapshots["tool_call_error"]["responses"],
                path="/v1/messages",
                mock_client=client,
                respx_mock=respx_mock,
            )

Frequently Asked Questions

What is the TestSyncRunTools class?
TestSyncRunTools is a class in the anthropic-sdk-python codebase, defined in tests/lib/tools/test_runners.py.
Where is TestSyncRunTools defined?
TestSyncRunTools is defined in tests/lib/tools/test_runners.py at line 79.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free