Skip to content

Commit f4ed508

Browse files
committed
test: fix Windows compatibility for file prefix test
- Use platform-specific tempfile handling in test_agent_config_file_prefix_valid - Use mkstemp() with explicit cleanup on Windows for better permission handling - Keep NamedTemporaryFile on non-Windows platforms for simplicity - Should resolve permission errors on Windows GitHub runners 🤖 Assisted by Amazon Q Developer
1 parent 280f85a commit f4ed508

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

tests/strands/experimental/test_agent_config.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,34 @@ def test_agent_config_file_prefix_required(self):
6060
def test_agent_config_file_prefix_valid(self):
6161
"""Test that file:// prefix is properly handled."""
6262
import json
63+
import os
64+
import platform
6365
import tempfile
6466

6567
# Create a temporary config file
6668
config_data = {"model": "test-model", "prompt": "Test prompt"}
67-
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=True) as f:
68-
json.dump(config_data, f)
69-
f.flush() # Ensure data is written to disk
70-
71-
config = AgentConfig(f"file://{f.name}", tool_registry=ToolRegistry())
72-
assert config.model == "test-model"
73-
assert config.system_prompt == "Test prompt"
69+
70+
if platform.system() == "Windows":
71+
# Use mkstemp approach on Windows for better permission handling
72+
fd, temp_path = tempfile.mkstemp(suffix=".json")
73+
try:
74+
with os.fdopen(fd, 'w') as f:
75+
json.dump(config_data, f)
76+
77+
config = AgentConfig(f"file://{temp_path}", tool_registry=ToolRegistry())
78+
assert config.model == "test-model"
79+
assert config.system_prompt == "Test prompt"
80+
finally:
81+
os.unlink(temp_path)
82+
else:
83+
# Use NamedTemporaryFile on non-Windows platforms
84+
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=True) as f:
85+
json.dump(config_data, f)
86+
f.flush() # Ensure data is written to disk
87+
88+
config = AgentConfig(f"file://{f.name}", tool_registry=ToolRegistry())
89+
assert config.model == "test-model"
90+
assert config.system_prompt == "Test prompt"
7491

7592
@patch("strands.agent.agent.Agent")
7693
def test_to_agent_calls_agent_constructor(self, mock_agent):

0 commit comments

Comments
 (0)