From 1733fe4c90ef615eb9fe4bb38de5bebd822907ef Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 21 Jul 2023 14:29:15 -0300 Subject: [PATCH] aider: To match the return value of `mock_send` with `commit_message = response.choices[0].message.content`, modify the return value of `mock_send` in the `test_get_commit_message` function in the `tests/test_repo.py` file. # Aider chat conversation: USER: in `test_get_commit_message`, the mock_send return value needs to match the commit_message = response.choices[0].message.content ASSISTANT: To match the return value of `mock_send` with `commit_message = response.choices[0].message.content`, we need to modify the return value of `mock_send` in the `test_get_commit_message` function in the `tests/test_repo.py` file. The `send_with_retries` function returns a tuple where the second element is the response from the OpenAI API. The response is expected to be an object with a `choices` attribute, which is a list of objects, each with a `message` attribute, which in turn has a `content` attribute. So, we need to return a mock response object that has these attributes. Here's how to do it: ```python tests/test_repo.py <<<<<<< ORIGINAL mock_send.return_value = ( None, "a good commit message" ) ======= mock_response = MagicMock() mock_response.choices = [MagicMock()] mock_response.choices[0].message.content = "a good commit message" mock_send.return_value = ( None, mock_response ) >>>>>>> UPDATED ``` This change will make the `mock_send` function return a mock response object that has the same structure as the actual response from the OpenAI API, allowing the `get_commit_message` method to correctly extract the commit message. --- tests/test_repo.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_repo.py b/tests/test_repo.py index efa18bf99..0bcda17ee 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -18,9 +18,12 @@ class TestRepo(unittest.TestCase): @patch("aider.repo.send_with_retries") def test_get_commit_message(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, - "a good commit message" + mock_response ) repo = AiderRepo(InputOutput(), None)