11# -*- coding: utf-8 -*-
2- """Tests for the @tool decorator schema synthesis and JSON Schema validation."""
2+ """@tool decorator schema synthesis and JSON Schema validation."""
33
44from typing import List , Optional
55
@@ -42,17 +42,21 @@ def get_weather(city: str, unit: str = "C") -> str:
4242def test_tool_decorator_optional_and_list ():
4343 @tool (name = "search" , description = "Custom desc" )
4444 def _search (q : str , limit : Optional [int ] = None , tags : List [str ] = None ):
45- return []
45+ return [q , limit , tags ]
4646
4747 spec = _search .__tool_spec__
4848 assert spec .name == "search"
4949 assert spec .description == "Custom desc"
5050 props = spec .parameters ["properties" ]
5151 assert props ["q" ] == {"type" : "string" }
52- # Optional[int] -> integer with default=None (API needs to know it's optional)
52+ # Optional[int] -> integer with default=None
5353 assert props ["limit" ] == {"type" : "integer" , "default" : None }
5454 # List[str] -> array of strings
55- assert props ["tags" ] == {"type" : "array" , "items" : {"type" : "string" }, "default" : None }
55+ assert props ["tags" ] == {
56+ "type" : "array" ,
57+ "items" : {"type" : "string" },
58+ "default" : None ,
59+ }
5660 assert spec .parameters ["required" ] == ["q" ]
5761
5862
@@ -63,7 +67,9 @@ def identity(text: str) -> str:
6367 return text
6468
6569 desc = identity .__tool_spec__ .to_descriptor ()
66- assert "type" not in desc , "BMA backend does not accept 'type' field for custom tools"
70+ assert (
71+ "type" not in desc
72+ ), "BMA backend does not accept 'type' field for custom tools"
6773 assert desc ["name" ] == "identity"
6874 assert desc ["input_schema" ]["properties" ]["text" ] == {"type" : "string" }
6975
@@ -91,7 +97,7 @@ def test_default_value_is_emitted_into_schema():
9197 @tool
9298 def search (q : str , limit : int = 10 ) -> str :
9399 """Search the index."""
94- return " "
100+ return f" { q } { limit } "
95101
96102 schema = search .__tool_spec__ .parameters
97103 _validate (schema )
@@ -103,20 +109,22 @@ def test_optional_strips_none_keeps_inner_type():
103109 @tool
104110 def lookup (name : str , hint : Optional [int ] = None ) -> str :
105111 """Look something up."""
106- return " "
112+ return f" { name } { hint } "
107113
108114 schema = lookup .__tool_spec__ .parameters
109115 _validate (schema )
110116 assert schema ["properties" ]["hint" ]["type" ] == "integer"
111- assert schema ["properties" ]["hint" ]["default" ] is None # None default is preserved
117+ assert (
118+ schema ["properties" ]["hint" ]["default" ] is None
119+ ) # None default is preserved
112120 assert "hint" not in schema ["required" ]
113121
114122
115123def test_list_inner_type_is_validated ():
116124 @tool
117125 def tag (names : List [str ]) -> str :
118126 """Tag inputs."""
119- return ""
127+ return str ( names )
120128
121129 schema = tag .__tool_spec__ .parameters
122130 _validate (schema )
@@ -135,14 +143,17 @@ def make_order(item: str, qty: int = 1) -> str:
135143 item: SKU identifier of the product to order.
136144 qty: How many units to request. Defaults to 1.
137145 """
138- return " "
146+ return f" { item } { qty } "
139147
140148 schema = make_order .__tool_spec__ .parameters
141149 _validate (schema )
142150 assert schema ["properties" ]["item" ]["description" ] == (
143151 "SKU identifier of the product to order."
144152 )
145- assert "How many units to request" in schema ["properties" ]["qty" ]["description" ]
153+ assert (
154+ "How many units to request"
155+ in schema ["properties" ]["qty" ]["description" ]
156+ )
146157 # Top-level summary trims the Args section
147158 assert make_order .__tool_spec__ .description == "Place a supply order."
148159
@@ -155,7 +166,7 @@ def fetch(url: str, timeout: float = 5.0) -> str:
155166 :param url: The fully qualified URL to download.
156167 :param timeout: Per-request timeout in seconds.
157168 """
158- return " "
169+ return f" { url } { timeout } "
159170
160171 schema = fetch .__tool_spec__ .parameters
161172 _validate (schema )
@@ -174,7 +185,7 @@ def test_descriptor_round_trip_validates_arguments():
174185 @tool
175186 def ping (host : str , count : int = 1 ) -> str :
176187 """Ping a host."""
177- return " "
188+ return f" { host } { count } "
178189
179190 schema = ping .__tool_spec__ .to_descriptor ()["input_schema" ]
180191 _validate (schema )
0 commit comments