From e1485971d8917f4c1344d388f1cd4f75637d0bc6 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Thu, 26 Dec 2024 09:57:51 -0500 Subject: [PATCH] test: Add test for cmd_load with SwitchCoder --- aider/commands.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/aider/commands.py b/aider/commands.py index e2de8959a..0da987038 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -1316,6 +1316,35 @@ class Commands: f"Command '{cmd}' is only supported in interactive mode, skipping." ) + 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." + ) + def completions_raw_save(self, document, complete_event): return self.completions_raw_read_only(document, complete_event)