1- import io
21import sys
32from unittest import mock
43
76from strands_agents_builder import strands
87
98
10- @mock .patch . object ( sys , "stdin " )
9+ @mock .patch ( "strands_tools.utils.user_input.get_user_input" , return_value = "y " )
1110@mock .patch .dict ("os.environ" , {"STRANDS_TOOL_CONSOLE_MODE" : "enabled" })
12- def test_interactive_model_create_tool_then_validate (mock_stdin , capsys , tmp_file_structure ):
11+ def test_interactive_model_create_tool_then_validate (mock_get_user_input , capsys , tmp_file_structure ):
1312 """
1413 Test creating a calculator tool via CLI and validating its functionality.
1514 """
1615 with mock .patch .dict ("os.environ" , {"STRANDS_TOOLS_DIR" : str (tmp_file_structure ["tools_dir" ])}):
1716 test_query = "create a tool that can only calculate sum of two number called calculator"
18- mock_stdin .return_value = io .StringIO ("y\n y\n y\n " )
1917
2018 with mock .patch .object (sys , "argv" , ["strands" , test_query ]):
2119 strands .main ()
@@ -33,3 +31,12 @@ def test_interactive_model_create_tool_then_validate(mock_stdin, capsys, tmp_fil
3331 response = agent (question )
3432 response_str = str (response ).lower ()
3533 assert expected in response_str , f"Expected '{ expected } ' in response for '{ question } ', got '{ response_str } '"
34+
35+ # Verify the calculator tool was actually used by checking for toolResults
36+ calculator_used = any (
37+ content .get ("toolUse" , {}).get ("name" ) == "calculator"
38+ for message in agent .messages
39+ for content in message .get ("content" , [])
40+ if content .get ("toolUse" )
41+ )
42+ assert calculator_used , f"Calculator tool should have been used for question: '{ question } '"
0 commit comments