Refactor test_get_commit_message_strip_quotes to use a mocked send_with_retries function and set the return value of the mocked function.

This commit is contained in:
Paul Gauthier 2023-07-21 14:30:33 -03:00
parent 1733fe4c90
commit b9dc419f19

View file

@ -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")