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

TestAnthropicVertex Class — anthropic-sdk-python Architecture

Architecture documentation for the TestAnthropicVertex class in test_vertex.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  4a282b80_48ff_4ba8_f27f_bad6b030b947["TestAnthropicVertex"]
  db230024_6f86_b90f_ba9d_ea89f56ffac7["test_vertex.py"]
  4a282b80_48ff_4ba8_f27f_bad6b030b947 -->|defined in| db230024_6f86_b90f_ba9d_ea89f56ffac7
  3b3c7af1_44b3_cbc7_4c8d_4ea75f33e855["test_messages_retries()"]
  4a282b80_48ff_4ba8_f27f_bad6b030b947 -->|method| 3b3c7af1_44b3_cbc7_4c8d_4ea75f33e855
  788a9997_4593_ea4a_405e_1d6166f25e62["test_copy()"]
  4a282b80_48ff_4ba8_f27f_bad6b030b947 -->|method| 788a9997_4593_ea4a_405e_1d6166f25e62
  32103369_434d_cd4f_744c_8312ab2b9b3c["test_with_options()"]
  4a282b80_48ff_4ba8_f27f_bad6b030b947 -->|method| 32103369_434d_cd4f_744c_8312ab2b9b3c
  0d8a0dfd_83cd_186a_bf4d_f88e929e7702["test_copy_default_options()"]
  4a282b80_48ff_4ba8_f27f_bad6b030b947 -->|method| 0d8a0dfd_83cd_186a_bf4d_f88e929e7702
  0bf60e41_4ec6_fb08_f96a_70685170e508["test_copy_default_headers()"]
  4a282b80_48ff_4ba8_f27f_bad6b030b947 -->|method| 0bf60e41_4ec6_fb08_f96a_70685170e508
  121b405a_9255_b8ad_d625_9c4b9b11fe5a["test_global_region_base_url()"]
  4a282b80_48ff_4ba8_f27f_bad6b030b947 -->|method| 121b405a_9255_b8ad_d625_9c4b9b11fe5a
  8585eaa8_6ec4_0034_2f78_1da3aebc7f7c["test_regional_base_url()"]
  4a282b80_48ff_4ba8_f27f_bad6b030b947 -->|method| 8585eaa8_6ec4_0034_2f78_1da3aebc7f7c
  39ea5662_3fa7_a372_9984_14d2b99f4739["test_env_var_base_url_override()"]
  4a282b80_48ff_4ba8_f27f_bad6b030b947 -->|method| 39ea5662_3fa7_a372_9984_14d2b99f4739

Relationship Graph

Source Code

tests/lib/test_vertex.py lines 20–146

class TestAnthropicVertex:
    client = AnthropicVertex(region="region", project_id="project", access_token="my-access-token")

    @pytest.mark.respx()
    def test_messages_retries(self, respx_mock: MockRouter) -> None:
        request_url = "https://region-aiplatform.googleapis.com/v1/projects/project/locations/region/publishers/anthropic/models/claude-3-sonnet@20240229:rawPredict"
        respx_mock.post(request_url).mock(
            side_effect=[
                httpx.Response(500, json={"error": "server error"}, headers={"retry-after-ms": "10"}),
                httpx.Response(200, json={"foo": "bar"}),
            ]
        )

        self.client.messages.create(
            max_tokens=1024,
            messages=[
                {
                    "role": "user",
                    "content": "Say hello there!",
                }
            ],
            model="claude-3-sonnet@20240229",
        )

        calls = cast("list[MockRequestCall]", respx_mock.calls)

        assert len(calls) == 2

        assert calls[0].request.url == request_url
        assert calls[1].request.url == request_url

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

        copied = self.client.copy(region="another-region", project_id="another-project")
        assert copied.region == "another-region"
        assert self.client.region == "region"
        assert copied.project_id == "another-project"
        assert self.client.project_id == "project"

    def test_with_options(self) -> None:
        copied = self.client.with_options(region="another-region", project_id="another-project")
        assert copied.region == "another-region"
        assert self.client.region == "region"
        assert copied.project_id == "another-project"
        assert self.client.project_id == "project"

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

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

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

    def test_copy_default_headers(self) -> None:
        client = AnthropicVertex(
            base_url=base_url,
            region="region",
            project_id="project",
            _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"

Frequently Asked Questions

What is the TestAnthropicVertex class?
TestAnthropicVertex is a class in the anthropic-sdk-python codebase, defined in tests/lib/test_vertex.py.
Where is TestAnthropicVertex defined?
TestAnthropicVertex is defined in tests/lib/test_vertex.py at line 20.

Analyze Your Own Codebase

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

Try Supermodel Free