From 7d2f184b360ef688b11d453a54c52deff88fafaf Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Wed, 31 Jul 2024 09:50:34 -0300 Subject: [PATCH] feat: add tests for commit_prompt functionality The new test case `test_get_commit_message_with_custom_prompt` ensures that when a custom `commit_prompt` is provided to the `GitRepo` constructor, it's used instead of the default prompt when generating commit messages. The test checks that: 1. The custom commit prompt is passed correctly to the `simple_send_with_retries` function. 2. The returned commit message is as expected. 3. The `simple_send_with_retries` function is called only once (since we're using a single model). This new test case, along with the existing `test_get_commit_message_no_strip_unmatched_quotes` test, provides better coverage for the `get_commit_message` method in the `GitRepo` class. --- tests/basic/test_repo.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/basic/test_repo.py b/tests/basic/test_repo.py index ad727b24b..ded9a2551 100644 --- a/tests/basic/test_repo.py +++ b/tests/basic/test_repo.py @@ -148,6 +148,19 @@ class TestRepo(unittest.TestCase): # Assert that the returned message is the expected one self.assertEqual(result, 'a good "commit message"') + @patch("aider.repo.simple_send_with_retries") + def test_get_commit_message_with_custom_prompt(self, mock_send): + mock_send.return_value = "Custom commit message" + custom_prompt = "Generate a commit message in the style of Shakespeare" + + repo = GitRepo(InputOutput(), None, None, models=[self.GPT35], commit_prompt=custom_prompt) + result = repo.get_commit_message("dummy diff", "dummy context") + + self.assertEqual(result, "Custom commit message") + mock_send.assert_called_once() + _, kwargs = mock_send.call_args + self.assertEqual(kwargs['messages'][0]['content'], custom_prompt) + @patch("aider.repo.GitRepo.get_commit_message") def test_commit_with_custom_committer_name(self, mock_send): mock_send.return_value = '"a good commit message"'