diff --git a/tests/basic/test_scripting.py b/tests/basic/test_scripting.py index b2873a15c..99bca326e 100644 --- a/tests/basic/test_scripting.py +++ b/tests/basic/test_scripting.py @@ -7,34 +7,30 @@ from aider.models import Model class TestScriptingAPI(unittest.TestCase): - @patch("aider.coders.Coder.create") - @patch("aider.models.Model") - def test_basic_scripting(self, mock_model, mock_coder_create): + @patch("aider.coders.base_coder.Coder.send") + def test_basic_scripting(self, mock_send): # Setup - mock_coder = MagicMock() - mock_coder_create.return_value = mock_coder + mock_send.return_value = "Changes applied successfully." # Test script fnames = ["greeting.py"] model = Model("gpt-4-turbo") coder = Coder.create(main_model=model, fnames=fnames) - coder.run("make a script that prints hello world") - coder.run("make it say goodbye") + result1 = coder.run("make a script that prints hello world") + result2 = coder.run("make it say goodbye") # Assertions - mock_model.assert_called_once_with("gpt-4-turbo") - mock_coder_create.assert_called_once_with(main_model=model, fnames=fnames) - self.assertEqual(mock_coder.run.call_count, 2) - mock_coder.run.assert_any_call("make a script that prints hello world") - mock_coder.run.assert_any_call("make it say goodbye") + self.assertEqual(mock_send.call_count, 2) + mock_send.assert_any_call([{'role': 'user', 'content': 'make a script that prints hello world'}]) + mock_send.assert_any_call([{'role': 'user', 'content': 'make it say goodbye'}]) + self.assertEqual(result1, "Changes applied successfully.") + self.assertEqual(result2, "Changes applied successfully.") - @patch("aider.coders.Coder.create") - @patch("aider.models.Model") - def test_scripting_with_io(self, mock_model, mock_coder_create): + @patch("aider.coders.base_coder.Coder.send") + def test_scripting_with_io(self, mock_send): # Setup - mock_coder = MagicMock() - mock_coder_create.return_value = mock_coder + mock_send.return_value = "New function added successfully." # Test script fnames = ["greeting.py"] @@ -42,12 +38,11 @@ class TestScriptingAPI(unittest.TestCase): io = InputOutput(yes=True) coder = Coder.create(main_model=model, fnames=fnames, io=io) - coder.run("add a new function") + result = coder.run("add a new function") # Assertions - mock_model.assert_called_once_with("gpt-4-turbo") - mock_coder_create.assert_called_once_with(main_model=model, fnames=fnames, io=io) - mock_coder.run.assert_called_once_with("add a new function") + mock_send.assert_called_once_with([{'role': 'user', 'content': 'add a new function'}]) + self.assertEqual(result, "New function added successfully.") self.assertTrue(io.yes) # Check that 'yes' is set to True