refactor: Move test_cmd_load_with_switch_coder to test file

This commit is contained in:
Paul Gauthier 2024-12-30 14:21:28 -04:00 committed by Paul Gauthier (aider)
parent 20bc718bdc
commit 761fb93aba
2 changed files with 30 additions and 30 deletions

View file

@ -1721,3 +1721,33 @@ class TestCommands(TestCase):
del coder
del commands
def test_cmd_load_with_switch_coder(self):
with GitTemporaryDirectory() as repo_dir:
io = InputOutput(pretty=False, fancy_input=False, yes=True)
coder = Coder.create(self.GPT35, None, io)
commands = Commands(io, coder)
# Create a temporary file with commands
commands_file = Path(repo_dir) / "test_commands.txt"
commands_file.write_text("/ask Tell me about the code\n/model gpt-4\n")
# Mock run to raise SwitchCoder for /ask and /model
def mock_run(cmd):
if cmd.startswith(("/ask", "/model")):
raise SwitchCoder()
return None
with mock.patch.object(commands, "run", side_effect=mock_run):
# Capture tool_error output
with mock.patch.object(io, "tool_error") as mock_tool_error:
commands.cmd_load(str(commands_file))
# Check that appropriate error messages were shown
mock_tool_error.assert_any_call(
"Command '/ask Tell me about the code' is only supported in interactive"
" mode, skipping."
)
mock_tool_error.assert_any_call(
"Command '/model gpt-4' is only supported in interactive mode, skipping."
)