Skip to content

Commit c149f5b

Browse files
committed
fix: make tests more accurate
1 parent b0c5f7e commit c149f5b

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

tests_integ/test_build_agent_from_specifications.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""Test building agent from specification file using semantic creation."""
2-
31
import sys
42
from unittest import mock
53

@@ -8,20 +6,17 @@
86
from strands_agents_builder import strands
97

108

11-
def test_build_agent_from_specification_file(tmp_path):
12-
"""Test building agent from agent-spec.txt using semantic creation."""
9+
def test_build_agent_from_specification_file():
10+
"""Test building agent from specification using semantic creation."""
1311

14-
# Create agent specification file
12+
# Agent specification content
1513
spec_content = """Agent Specification:
1614
- Role: Math Tutor Agent
1715
- Purpose: Help students with basic arithmetic and algebra
1816
- Tools needed: calculator, file_read, current_time
1917
- Create specialized tools for math tutoring
2018
"""
2119

22-
spec_file = tmp_path / "agent-spec.txt"
23-
spec_file.write_text(spec_content)
24-
2520
# Simulate: cat agent-spec.txt | strands "Build a specialized agent based on these specifications"
2621
query = f"Build a specialized agent based on these specifications:\n\n{spec_content}"
2722

tests_integ/test_custom_load_from_file.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ def reverse_text(text: str) -> dict:
2828
strands.main()
2929

3030
out = capsys.readouterr().out
31+
assert (
32+
"The reverse_text tool worked as expected"
33+
or "The reverse_text tool worked"
34+
or ("reverse_text tool" and "The tool successfully reversed") in out
35+
), f"Expected 'olleh' in output, but got:\n{out}"
3136
assert "olleh" in out, f"Expected 'olleh' in output, but got:\n{out}"

tests_integ/test_sementic_create_tool.py renamed to tests_integ/test_semantic_create_tool.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import io
21
import sys
32
from unittest import mock
43

@@ -7,15 +6,14 @@
76
from 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\ny\ny\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

Comments
 (0)