@@ -185,3 +185,78 @@ def test_register_strands_tools_specific_tool_from_module():
185185 assert len (tool_registry .registry ) == 1
186186 assert "say" in tool_registry .registry
187187 assert "dont_say" not in tool_registry .registry
188+
189+
190+ def test_register_strands_tools_specific_tool_from_module_tool_missing ():
191+ tool_registry = ToolRegistry ()
192+
193+ with pytest .raises (ValueError , match = "Failed to load tool tests.fixtures.say_tool:nay: " ):
194+ tool_registry .process_tools (["tests.fixtures.say_tool:nay" ])
195+
196+
197+ def test_register_strands_tools_specific_tool_from_module_not_a_tool ():
198+ tool_registry = ToolRegistry ()
199+
200+ with pytest .raises (ValueError , match = "Failed to load tool tests.fixtures.say_tool:not_a_tool: " ):
201+ tool_registry .process_tools (["tests.fixtures.say_tool:not_a_tool" ])
202+
203+
204+ def test_register_strands_tools_with_dict ():
205+ tool_registry = ToolRegistry ()
206+ tool_registry .process_tools ([{"path" : "tests.fixtures.say_tool" }])
207+
208+ assert len (tool_registry .registry ) == 2
209+ assert "say" in tool_registry .registry
210+ assert "dont_say" in tool_registry .registry
211+
212+
213+ def test_register_strands_tools_specific_tool_with_dict ():
214+ tool_registry = ToolRegistry ()
215+ tool_registry .process_tools ([{"path" : "tests.fixtures.say_tool" , "name" : "say" }])
216+
217+ assert len (tool_registry .registry ) == 1
218+ assert "say" in tool_registry .registry
219+
220+
221+ def test_register_strands_tools_specific_tool_with_dict_not_found ():
222+ tool_registry = ToolRegistry ()
223+
224+ with pytest .raises (
225+ ValueError ,
226+ match = "Failed to load tool {'path': 'tests.fixtures.say_tool'"
227+ ", 'name': 'nay'}: Tool \" nay\" not found in \" tests.fixtures.say_tool\" " ,
228+ ):
229+ tool_registry .process_tools ([{"path" : "tests.fixtures.say_tool" , "name" : "nay" }])
230+
231+
232+ def test_register_strands_tools_module_no_spec ():
233+ tool_registry = ToolRegistry ()
234+
235+ with pytest .raises (
236+ ValueError ,
237+ match = "Failed to load tool tests.fixtures.mocked_model_provider: "
238+ "The module mocked_model_provider is not a valid module" ,
239+ ):
240+ tool_registry .process_tools (["tests.fixtures.mocked_model_provider" ])
241+
242+
243+ def test_register_strands_tools_module_no_function ():
244+ tool_registry = ToolRegistry ()
245+
246+ with pytest .raises (
247+ ValueError ,
248+ match = "Failed to load tool tests.fixtures.tool_with_spec_but_no_function: "
249+ "Module-based tool tool_with_spec_but_no_function missing function tool_with_spec_but_no_function" ,
250+ ):
251+ tool_registry .process_tools (["tests.fixtures.tool_with_spec_but_no_function" ])
252+
253+
254+ def test_register_strands_tools_module_non_callable_function ():
255+ tool_registry = ToolRegistry ()
256+
257+ with pytest .raises (
258+ ValueError ,
259+ match = "Failed to load tool tests.fixtures.tool_with_spec_but_non_callable_function:"
260+ " Tool tool_with_spec_but_non_callable_function function is not callable" ,
261+ ):
262+ tool_registry .process_tools (["tests.fixtures.tool_with_spec_but_non_callable_function" ])
0 commit comments