TestFunctionTool Class — anthropic-sdk-python Architecture
Architecture documentation for the TestFunctionTool class in test_functions.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD e25ad18d_e1f6_726f_20bc_ac8e568d4e63["TestFunctionTool"] 17ce5647_6f06_0676_a4a5_e378a3f57cb1["BaseModel"] e25ad18d_e1f6_726f_20bc_ac8e568d4e63 -->|extends| 17ce5647_6f06_0676_a4a5_e378a3f57cb1 b38a2dde_3dd7_54c3_3cd6_31b55c63196d["test_functions.py"] e25ad18d_e1f6_726f_20bc_ac8e568d4e63 -->|defined in| b38a2dde_3dd7_54c3_3cd6_31b55c63196d 70d32c37_63f2_d6f3_31a1_1c2453475a94["test_basic_function_schema_conversion()"] e25ad18d_e1f6_726f_20bc_ac8e568d4e63 -->|method| 70d32c37_63f2_d6f3_31a1_1c2453475a94 79568418_e545_f515_f59d_aefa1dd99dce["test_function_with_multiple_types()"] e25ad18d_e1f6_726f_20bc_ac8e568d4e63 -->|method| 79568418_e545_f515_f59d_aefa1dd99dce 94b92ceb_b67a_7402_e749_18efb705c6c1["test_function_call_with_valid_input()"] e25ad18d_e1f6_726f_20bc_ac8e568d4e63 -->|method| 94b92ceb_b67a_7402_e749_18efb705c6c1 2994cf62_fcc7_d475_3de4_12161fde117b["test_function_call_with_invalid_input()"] e25ad18d_e1f6_726f_20bc_ac8e568d4e63 -->|method| 2994cf62_fcc7_d475_3de4_12161fde117b 33532873_f2e1_1b69_0244_a9f6bbf86523["test_custom_name_and_description()"] e25ad18d_e1f6_726f_20bc_ac8e568d4e63 -->|method| 33532873_f2e1_1b69_0244_a9f6bbf86523 9b345a3e_c441_0f79_0277_fe5d018f05fa["test_custom_input_schema_with_dict()"] e25ad18d_e1f6_726f_20bc_ac8e568d4e63 -->|method| 9b345a3e_c441_0f79_0277_fe5d018f05fa 1584a239_00ff_c896_678f_5dca6422b821["test_custom_input_schema_with_pydantic_model()"] e25ad18d_e1f6_726f_20bc_ac8e568d4e63 -->|method| 1584a239_00ff_c896_678f_5dca6422b821 4a5886f3_6b04_5880_4c1c_79c3f5d6f9d9["test_to_dict_method()"] e25ad18d_e1f6_726f_20bc_ac8e568d4e63 -->|method| 4a5886f3_6b04_5880_4c1c_79c3f5d6f9d9 1d0ed91f_63d4_47ac_4893_0da29bc7ab57["test_function_without_docstring()"] e25ad18d_e1f6_726f_20bc_ac8e568d4e63 -->|method| 1d0ed91f_63d4_47ac_4893_0da29bc7ab57 43d49828_de5f_6bd4_c39d_4a1d26cc2873["test_function_without_type_hints()"] e25ad18d_e1f6_726f_20bc_ac8e568d4e63 -->|method| 43d49828_de5f_6bd4_c39d_4a1d26cc2873 0d9ba713_c268_e925_976b_46c715c78ca5["test_docstring_parsing_with_parameters()"] e25ad18d_e1f6_726f_20bc_ac8e568d4e63 -->|method| 0d9ba713_c268_e925_976b_46c715c78ca5 55770029_1e35_bc6d_aa2c_f030dc29fb14["test_decorator_without_parentheses()"] e25ad18d_e1f6_726f_20bc_ac8e568d4e63 -->|method| 55770029_1e35_bc6d_aa2c_f030dc29fb14
Relationship Graph
Source Code
tests/lib/tools/test_functions.py lines 15–439
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",
"age": 25,
}
)
assert result == "Person: John, 25 years old"
# Test schema structure
expected_schema = {
"additionalProperties": False,
"type": "object",
"properties": {
"name": {"title": "Name", "type": "string"},
"age": {"title": "Age", "type": "integer"},
},
"required": ["name", "age"],
}
assert function_tool.input_schema == expected_schema
def test_function_call_with_valid_input(self) -> None:
def add_numbers(a: int, b: int) -> str:
"""Add two numbers together."""
return str(a + b)
function_tool = beta_tool(add_numbers)
result = function_tool.call({"a": 5, "b": 3})
assert result == "8"
@pytest.mark.parametrize(
"input_data, expected_error_type, expected_error_msg",
[
pytest.param(
{"a": "not a number", "b": 3},
ValueError,
"Invalid arguments for function add_numbers",
Defined In
Extends
Source
Frequently Asked Questions
What is the TestFunctionTool class?
TestFunctionTool is a class in the anthropic-sdk-python codebase, defined in tests/lib/tools/test_functions.py.
Where is TestFunctionTool defined?
TestFunctionTool is defined in tests/lib/tools/test_functions.py at line 15.
What does TestFunctionTool extend?
TestFunctionTool extends BaseModel.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free