mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 06:15:00 +00:00
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:
parent
1733fe4c90
commit
b9dc419f19
1 changed files with 12 additions and 14 deletions
|
@ -33,22 +33,20 @@ class TestRepo(unittest.TestCase):
|
||||||
# Assert that the returned message is the expected one
|
# Assert that the returned message is the expected one
|
||||||
self.assertEqual(result, "a good commit message")
|
self.assertEqual(result, "a good commit message")
|
||||||
|
|
||||||
def test_get_commit_message_strip_quotes(self):
|
@patch("aider.repo.send_with_retries")
|
||||||
# Mock the IO object
|
def test_get_commit_message_strip_quotes(self, mock_send):
|
||||||
mock_io = MagicMock()
|
# Set the return value of the mocked function
|
||||||
|
mock_response = MagicMock()
|
||||||
# Initialize the Coder object with the mocked IO and mocked repo
|
mock_response.choices = [MagicMock()]
|
||||||
coder = Coder.create(models.GPT4, None, mock_io)
|
mock_response.choices[0].message.content = '"a good commit message"'
|
||||||
|
mock_send.return_value = (
|
||||||
# Mock the send method to set partial_response_content and return False
|
None,
|
||||||
def mock_send(*args, **kwargs):
|
mock_response
|
||||||
coder.partial_response_content = "a good commit message"
|
)
|
||||||
return False
|
|
||||||
|
|
||||||
coder.send = MagicMock(side_effect=mock_send)
|
|
||||||
|
|
||||||
|
repo = AiderRepo(InputOutput(), None)
|
||||||
# Call the get_commit_message method with dummy diff and context
|
# 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
|
# Assert that the returned message is the expected one
|
||||||
self.assertEqual(result, "a good commit message")
|
self.assertEqual(result, "a good commit message")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue