Commit graph

83 commits

Author SHA1 Message Date
Paul Gauthier
bf6cd8294e handle submodules (or other dirs) which are git tracked #336 2023-11-15 13:34:29 -08:00
Paul Gauthier
277a92b3c6 fixed tests 2023-10-25 15:30:33 -07:00
Paul Gauthier
7929e825e7 fixed test 2023-10-19 15:27:51 -07:00
Paul Gauthier
ae8d04a95f Handle diff of file not yet part of repo 2023-08-18 13:20:27 -07:00
Paul Gauthier
2737cbde06 ssh 2023-08-18 10:35:42 -07:00
Paul Gauthier
7af82ba185 keep track of the files which need dirty commits 2023-08-18 09:50:18 -07:00
Paul Gauthier
752e47a886 better tests, small cleanups 2023-08-18 09:43:40 -07:00
Paul Gauthier
95fb55b9d9 test_gpt_edit_to_dirty_file 2023-08-18 09:17:07 -07:00
Paul Gauthier
93795c085a make sure newly created files don't just get committed 2023-08-18 08:01:14 -07:00
Paul Gauthier
83f084a800 aider: Added assertion to check if repo.iter_commits(repo.active_branch.name) raises git.exc.GitCommandError.
# Aider chat conversation:

ASSISTANT: I understand that you want to complete the TODO task in the `test_new_file_edit_one_commit` method in the `tests/test_coder.py` file. However, the task is not clear. The TODO comment says:

```python
### TODO: assert that the next line raises git.exc.GitCommandError
```

This suggests that the following line of code should raise a `git.exc.GitCommandError` exception:

```python
repo.iter_commits(repo.active_branch.name)
```

To complete this task, we need to add a test assertion that checks if this line of code raises the `git.exc.GitCommandError` exception. We can use the `assertRaises` method from the `unittest.TestCase` class to do this.

Here is the change that needs to be made:

<source>python
tests/test_coder.py
<<<<<<< HEAD
            ### TODO: assert that the next line raises git.exc.GitCommandError
            repo.iter_commits(repo.active_branch.name)
=======
            with self.assertRaises(git.exc.GitCommandError):
                repo.iter_commits(repo.active_branch.name)
>>>>>>> updated
</source>

This change will add an assertion that checks if the `repo.iter_commits(repo.active_branch.name)` line of code raises a `git.exc.GitCommandError` exception. If the line of code does not raise this exception, the test will fail.
2023-08-18 08:00:04 -07:00
Paul Gauthier
f722394db6 Assert that the file exists before iterating through commits. 2023-08-18 08:00:03 -07:00
Paul Gauthier
d09e85adc2 Also ensure commit msg only depends on diffs from the GPT edited file. 2023-08-18 07:55:42 -07:00
Paul Gauthier
b7cb006958 test_only_commit_gpt_edited_file 2023-08-18 07:52:25 -07:00
Paul Gauthier
1460cd0055 test_new_file_edit_one_commit 2023-08-18 07:46:39 -07:00
Paul Gauthier
14d19e22b2 improved tests 2023-08-17 11:28:43 -07:00
Paul Gauthier
17c275b987 improved tests 2023-08-17 11:23:45 -07:00
Paul Gauthier
6c2923ff70 remove test for should_dirty_commit 2023-08-17 10:43:12 -07:00
Paul Gauthier
fed24aa444 lint 2023-08-10 16:53:34 -03:00
Paul Gauthier
20c7eb549c aider: Mocked get_commit_message to return "I added str(fname)".
# Aider chat conversation:

USER: mock `get_commit_message` to return "I added str(fname)"

ASSISTANT: To mock the `get_commit_message` method to return "I added str(fname)", we need to modify the `test_new_file_commit_message` function in the `tests/test_coder.py` file.

Here is the change needed:

<source>python
tests/test_coder.py
<<<<<<< ORIGINAL
            # Get the latest commit message
            commit_message = repo.head.commit.message
            # Check that the latest commit message contains the filename
            self.assertIn(str(fname), commit_message)
=======
            # Mock the get_commit_message method to return "I added str(fname)"
            repo.get_commit_message = MagicMock(return_value=f"I added {str(fname)}")
            # Get the latest commit message
            commit_message = repo.get_commit_message()
            # Check that the latest commit message is "I added str(fname)"
            self.assertEqual(commit_message, f"I added {str(fname)}")
>>>>>>> UPDATED
</source>
2023-08-08 08:01:15 -03:00
Paul Gauthier
737c2e0b5f aider: Check that the latest commit message contains the filename.
# Aider chat conversation:

USER: do the todo

ASSISTANT: To complete the TODO task in the `test_new_file_commit_message` function, we need to check that the latest commit message contains the filename. We can do this by getting the latest commit message from the git repository and checking if the filename is in it.

Here is the change needed in the `tests/test_coder.py` file:

<source>python
tests/test_coder.py
<<<<<<< ORIGINAL
            # TODO: check that the latest commit message contains str(fname)
=======
            # Get the latest commit message
            commit_message = repo.head.commit.message
            # Check that the latest commit message contains the filename
            self.assertIn(str(fname), commit_message)
>>>>>>> UPDATED
</source>
2023-08-08 07:59:57 -03:00
Paul Gauthier
832259b55b Bugfix reference to self.get_tracked_files, plus test coverage 2023-07-27 06:55:06 -03:00
Paul Gauthier
e2a32fec7e linting 2023-07-21 16:08:50 -03:00
Paul Gauthier
e74bfc21d0 Merge branch 'main' into refactor-repo 2023-07-21 15:46:31 -03:00
Paul Gauthier
dfd92073f4 Handle files in the git repo which have been deleted but not committed, with test 2023-07-21 15:41:57 -03:00
Paul Gauthier
1fcb090ff6 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
Paul Gauthier
ebd8d9725b wip 2023-07-21 14:24:19 -03:00
Paul Gauthier
28578217da move tests to test_sendchat.py 2023-07-21 14:17:14 -03:00
Paul Gauthier
5dc7bc055e Whitelist more /cmds for no dirty commit 2023-07-16 13:42:36 -03:00
Paul Gauthier
a9cca05680 Added GitTemporaryDirectory 2023-07-16 09:39:07 -03:00
Paul Gauthier
e6996da018 fix tests for windows 2023-07-14 20:28:33 -07:00
Paul Gauthier
78d9d014f2 fix bug blocking addition of subdir filename mentions 2023-07-14 20:00:04 -07:00
Paul Gauthier
16a21d9844 added failing test for mention 2023-07-14 19:53:49 -07:00
Paul Gauthier
2190435780 updated tests 2023-07-11 15:15:26 -07:00
Paul Gauthier
3e3694b38a aider: Set the git user name and email in the get_tracked_files test.
# Aider chat conversation:

USER: set the git user name and email in the `get_tracked_files` test

ASSISTANT: To set the git user name and email in the `get_tracked_files` test, we need to modify the `tests/test_coder.py` file. We will add two lines of code to set the git user name and email after initializing the git repository.

Here is the change:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
        # Initialize a git repository in the temporary directory
        repo = git.Repo.init(tempdir)
=======
        # Initialize a git repository in the temporary directory and set user name and email
        repo = git.Repo.init(tempdir)
        repo.config_writer().set_value("user", "name", "Test User").release()
        repo.config_writer().set_value("user", "email", "testuser@example.com").release()
>>>>>>> UPDATED
```

This change sets the git user name to "Test User" and the email to "testuser@example.com".
2023-07-11 09:20:50 -07:00
Paul Gauthier
8d5f17898a test subdirs too 2023-07-11 09:17:55 -07:00
Paul Gauthier
cccd0d1ebe Make the tests run on windows; added test for files with quotes 2023-07-11 09:15:21 -07:00
Paul Gauthier
68c26a60ef get tracked files by traversing the tree 2023-07-11 09:08:37 -07:00
Paul Gauthier
59a54f5f83 fix Coder.create 2023-07-11 08:21:16 -07:00
Paul Gauthier
cb5d2450ec aider: Ensure parent directory exists before creating file in test_get_tracked_files.
# Aider chat conversation:

USER: I ran this command:

 pytest -k test_get_tracked_files -s

And got this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/gauthier/Projects/aider
configfile: pytest.ini
collected 61 items / 60 deselected / 1 selected

tests/test_coder.py F

=================================== FAILURES ===================================
_______________________ TestCoder.test_get_tracked_files _______________________

self = <tests.test_coder.TestCoder testMethod=test_get_tracked_files>

    def test_get_tracked_files(self):
        # Create a temporary directory
        tempdir = Path(tempfile.mkdtemp())

        # Initialize a git repository in the temporary directory
        repo = git.Repo.init(tempdir)

        # Create three empty files and add them to the git repository
        filenames = ["README.md", "doc/fänny_dirname/README.md", "doc/systemüberblick.md"]
        for filename in filenames:
>           (tempdir / filename).touch()

tests/test_coder.py:374:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = PosixPath('/var/folders/49/kxrdwwbx0h9bchx99397477c0000gn/T/tmpoowegb9x/doc/fänny_dirname/README.md')
mode = 438, exist_ok = True

    def touch(self, mode=0o666, exist_ok=True):
        """
        Create this file with the given access mode, if it doesn't exist.
        """

        if exist_ok:
            # First try to bump modification time
            # Implementation note: GNU touch uses the UTIME_NOW option of
            # the utimensat() / futimens() functions.
            try:
                os.utime(self, None)
            except OSError:
                # Avoid exception chaining
                pass
            else:
                return
        flags = os.O_CREAT | os.O_WRONLY
        if not exist_ok:
            flags |= os.O_EXCL
>       fd = os.open(self, flags, mode)
E       FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/49/kxrdwwbx0h9bchx99397477c0000gn/T/tmpoowegb9x/doc/fänny_dirname/README.md'

/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pathlib.py:1108: FileNotFoundError
=========================== short test summary info ============================
FAILED tests/test_coder.py::TestCoder::test_get_tracked_files - FileNotFoundE...
======================= 1 failed, 60 deselected in 1.53s =======================

ASSISTANT: The error message indicates that the directory `doc/fänny_dirname` does not exist when the test tries to create the file `README.md` inside it.

We need to ensure that the directory exists before creating the file. We can use the `mkdir` method of `Path` with the `parents=True` argument to create the directory and all its missing parents.

Here is the updated code:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
    def test_get_tracked_files(self):
        # Create a temporary directory
        tempdir = Path(tempfile.mkdtemp())

        # Initialize a git repository in the temporary directory
        repo = git.Repo.init(tempdir)

        # Create three empty files and add them to the git repository
        filenames = ["README.md", "doc/fänny_dirname/README.md", "doc/systemüberblick.md"]
        for filename in filenames:
            (tempdir / filename).touch()
            repo.git.add(filename)

        # Create a Coder object on the temporary directory
        coder = Coder.create(
            models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", root=tempdir
        )

        # Assert that coder.get_tracked_files() returns the three filenames
        self.assertEqual(set(coder.get_tracked_files()), set(filenames))
=======
    def test_get_tracked_files(self):
        # Create a temporary directory
        tempdir = Path(tempfile.mkdtemp())

        # Initialize a git repository in the temporary directory
        repo = git.Repo.init(tempdir)

        # Create three empty files and add them to the git repository
        filenames = ["README.md", "doc/fänny_dirname/README.md", "doc/systemüberblick.md"]
        for filename in filenames:
            file_path = tempdir / filename
            file_path.parent.mkdir(parents=True, exist_ok=True)
            file_path.touch()
            repo.git.add(str(file_path))

        # Create a Coder object on the temporary directory
        coder = Coder.create(
            models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", root=tempdir
        )

        # Assert that coder.get_tracked_files() returns the three filenames
        self.assertEqual(set(coder.get_tracked_files()), set(filenames))
>>>>>>> UPDATED
```

This code creates the parent directory of each file before creating the file. It also converts the `Path` object to a string before passing it to `repo.git.add`, because the `git` library may not accept `Path` objects.
2023-07-11 08:20:22 -07:00
Paul Gauthier
db8fb97a38 added import 2023-07-11 08:19:24 -07:00
Paul Gauthier
f1b61d49e9 aider: Added a test that creates a temporary directory, initializes a git repository there, adds three empty files, creates a Coder object on that directory, and asserts that coder.get_tracked_files() returns the three filenames.
# Aider chat conversation:

USER: make a test which creates a tempdir and inits a git repo there. it should add 3 empty files with the filenames below. the test should create a Coder on that and make sure that coder.get_tracked_files() returns the 3 filenames. Here are the filenames: README.md
doc/fänny_dirname/README.md
doc/systemüberblick.md

ASSISTANT: To create this test, we need to modify the `tests/test_coder.py` file. We will add a new test method named `test_get_tracked_files` in the `TestCoder` class. This method will create a temporary directory, initialize a git repository there, add three empty files, create a `Coder` object on that directory, and assert that `coder.get_tracked_files()` returns the three filenames.

Here is the code change:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
    if __name__ == "__main__":
        unittest.main()
=======
    def test_get_tracked_files(self):
        # Create a temporary directory
        tempdir = Path(tempfile.mkdtemp())

        # Initialize a git repository in the temporary directory
        repo = git.Repo.init(tempdir)

        # Create three empty files and add them to the git repository
        filenames = ["README.md", "doc/fänny_dirname/README.md", "doc/systemüberblick.md"]
        for filename in filenames:
            (tempdir / filename).touch()
            repo.git.add(filename)

        # Create a Coder object on the temporary directory
        coder = Coder.create(models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", root=tempdir)

        # Assert that coder.get_tracked_files() returns the three filenames
        self.assertEqual(set(coder.get_tracked_files()), set(filenames))

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

This code assumes that the `Coder` class has a `get_tracked_files` method that returns the filenames of the tracked files in the git repository. If such a method does not exist, it should be implemented in the `Coder` class.
2023-07-11 08:18:39 -07:00
Paul Gauthier
2f4e20658d fix the test to mock git.execute not git.ls_files 2023-07-11 08:14:01 -07:00
Paul Gauthier
3040409590 aider: The test is modified to include the missing param argument when raising InvalidRequestError.
# Aider chat conversation:

USER: I ran this command:

 pytest tests/test_coder.py -k test_run_with_invalid_request_error

And got this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/gauthier/Projects/aider
configfile: pytest.ini
collected 14 items / 13 deselected / 1 selected

tests/test_coder.py F                                                    [100%]

=================================== FAILURES ===================================
________________ TestCoder.test_run_with_invalid_request_error _________________

self = <tests.test_coder.TestCoder testMethod=test_run_with_invalid_request_error>
mock_chat_completion_create = <MagicMock name='create' id='4934396624'>

    @patch("aider.coders.base_coder.openai.ChatCompletion.create")
    def test_run_with_invalid_request_error(self, mock_chat_completion_create):
        # 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, openai_api_key="fake_key")

        # Set up the mock to raise InvalidRequestError
>       mock_chat_completion_create.side_effect = openai.error.InvalidRequestError("Invalid request")
E       TypeError: InvalidRequestError.__init__() missing 1 required positional argument: 'param'

tests/test_coder.py:355: TypeError
=========================== short test summary info ============================
FAILED tests/test_coder.py::TestCoder::test_run_with_invalid_request_error - ...
======================= 1 failed, 13 deselected in 1.04s =======================

ASSISTANT: The `openai.error.InvalidRequestError` requires two positional arguments: `message` and `param`. The `param` argument is used to specify the parameter that caused the invalid request.

Let's modify the test to include a `param` when raising the `InvalidRequestError`.

Here is the change:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
    @patch("aider.coders.base_coder.openai.ChatCompletion.create")
    def test_run_with_invalid_request_error(self, mock_chat_completion_create):
        # 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, openai_api_key="fake_key")

        # Set up the mock to raise InvalidRequestError
        mock_chat_completion_create.side_effect = openai.error.InvalidRequestError("Invalid request")

        # Call the run method and assert that InvalidRequestError is raised
        with self.assertRaises(openai.error.InvalidRequestError):
            coder.run(with_message="hi")
=======
    @patch("aider.coders.base_coder.openai.ChatCompletion.create")
    def test_run_with_invalid_request_error(self, mock_chat_completion_create):
        # 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, openai_api_key="fake_key")

        # Set up the mock to raise InvalidRequestError
        mock_chat_completion_create.side_effect = openai.error.InvalidRequestError("Invalid request", "param")

        # Call the run method and assert that InvalidRequestError is raised
        with self.assertRaises(openai.error.InvalidRequestError):
            coder.run(with_message="hi")
>>>>>>> UPDATED
```

This change should fix the `TypeError` you're seeing in your test run.
2023-07-08 09:27:43 -07:00
Paul Gauthier
d3dac2fac6 aider: Add a test that mocks openai.ChatCompletion.create to throw an openai.error.InvalidRequestError and make sure it bubbles all the way up and out of the Coder class.
# Aider chat conversation:

USER: add a test that mocks openai.ChatCompletion.create to throw an openai.error.InvalidRequestError and make sure it bubbles all the way up and out of the Coder class. use coder.run as the entrypoint for the test

ASSISTANT: To add this test, we need to modify the `tests/test_coder.py` file. We will add a new test method `test_run_with_invalid_request_error` that mocks `openai.ChatCompletion.create` to throw an `openai.error.InvalidRequestError`. We will then call `coder.run` and assert that the `InvalidRequestError` is raised.

Here is the change:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
    if __name__ == "__main__":
        unittest.main()
=======
    @patch("aider.coders.base_coder.openai.ChatCompletion.create")
    def test_run_with_invalid_request_error(self, mock_chat_completion_create):
        # 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, openai_api_key="fake_key")

        # Set up the mock to raise InvalidRequestError
        mock_chat_completion_create.side_effect = openai.error.InvalidRequestError("Invalid request")

        # Call the run method and assert that InvalidRequestError is raised
        with self.assertRaises(openai.error.InvalidRequestError):
            coder.run(with_message="hi")

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

This test will ensure that if `openai.ChatCompletion.create` throws an `InvalidRequestError`, it will propagate up and out of the `Coder` class.
2023-07-08 09:26:27 -07:00
Paul Gauthier
1f64128978 added test_get_files_content 2023-07-07 16:45:10 -07:00
Paul Gauthier
031c2bc34b provide default git name/email; fix tests 2023-07-07 15:02:56 -07:00
Paul Gauthier
09f79e5a42 fix PermErr in test on windows 2023-07-06 12:37:32 -07:00
Paul Gauthier
656af5cd83 rename did not help 2023-07-06 12:26:29 -07:00
Paul Gauthier
2b69c11672 Try renaming to avoid windows PermErr 2023-07-06 12:08:07 -07:00
Paul Gauthier
4a15b6c010 test_run_with_file_utf_unicode_error 2023-07-06 11:57:44 -07:00