aider/tests
Paul Gauthier 6d22dd06f8 aider: Refactored test_main_with_empty_dir_new_file to use @patch decorator to mock get_commit_message method.
# Aider chat conversation:

USER: @patch("aider.repo.AiderRepo.get_commit_message") is not patching it

ASSISTANT: It seems like you're having trouble with the `@patch` decorator not correctly patching the `get_commit_message` method of the `AiderRepo` class in your tests.

To help you with this, I need to understand the context better. Could you please provide more details about the issue? Are you getting any error messages? If so, could you share them?

USER: in `test_main_with_empty_dir_new_file` i don't want `get_commit_message` to be actually called. just to return a mock value

ASSISTANT: The `@patch` decorator from the `unittest.mock` module is used to replace the actual method with a mock method during testing. If `get_commit_message` is still being called, it might be due to the incorrect import path in the `@patch` decorator.

In your case, the `@patch` decorator should be used as follows:

```python
@patch("aider.repo.AiderRepo.get_commit_message", return_value="commit message!")
```

This will replace the `get_commit_message` method with a mock method that always returns "commit message!".

Here is the updated `test_main_with_empty_dir_new_file` method:

```python
tests/test_main.py
<<<<<<< ORIGINAL
    @patch("aider.repo.AiderRepo.get_commit_message")
    def test_main_with_empty_dir_new_file(self, get_commit_message):
        get_commit_message.return_value = "commit message!"
        main(["foo.txt", "--yes","--no-git"], input=DummyInput(), output=DummyOutput())
        self.assertTrue(os.path.exists("foo.txt"))
=======
    @patch("aider.repo.AiderRepo.get_commit_message", return_value="commit message!")
    def test_main_with_empty_dir_new_file(self, get_commit_message):
        main(["foo.txt", "--yes","--no-git"], input=DummyInput(), output=DummyOutput())
        self.assertTrue(os.path.exists("foo.txt"))
>>>>>>> UPDATED
```

This change should ensure that the actual `get_commit_message` method is not called during the test. Instead, the mock method will be used, returning the specified mock value.
2023-07-21 15:56:27 -03:00
..
__init__.py aider: Added empty __init__.py file to tests directory to fix ModuleNotFoundError when running tests. 2023-05-11 17:12:42 -07:00
test_coder.py Merge branch 'main' into refactor-repo 2023-07-21 15:46:31 -03:00
test_commands.py restore test_cmd_tokens 2023-07-17 16:01:37 -03:00
test_editblock.py added test_replace_part_with_missing_varied_leading_whitespace 2023-07-18 15:13:14 -03:00
test_io.py Fix test 2023-07-10 15:33:46 -07:00
test_main.py aider: Refactored test_main_with_empty_dir_new_file to use @patch decorator to mock get_commit_message method. 2023-07-21 15:56:27 -03:00
test_models.py More Model test cases 2023-06-21 14:13:34 -07:00
test_repo.py Refactor coder.get_tracked_files to coder.repo.get_tracked_files in test_coder.py and add test_get_commit_message_no_strip_unmatched_quotes in test_repo.py. 2023-07-21 14:36:26 -03:00
test_repomap.py aider: Change the relative import to an absolute import for the IgnorantTemporaryDirectory class in test_repomap.py. 2023-07-16 09:05:18 -03:00
test_sendchat.py move tests to test_sendchat.py 2023-07-21 14:17:14 -03:00
test_wholefile.py updated tests 2023-07-11 15:17:00 -07:00
utils.py refac make_repo 2023-07-16 12:25:18 -03:00