Commit graph

62 commits

Author SHA1 Message Date
Paul Gauthier
92cd2f3ce6 isort 2023-05-28 22:47:38 -07:00
Paul Gauthier
bd78789bd2 Fixed quote stripping of gpt3.5 commit messages 2023-05-27 17:05:57 -07:00
Paul Gauthier
3d8ecddb3f aider: Added a test method to check if get_commit_message returns the expected message when send method is mocked.
# Context:
USER: add a test for get_commit_message that passes in a dummy diff and context string. mock coder.send to return "a good commit message",False. assert that is the message returned by get_commit_message
ASSISTANT: I will add a new test method called `test_get_commit_message` in the `tests/test_coder.py` file.

```python
tests/test_coder.py
<<<<<<< ORIGINAL

if __name__ == "__main__":
    unittest.main()
=======
    def test_get_commit_message(self):
        # Mock the IO object
        mock_io = MagicMock()

        # Initialize the Coder object with the mocked IO and mocked repo
        coder = Coder(io=mock_io, openai_api_key="fake_key")

        # Mock the send method to return a tuple with a message and False
        coder.send = MagicMock(return_value=("a good commit message", False))

        # Call the get_commit_message method with dummy diff and context
        result = coder.get_commit_message("dummy diff", "dummy context")

        # Assert that the returned message is the expected one
        self.assertEqual(result, "a good commit message")

if __name__ == "__main__":
    unittest.main()
>>>>>>> UPDATED
```

This new test method mocks the `send` method of the `Coder` object to return a predefined commit message and checks if the `get_commit_message` method returns the expected message.
2023-05-27 17:03:27 -07:00
Paul Gauthier
4fd1bf7f21 Added test_check_for_ambiguous_filename_mentions_of_longer_paths 2023-05-27 08:39:18 -07:00
Paul Gauthier
3732f62a9c Use ./ paths for the test 2023-05-27 08:32:39 -07:00
Paul Gauthier
c8cf78b5cf Added a new test to check for filename mentions of longer paths. 2023-05-27 08:30:17 -07:00
Paul Gauthier
7e75cfb1fa added missing import 2023-05-27 08:29:05 -07:00
Paul Gauthier
bcf258f1c6 aider: Modified test to check if coder.abs_fnames contains both files.
# Context:
USER: don't compare the result string. check that coder.abs_fnames now contains both files
ASSISTANT: To update the test to check if `coder.abs_fnames` contains both files, modify the test as follows:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
        # Check if the result is as expected
        self.assertEqual(result, "Added files: file1.txt, file2.py")
=======
        # Check if coder.abs_fnames contains both files
        expected_files = {os.path.abspath("file1.txt"), os.path.abspath("file2.py")}
        self.assertEqual(coder.abs_fnames, expected_files)
>>>>>>> UPDATED
```

This change will ensure that the test checks if `coder.abs_fnames` contains both files instead of comparing the result string.
2023-05-27 08:28:31 -07:00
Paul Gauthier
4ac2143cc2 Initialized Coder object with mocked IO and mocked repo, and updated coder.repo instead of coder.root. 2023-05-27 08:27:45 -07:00
Paul Gauthier
0fc40df8e6 aider: Replaced manual setting of abs_fnames with a mocked git.Repo object that has its ls_files method return the desired file paths.
# Context:
USER: don't set the files in abs_fnames. patch self.repo.git.ls_files to return them
ASSISTANT: To patch `self.repo.git.ls_files` to return the files in `abs_fnames`, we will modify the `test_check_for_file_mentions` function in the `tests/test_coder.py` file.

```python
tests/test_coder.py
<<<<<<< ORIGINAL
        # Initialize the Coder object with the mocked IO
        coder = Coder(io=mock_io, openai_api_key="fake_key")

        # Add sample files to the Coder object
        coder.abs_fnames = {
            "/path/to/repo/file1.txt",
            "/path/to/repo/file2.py",
        }
        coder.root = "/path/to/repo"
=======
        # Mock the git repo
        mock_repo = MagicMock()
        mock_repo.git.ls_files.return_value = "file1.txt\nfile2.py"

        # Initialize the Coder object with the mocked IO and mocked repo
        coder = Coder(io=mock_io, openai_api_key="fake_key", repo=mock_repo)
        coder.root = "/path/to/repo"
>>>>>>> UPDATED
```

This change replaces the manual setting of `abs_fnames` with a mocked `git.Repo` object that has its `ls_files` method return the desired file paths.
2023-05-27 08:26:16 -07:00
Paul Gauthier
475f85bcc3 aider: Added a test function for the check_for_file_mentions method in tests/test_coder.py.
# Context:
USER: write a test for check_for_file_mentions
ASSISTANT: To write a test for the `check_for_file_mentions` method, we will create a new test function in the `tests/test_coder.py` file. Here's the test function:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
=======
import unittest
from unittest.mock import MagicMock
from aider.coder import Coder

class TestCoder(unittest.TestCase):
    def test_check_for_file_mentions(self):
        # Mock the IO object
        mock_io = MagicMock()
        mock_io.get_input.return_value = "Please check file1.txt and file2.py"
        mock_io.confirm_ask.return_value = True

        # Initialize the Coder object with the mocked IO
        coder = Coder(io=mock_io, openai_api_key="fake_key")

        # Add sample files to the Coder object
        coder.abs_fnames = {
            "/path/to/repo/file1.txt",
            "/path/to/repo/file2.py",
        }
        coder.root = "/path/to/repo"

        # Call the check_for_file_mentions method
        result = coder.check_for_file_mentions("Please check file1.txt and file2.py")

        # Check if the result is as expected
        self.assertEqual(result, "Added files: file1.txt, file2.py")

if __name__ == "__main__":
    unittest.main()
>>>>>>> UPDATED
```

This test function creates a `Coder` object with a mocked IO, adds sample files to the object, and then calls the `check_for_file_mentions` method with a sample input. It checks if the returned result is as expected.
2023-05-27 08:23:51 -07:00
Paul Gauthier
dd3bdfbe15 Added new files to the git repo: tests/test_coder.py 2023-05-27 08:22:37 -07:00