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

TestAsyncAnthropic Class — anthropic-sdk-python Architecture

Architecture documentation for the TestAsyncAnthropic class in test_client.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  9bf4cfe0_e3b0_70de_25ac_2113c8918900["TestAsyncAnthropic"]
  17ce5647_6f06_0676_a4a5_e378a3f57cb1["BaseModel"]
  9bf4cfe0_e3b0_70de_25ac_2113c8918900 -->|extends| 17ce5647_6f06_0676_a4a5_e378a3f57cb1
  b32f013f_956e_96fd_9f6d_94151a449136["Model2"]
  9bf4cfe0_e3b0_70de_25ac_2113c8918900 -->|extends| b32f013f_956e_96fd_9f6d_94151a449136
  0fa24978_add9_abda_1a4e_fde7589db6ab["Model1"]
  9bf4cfe0_e3b0_70de_25ac_2113c8918900 -->|extends| 0fa24978_add9_abda_1a4e_fde7589db6ab
  a6fff0e7_9ede_c681_7580_0d5f4208be04["Model"]
  9bf4cfe0_e3b0_70de_25ac_2113c8918900 -->|extends| a6fff0e7_9ede_c681_7580_0d5f4208be04
  784c8609_446c_8ad9_9fbc_2f1a028e3cfc["APIResponseValidationError"]
  9bf4cfe0_e3b0_70de_25ac_2113c8918900 -->|extends| 784c8609_446c_8ad9_9fbc_2f1a028e3cfc
  03fc0a8b_1c63_1aee_ef30_754aeebc2ff6["AsyncStream"]
  9bf4cfe0_e3b0_70de_25ac_2113c8918900 -->|extends| 03fc0a8b_1c63_1aee_ef30_754aeebc2ff6
  e4a9b8e1_6fee_1c9b_f943_12d9853a22f3["APITimeoutError"]
  9bf4cfe0_e3b0_70de_25ac_2113c8918900 -->|extends| e4a9b8e1_6fee_1c9b_f943_12d9853a22f3
  f2b4a800_fc6e_a4b1_452a_a707d6a71c8c["APIStatusError"]
  9bf4cfe0_e3b0_70de_25ac_2113c8918900 -->|extends| f2b4a800_fc6e_a4b1_452a_a707d6a71c8c
  9e5c097c_ec73_f29f_5858_a29a8c31dd98["test_client.py"]
  9bf4cfe0_e3b0_70de_25ac_2113c8918900 -->|defined in| 9e5c097c_ec73_f29f_5858_a29a8c31dd98
  fe60adc8_f8e4_f5da_4100_e19f48ca3844["test_raw_response()"]
  9bf4cfe0_e3b0_70de_25ac_2113c8918900 -->|method| fe60adc8_f8e4_f5da_4100_e19f48ca3844
  f6197800_7239_1194_baac_fe29d16c004c["test_raw_response_for_binary()"]
  9bf4cfe0_e3b0_70de_25ac_2113c8918900 -->|method| f6197800_7239_1194_baac_fe29d16c004c
  2f56b542_d3fb_fe17_b190_cf0d4fc2531c["test_copy()"]
  9bf4cfe0_e3b0_70de_25ac_2113c8918900 -->|method| 2f56b542_d3fb_fe17_b190_cf0d4fc2531c
  d52f3e3a_8ac1_1640_89eb_1efb04f62183["test_copy_default_options()"]
  9bf4cfe0_e3b0_70de_25ac_2113c8918900 -->|method| d52f3e3a_8ac1_1640_89eb_1efb04f62183
  4b2dc738_ca52_0d04_33d8_d56d8628eccd["test_copy_default_headers()"]
  9bf4cfe0_e3b0_70de_25ac_2113c8918900 -->|method| 4b2dc738_ca52_0d04_33d8_d56d8628eccd

Relationship Graph

Source Code

tests/test_client.py lines 1093–2095

class TestAsyncAnthropic:
    @pytest.mark.respx(base_url=base_url)
    async def test_raw_response(self, respx_mock: MockRouter, async_client: AsyncAnthropic) -> None:
        respx_mock.post("/foo").mock(return_value=httpx.Response(200, json={"foo": "bar"}))

        response = await async_client.post("/foo", cast_to=httpx.Response)
        assert response.status_code == 200
        assert isinstance(response, httpx.Response)
        assert response.json() == {"foo": "bar"}

    @pytest.mark.respx(base_url=base_url)
    async def test_raw_response_for_binary(self, respx_mock: MockRouter, async_client: AsyncAnthropic) -> None:
        respx_mock.post("/foo").mock(
            return_value=httpx.Response(200, headers={"Content-Type": "application/binary"}, content='{"foo": "bar"}')
        )

        response = await async_client.post("/foo", cast_to=httpx.Response)
        assert response.status_code == 200
        assert isinstance(response, httpx.Response)
        assert response.json() == {"foo": "bar"}

    def test_copy(self, async_client: AsyncAnthropic) -> None:
        copied = async_client.copy()
        assert id(copied) != id(async_client)

        copied = async_client.copy(api_key="another my-anthropic-api-key")
        assert copied.api_key == "another my-anthropic-api-key"
        assert async_client.api_key == "my-anthropic-api-key"

    def test_copy_default_options(self, async_client: AsyncAnthropic) -> None:
        # options that have a default are overridden correctly
        copied = async_client.copy(max_retries=7)
        assert copied.max_retries == 7
        assert async_client.max_retries == 2

        copied2 = copied.copy(max_retries=6)
        assert copied2.max_retries == 6
        assert copied.max_retries == 7

        # timeout
        assert isinstance(async_client.timeout, httpx.Timeout)
        copied = async_client.copy(timeout=None)
        assert copied.timeout is None
        assert isinstance(async_client.timeout, httpx.Timeout)

    async def test_copy_default_headers(self) -> None:
        client = AsyncAnthropic(
            base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={"X-Foo": "bar"}
        )
        assert client.default_headers["X-Foo"] == "bar"

        # does not override the already given value when not specified
        copied = client.copy()
        assert copied.default_headers["X-Foo"] == "bar"

        # merges already given headers
        copied = client.copy(default_headers={"X-Bar": "stainless"})
        assert copied.default_headers["X-Foo"] == "bar"
        assert copied.default_headers["X-Bar"] == "stainless"

        # uses new values for any already given headers
        copied = client.copy(default_headers={"X-Foo": "stainless"})
        assert copied.default_headers["X-Foo"] == "stainless"

        # set_default_headers

        # completely overrides already set values
        copied = client.copy(set_default_headers={})
        assert copied.default_headers.get("X-Foo") is None

        copied = client.copy(set_default_headers={"X-Bar": "Robert"})
        assert copied.default_headers["X-Bar"] == "Robert"

        with pytest.raises(
            ValueError,
            match="`default_headers` and `set_default_headers` arguments are mutually exclusive",
        ):
            client.copy(set_default_headers={}, default_headers={"X-Foo": "Bar"})
        await client.close()

    async def test_copy_default_query(self) -> None:

Frequently Asked Questions

What is the TestAsyncAnthropic class?
TestAsyncAnthropic is a class in the anthropic-sdk-python codebase, defined in tests/test_client.py.
Where is TestAsyncAnthropic defined?
TestAsyncAnthropic is defined in tests/test_client.py at line 1093.
What does TestAsyncAnthropic extend?
TestAsyncAnthropic extends BaseModel, Model2, Model1, Model, APIResponseValidationError, AsyncStream, APITimeoutError, APIStatusError.

Analyze Your Own Codebase

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

Try Supermodel Free