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

TestAnthropic Class — anthropic-sdk-python Architecture

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

Entity Profile

Dependency Diagram

graph TD
  d53b6c34_1743_a045_4be1_3554ab153964["TestAnthropic"]
  17ce5647_6f06_0676_a4a5_e378a3f57cb1["BaseModel"]
  d53b6c34_1743_a045_4be1_3554ab153964 -->|extends| 17ce5647_6f06_0676_a4a5_e378a3f57cb1
  b32f013f_956e_96fd_9f6d_94151a449136["Model2"]
  d53b6c34_1743_a045_4be1_3554ab153964 -->|extends| b32f013f_956e_96fd_9f6d_94151a449136
  0fa24978_add9_abda_1a4e_fde7589db6ab["Model1"]
  d53b6c34_1743_a045_4be1_3554ab153964 -->|extends| 0fa24978_add9_abda_1a4e_fde7589db6ab
  a6fff0e7_9ede_c681_7580_0d5f4208be04["Model"]
  d53b6c34_1743_a045_4be1_3554ab153964 -->|extends| a6fff0e7_9ede_c681_7580_0d5f4208be04
  784c8609_446c_8ad9_9fbc_2f1a028e3cfc["APIResponseValidationError"]
  d53b6c34_1743_a045_4be1_3554ab153964 -->|extends| 784c8609_446c_8ad9_9fbc_2f1a028e3cfc
  3c15a36b_3b82_93a8_fe82_3d955b1934ca["Stream"]
  d53b6c34_1743_a045_4be1_3554ab153964 -->|extends| 3c15a36b_3b82_93a8_fe82_3d955b1934ca
  e4a9b8e1_6fee_1c9b_f943_12d9853a22f3["APITimeoutError"]
  d53b6c34_1743_a045_4be1_3554ab153964 -->|extends| e4a9b8e1_6fee_1c9b_f943_12d9853a22f3
  f2b4a800_fc6e_a4b1_452a_a707d6a71c8c["APIStatusError"]
  d53b6c34_1743_a045_4be1_3554ab153964 -->|extends| f2b4a800_fc6e_a4b1_452a_a707d6a71c8c
  9e5c097c_ec73_f29f_5858_a29a8c31dd98["test_client.py"]
  d53b6c34_1743_a045_4be1_3554ab153964 -->|defined in| 9e5c097c_ec73_f29f_5858_a29a8c31dd98
  aed21858_eb15_a7cb_a832_a6cb0d4205e4["test_raw_response()"]
  d53b6c34_1743_a045_4be1_3554ab153964 -->|method| aed21858_eb15_a7cb_a832_a6cb0d4205e4
  1f603d78_5e09_2f3a_dcef_536d1e4e3baf["test_raw_response_for_binary()"]
  d53b6c34_1743_a045_4be1_3554ab153964 -->|method| 1f603d78_5e09_2f3a_dcef_536d1e4e3baf
  8fe7591b_2b14_11be_b1c1_d15fd7119542["test_copy()"]
  d53b6c34_1743_a045_4be1_3554ab153964 -->|method| 8fe7591b_2b14_11be_b1c1_d15fd7119542
  b690456f_9001_fa33_5498_bf5a6b9d9ec4["test_copy_default_options()"]
  d53b6c34_1743_a045_4be1_3554ab153964 -->|method| b690456f_9001_fa33_5498_bf5a6b9d9ec4
  42713461_a08c_cbdb_7366_defcb18a80f1["test_copy_default_headers()"]
  d53b6c34_1743_a045_4be1_3554ab153964 -->|method| 42713461_a08c_cbdb_7366_defcb18a80f1

Relationship Graph

Source Code

tests/test_client.py lines 115–1090

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

        response = 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)
    def test_raw_response_for_binary(self, respx_mock: MockRouter, client: Anthropic) -> None:
        respx_mock.post("/foo").mock(
            return_value=httpx.Response(200, headers={"Content-Type": "application/binary"}, content='{"foo": "bar"}')
        )

        response = 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, client: Anthropic) -> None:
        copied = client.copy()
        assert id(copied) != id(client)

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

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

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

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

    def test_copy_default_headers(self) -> None:
        client = Anthropic(
            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"})
        client.close()

    def test_copy_default_query(self) -> None:

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free