Home / File/ test_functions.py — anthropic-sdk-python Source File

test_functions.py — anthropic-sdk-python Source File

Architecture documentation for test_functions.py, a python file in the anthropic-sdk-python codebase. 7 imports, 0 dependents.

File python AnthropicClient Authentication 7 imports 1 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  b38a2dde_3dd7_54c3_3cd6_31b55c63196d["test_functions.py"]
  89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"]
  b38a2dde_3dd7_54c3_3cd6_31b55c63196d --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875
  cde8421b_93c7_41e4_d69d_2a3f1bade2f2["pytest"]
  b38a2dde_3dd7_54c3_3cd6_31b55c63196d --> cde8421b_93c7_41e4_d69d_2a3f1bade2f2
  21de8837_7dae_989e_fdbb_1415c0770d90["pydantic"]
  b38a2dde_3dd7_54c3_3cd6_31b55c63196d --> 21de8837_7dae_989e_fdbb_1415c0770d90
  d10c5377_2939_0f0b_cc44_8759393f2853["anthropic"]
  b38a2dde_3dd7_54c3_3cd6_31b55c63196d --> d10c5377_2939_0f0b_cc44_8759393f2853
  42bc4048_b76c_4d27_9cbe_884618df8c52["anthropic._compat"]
  b38a2dde_3dd7_54c3_3cd6_31b55c63196d --> 42bc4048_b76c_4d27_9cbe_884618df8c52
  d0f46640_368d_8e60_2a90_5b5b56eeb69b["anthropic.lib.tools._beta_functions"]
  b38a2dde_3dd7_54c3_3cd6_31b55c63196d --> d0f46640_368d_8e60_2a90_5b5b56eeb69b
  39bbe83a_1571_40c8_90a3_6c0bc7e50d96["anthropic.types.beta.beta_tool_param"]
  b38a2dde_3dd7_54c3_3cd6_31b55c63196d --> 39bbe83a_1571_40c8_90a3_6c0bc7e50d96
  style b38a2dde_3dd7_54c3_3cd6_31b55c63196d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

from typing import Any, cast

import pytest
from pydantic import BaseModel

from anthropic import beta_tool
from anthropic._compat import PYDANTIC_V1
from anthropic.lib.tools._beta_functions import BaseFunctionTool
from anthropic.types.beta.beta_tool_param import InputSchema


@pytest.mark.skipif(PYDANTIC_V1, reason="only applicable in pydantic v2")
class TestFunctionTool:
    def test_basic_function_schema_conversion(self) -> None:
        """Test basic function schema conversion with simple types."""

        def get_weather(location: str, unit: str = "celsius") -> str:
            """Get the weather for a specific location."""
            return f"Weather in {location} is 20 degrees {unit}"

        function_tool = beta_tool(get_weather)

        assert function_tool.name == "get_weather"
        assert function_tool.description == "Get the weather for a specific location."
        assert function_tool.input_schema == {
            "additionalProperties": False,
            "type": "object",
            "properties": {
                "location": {"title": "Location", "type": "string"},
                "unit": {"title": "Unit", "type": "string", "default": "celsius"},
            },
            "required": ["location"],
        }
        assert function_tool(location="CA") == "Weather in CA is 20 degrees celsius"

        # invalid types should be allowed because __call__ should just be the original function
        assert function_tool(location=cast(Any, 1)) == "Weather in 1 is 20 degrees celsius"

    def test_function_with_multiple_types(self) -> None:
        """Test function schema conversion with various Python types."""

        def simple_function(
            name: str,
            age: int,
        ) -> str:
            """A simple function with basic parameter types."""
            return f"Person: {name}, {age} years old"

        function_tool = beta_tool(simple_function)

        # Test that we can create the tool and call it
        assert function_tool.name == "simple_function"
        assert function_tool.description == "A simple function with basic parameter types."

        # Test calling the function
        result = function_tool.call(
            {
                "name": "John",
// ... (388 more lines)

Subdomains

Dependencies

  • anthropic
  • anthropic._compat
  • anthropic.lib.tools._beta_functions
  • anthropic.types.beta.beta_tool_param
  • pydantic
  • pytest
  • typing

Frequently Asked Questions

What does test_functions.py do?
test_functions.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, Authentication subdomain.
What functions are defined in test_functions.py?
test_functions.py defines 1 function(s): _get_parameters_info.
What does test_functions.py depend on?
test_functions.py imports 7 module(s): anthropic, anthropic._compat, anthropic.lib.tools._beta_functions, anthropic.types.beta.beta_tool_param, pydantic, pytest, typing.
Where is test_functions.py in the architecture?
test_functions.py is located at tests/lib/tools/test_functions.py (domain: AnthropicClient, subdomain: Authentication, directory: tests/lib/tools).

Analyze Your Own Codebase

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

Try Supermodel Free