From b9dc419f1974b6ac4b02e5ee88e2a36ac1bdf09b Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 21 Jul 2023 14:30:33 -0300 Subject: [PATCH] Refactor test_get_commit_message_strip_quotes to use a mocked send_with_retries function and set the return value of the mocked function. --- tests/test_repo.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/test_repo.py b/tests/test_repo.py index 0bcda17ee..5cacd9a1b 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -33,22 +33,20 @@ class TestRepo(unittest.TestCase): # Assert that the returned message is the expected one self.assertEqual(result, "a good commit message") - def test_get_commit_message_strip_quotes(self): - # Mock the IO object - mock_io = MagicMock() - - # Initialize the Coder object with the mocked IO and mocked repo - coder = Coder.create(models.GPT4, None, mock_io) - - # Mock the send method to set partial_response_content and return False - def mock_send(*args, **kwargs): - coder.partial_response_content = "a good commit message" - return False - - coder.send = MagicMock(side_effect=mock_send) + @patch("aider.repo.send_with_retries") + def test_get_commit_message_strip_quotes(self, mock_send): + # Set the return value of the mocked function + mock_response = MagicMock() + mock_response.choices = [MagicMock()] + mock_response.choices[0].message.content = '"a good commit message"' + mock_send.return_value = ( + None, + mock_response + ) + repo = AiderRepo(InputOutput(), None) # Call the get_commit_message method with dummy diff and context - result = coder.get_commit_message("dummy diff", "dummy context") + result = repo.get_commit_message("dummy diff", "dummy context") # Assert that the returned message is the expected one self.assertEqual(result, "a good commit message")