Commit graph

1119 commits

Author SHA1 Message Date
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
d7ba886e66 added test_update_files_live_diff 2023-07-11 07:32:31 -07:00
Paul Gauthier
27fbf8699f cleanup 2023-07-10 18:21:06 -07:00
Paul Gauthier
89e19b2370 Added failing test case 2023-07-10 16:26:20 -07:00
Paul Gauthier
c20b1bb073 Merge remote-tracking branch 'origin/main' 2023-07-10 15:34:04 -07:00
Paul Gauthier
aedfa64eb9 Fix test 2023-07-10 15:33:46 -07:00
Paul Gauthier
93866ebe17 test name 2023-07-10 15:19:30 -07:00
Paul Gauthier
e4389ab7f7 add test in drop 2023-07-10 15:18:11 -07:00
Paul Gauthier
a88b2a70e8 cleanup 2023-07-10 15:10:23 -07:00
Paul Gauthier
4b91adabdc aider: The test case has been modified to add files to the directory and ensure they are added correctly.
# Aider chat conversation:

USER: put some files in the test_dir, and the test shouldn't look for the exception. it should make sure the files were added

ASSISTANT: To modify the test case to add files to the directory and ensure they are added correctly, we need to modify the `tests/test_commands.py` file.

Here is the proposed change:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
    def test_cmd_add_directory(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Create a directory
        os.mkdir("test_dir")

        # Call the cmd_add method with a directory
        with self.assertRaises(IsADirectoryError):
            commands.cmd_add("test_dir")
=======
    def test_cmd_add_directory(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Create a directory and add files to it
        os.mkdir("test_dir")
        with open("test_dir/test_file1.txt", "w") as f:
            f.write("Test file 1")
        with open("test_dir/test_file2.txt", "w") as f:
            f.write("Test file 2")

        # Call the cmd_add method with a directory
        commands.cmd_add("test_dir")

        # Check if the files have been added to the chat session
        self.assertIn(str(Path("test_dir/test_file1.txt").resolve()), coder.abs_fnames)
        self.assertIn(str(Path("test_dir/test_file2.txt").resolve()), coder.abs_fnames)
>>>>>>> UPDATED
```

This new test case `test_cmd_add_directory` creates a directory named `test_dir`, adds two files to it, and attempts to add the directory using the `cmd_add` method. We then check if the files in the directory have been added to the chat session.
2023-07-10 13:19:11 -07:00
Paul Gauthier
8be2f8086c aider: Add a test case to reproduce the issue of trying to add a directory using the /add command.
# Aider chat conversation:

USER: add a test case to reproduce this issue: Trying to add just a directory makes the program throw the following and exit:

> /add src/components

Traceback (most recent call last):
  File "/home/palmerd/.local/bin/aider", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/palmerd/.local/lib/python3.11/site-packages/aider/main.py", line 369, in main
    coder.run()
  File "/home/palmerd/.local/lib/python3.11/site-packages/aider/coders/base_coder.py", line 382, in run
    new_user_message = self.run_loop()
                       ^^^^^^^^^^^^^^^
  File "/home/palmerd/.local/lib/python3.11/site-packages/aider/coders/base_coder.py", line 446, in run_loop
    return self.commands.run(inp)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/palmerd/.local/lib/python3.11/site-packages/aider/commands.py", line 60, in run
    return self.do_run(matching_commands[0][1:], rest_inp)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/palmerd/.local/lib/python3.11/site-packages/aider/commands.py", line 45, in do_run
    return cmd_method(args)
           ^^^^^^^^^^^^^^^^
  File "/home/palmerd/.local/lib/python3.11/site-packages/aider/commands.py", line 264, in cmd_add
    content = self.io.read_text(abs_file_path)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/palmerd/.local/lib/python3.11/site-packages/aider/io.py", line 142, in read_text
    with open(str(filename), "r", encoding=self.encoding) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IsADirectoryError: [Errno 21] Is a directory: '/home/palmerd/vue-frontend/src/components'

ASSISTANT: To reproduce this issue, we need to create a test case that tries to add a directory using the `/add` command. However, the code you've provided is not designed to handle test cases.

Could you please provide the test suite or the file where the test cases are written so that I can add a new test case?

USER: I added these *read-write* files: tests/test_commands.py

ASSISTANT: Great, we can add a test case in the `tests/test_commands.py` file. This test case will attempt to add a directory and check if the appropriate error is handled.

Here is the proposed change:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
    def test_cmd_add_no_match(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Call the cmd_add method with a non-existent file pattern
        commands.cmd_add("*.nonexistent")

        # Check if no files have been added to the chat session
        self.assertEqual(len(coder.abs_fnames), 0)
=======
    def test_cmd_add_no_match(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Call the cmd_add method with a non-existent file pattern
        commands.cmd_add("*.nonexistent")

        # Check if no files have been added to the chat session
        self.assertEqual(len(coder.abs_fnames), 0)

    def test_cmd_add_directory(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Create a directory
        os.mkdir("test_dir")

        # Call the cmd_add method with a directory
        with self.assertRaises(IsADirectoryError):
            commands.cmd_add("test_dir")
>>>>>>> UPDATED
```

This new test case `test_cmd_add_directory` creates a directory named `test_dir` and attempts to add it using the `cmd_add` method. We expect an `IsADirectoryError` to be raised in this scenario.
2023-07-10 13:17:55 -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
4b3fdc0f88 switch all to resolve 2023-07-07 16:59:35 -07:00
Paul Gauthier
d5921f1a9a try resolve 2023-07-07 16:49:56 -07:00
Paul Gauthier
1f64128978 added test_get_files_content 2023-07-07 16:45:10 -07:00
Paul Gauthier
2c037a009c add debug to failing test 2023-07-07 16:23:56 -07:00
Paul Gauthier
031c2bc34b provide default git name/email; fix tests 2023-07-07 15:02:56 -07:00
Paul Gauthier
f98ab4005d fix tests 2023-07-07 11:29:56 -07:00
Paul Gauthier
033541d01f Merge branch 'main' into glob-add 2023-07-07 09:10:56 -07:00
Paul Gauthier
1654ee422f add test for conf yml 2023-07-07 09:07:02 -07:00
Paul Gauthier
d8e125f552 added test_no_files_new_file_should_ask 2023-07-07 08:35:22 -07:00
Paul Gauthier
40787b3637 test case to tickle bug in wholefiles 2023-07-07 08:25:19 -07:00
Paul Gauthier
6a0cff50f8 filter against git 2023-07-06 18:09:26 -07:00
Paul Gauthier
cb2b2c5ce3 Merge branch 'main' into glob-add 2023-07-06 17:53:46 -07:00
Paul Gauthier
09f79e5a42 fix PermErr in test on windows 2023-07-06 12:37:32 -07:00
Paul Gauthier
0f1af1d991 improve filehandle hygene 2023-07-06 12:29:49 -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
Paul Gauthier
7cadfd9b4c aider: Changed encoding to 'latin-1' and provided content that will cause an error when read with 'utf-8' encoding in the test_run_with_file_utf_unicode_error method.
# Context:
USER: do the TODOs
ASSISTANT: I see two TODOs in the provided code.

1. In the `test_run_with_file_utf_unicode_error` method, you need to specify an encoding other than 'utf-8'.
2. In the same method, you need to provide content that will cause an error when read with 'utf-8' encoding.

Here are the proposed changes:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
        encoding = 'pick something other than utf-8' # TODO
=======
        encoding = 'latin-1'
>>>>>>> UPDATED
```

```python
tests/test_coder.py
<<<<<<< ORIGINAL
        some_content_which_will_error_if_read_with_encoding_utf8 = '' # TODO
=======
        some_content_which_will_error_if_read_with_encoding_utf8 = 'ÅÍÎÏ'.encode('utf-16')
>>>>>>> UPDATED
```

In the first change, I've chosen 'latin-1' as the encoding. It's a common encoding that's different from 'utf-8'.

In the second change, I've provided a string of characters that are not valid 'utf-8' when encoded with 'utf-16'. This will cause an error when trying to read the file with 'utf-8' encoding.
2023-07-06 11:56:15 -07:00
Paul Gauthier
5ec5b60660 better /tokens test 2023-07-06 11:50:13 -07:00
Paul Gauthier
eb6ac6841f aider: Redirected the standard output to an instance of io.StringIO and captured the console output of cmd_tokens.
# Context:
USER: how can i capture the console output of `cmd_tokens`?
ASSISTANT: To capture the console output of `cmd_tokens`, you can modify the `test_cmd_tokens` method in the `tests/test_commands.py` file. You can use the `io.StringIO` class to capture the standard output.

Here's how you can do it:

1. Import the `io` module at the top of the file.
2. In the `test_cmd_tokens` method, redirect the standard output to an instance of `io.StringIO` before calling `commands.cmd_tokens("")`.
3. After calling `commands.cmd_tokens("")`, you can get the console output from the `io.StringIO` instance.

Here is the *edit block* for the changes:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
import codecs
import os
import shutil
import tempfile
from unittest import TestCase

from aider import models
from aider.commands import Commands
from aider.io import InputOutput
=======
import codecs
import os
import shutil
import tempfile
from unittest import TestCase
import io

from aider import models
from aider.commands import Commands
from aider.io import InputOutput
>>>>>>> UPDATED

tests/test_commands.py
<<<<<<< ORIGINAL
    def test_cmd_tokens(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        commands.cmd_add("foo.txt bar.txt")
        commands.cmd_tokens("")
=======
    def test_cmd_tokens(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        commands.cmd_add("foo.txt bar.txt")

        # Redirect the standard output to an instance of io.StringIO
        stdout = io.StringIO()
        sys.stdout = stdout

        commands.cmd_tokens("")

        # Reset the standard output
        sys.stdout = sys.__stdout__

        # Get the console output
        console_output = stdout.getvalue()
        print(console_output)
>>>>>>> UPDATED
```

Please note that this will only capture the output of `print` statements. If the `cmd_tokens` method writes to the console in a different way (for example, by writing directly to `sys.stdout`), this might not capture that output.
2023-07-06 11:46:20 -07:00
Paul Gauthier
089fa57ede full edit for wholefile 2023-07-06 11:43:20 -07:00
Paul Gauthier
7d3c40ea21 test dry run 2023-07-06 11:34:19 -07:00
Paul Gauthier
7bbf0c0870 test full editblock edit 2023-07-06 11:32:31 -07:00
Paul Gauthier
610dd223b5 added test for choose_fence 2023-07-06 11:08:13 -07:00
Paul Gauthier
ffee2c9511 test for unicode errors 2023-07-06 10:59:25 -07:00
Paul Gauthier
5647240207 aider: Added a new test test_run_with_file_unicode_error that expects a UnicodeDecodeError to be raised when the run method of the Coder object is called with a file containing non-UTF8 text.
# Context:
USER: I did `git reset --hard HEAD~1` to discard the last edits.
ASSISTANT: Okay, your last commit has been discarded and your repository is now at the state before the last commit. If you need to make any further changes or need assistance with anything else, feel free to ask.
USER: try again, but don't elide code with ...
ASSISTANT: Understood. Here's the updated *edit block* without eliding any code:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
    def test_run_with_file_deletion(self):
        # Create a few temporary files
        _, file1 = tempfile.mkstemp()
        _, file2 = tempfile.mkstemp()

        files = [file1, file2]

        # Initialize the Coder object with the mocked IO and mocked repo
        coder = Coder.create(
            models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", fnames=files
        )

        def mock_send(*args, **kwargs):
            coder.partial_response_content = "ok"
            coder.partial_response_function_call = dict()

        coder.send = MagicMock(side_effect=mock_send)

        # Call the run method with a message
        coder.run(with_message="hi")
        self.assertEqual(len(coder.abs_fnames), 2)

        # Delete one of the files
        os.remove(file1)

        # Call the run method again with a message
        coder.run(with_message="hi")
        self.assertEqual(len(coder.abs_fnames), 1)

if __name__ == "__main__":
    unittest.main()
=======
    def test_run_with_file_deletion(self):
        # Create a few temporary files
        _, file1 = tempfile.mkstemp()
        _, file2 = tempfile.mkstemp()

        files = [file1, file2]

        # Initialize the Coder object with the mocked IO and mocked repo
        coder = Coder.create(
            models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", fnames=files
        )

        def mock_send(*args, **kwargs):
            coder.partial_response_content = "ok"
            coder.partial_response_function_call = dict()

        coder.send = MagicMock(side_effect=mock_send)

        # Call the run method with a message
        coder.run(with_message="hi")
        self.assertEqual(len(coder.abs_fnames), 2)

        # Delete one of the files
        os.remove(file1)

        # Call the run method again with a message
        coder.run(with_message="hi")
        self.assertEqual(len(coder.abs_fnames), 1)

    def test_run_with_file_unicode_error(self):
        # Create a temporary file
        _, file = tempfile.mkstemp()

        # Write some non-UTF8 text into the file
        with open(file, "wb") as f:
            f.write(b"\x80abc")

        # Initialize the Coder object with the temporary file
        coder = Coder.create(
            models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", fnames=[file]
        )

        # Expect a UnicodeDecodeError to be raised when the run method is called
        with self.assertRaises(UnicodeDecodeError):
            coder.run(with_message="hi")

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

This new test `test_run_with_file_unicode_error` will write non-UTF8 text into a temporary file and expect a `UnicodeDecodeError` to be raised when the `run` method of the `Coder` object is called.
2023-07-06 10:58:36 -07:00
Paul Gauthier
3c443d68d0 working test 2023-07-06 10:55:38 -07:00
Paul Gauthier
927b97bea1 Added test1.py and test2.py files, dropped *2.py files, and checked if test1.py file is in the abs_fnames list. 2023-07-05 21:41:31 -07:00
Paul Gauthier
7f76559e6c aider: Added a test for the cmd_drop method with glob patterns in the TestCommands class.
# Context:
USER: add a test for that
ASSISTANT: To add a test for the `cmd_drop` method with glob patterns, we need to modify the `tests/test_commands.py` file.

Here's the step-by-step process:

1. Add a new test method `test_cmd_drop_with_glob_patterns` in the `TestCommands` class.
2. In this method, initialize the `Commands` and `InputOutput` objects.
3. Add some files to the chat session.
4. Call the `cmd_drop` method with a glob pattern.
5. Check if the correct files have been removed from the chat session.

Here's the code change:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
    def test_cmd_add_no_match(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Call the cmd_add method with a non-existent file pattern
        commands.cmd_add("*.nonexistent")

        # Check if no files have been added to the chat session
        self.assertEqual(len(coder.abs_fnames), 0)
=======
    def test_cmd_add_no_match(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Call the cmd_add method with a non-existent file pattern
        commands.cmd_add("*.nonexistent")

        # Check if no files have been added to the chat session
        self.assertEqual(len(coder.abs_fnames), 0)

    def test_cmd_drop_with_glob_patterns(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Add some files to the chat session
        commands.cmd_add("*.py")

        # Call the cmd_drop method with a glob pattern
        commands.cmd_drop("*.py")

        # Check if the Python files have been removed from the chat session
        self.assertNotIn(os.path.abspath("test1.py"), coder.abs_fnames)
        self.assertNotIn(os.path.abspath("test2.py"), coder.abs_fnames)
>>>>>>> UPDATED
```
Please let me know if you need any further changes.
2023-07-05 21:40:01 -07:00
Paul Gauthier
2b07e2de30 aider: Add a test for cmd_add where nothing matches.
# Context:
USER: add a test for cmd_add where nothing matches
ASSISTANT: To add a test for the `cmd_add` method where nothing matches, we need to modify the `tests/test_commands.py` file.

Here's the step-by-step process:

1. Add a new test method `test_cmd_add_no_match` in the `TestCommands` class.
2. In this method, initialize the `Commands` and `InputOutput` objects.
3. Call the `cmd_add` method with a non-existent file pattern.
4. Check if no files have been added to the chat session.

Here's the code change:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
    def test_cmd_add_with_glob_patterns(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Create some test files
        with open("test1.py", "w") as f:
            f.write("print('test1')")
        with open("test2.py", "w") as f:
            f.write("print('test2')")
        with open("test.txt", "w") as f:
            f.write("test")

        # Call the cmd_add method with a glob pattern
        commands.cmd_add("*.py")

        # Check if the Python files have been added to the chat session
        self.assertIn(os.path.abspath("test1.py"), coder.abs_fnames)
        self.assertIn(os.path.abspath("test2.py"), coder.abs_fnames)

        # Check if the text file has not been added to the chat session
        self.assertNotIn(os.path.abspath("test.txt"), coder.abs_fnames)
=======
    def test_cmd_add_with_glob_patterns(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Create some test files
        with open("test1.py", "w") as f:
            f.write("print('test1')")
        with open("test2.py", "w") as f:
            f.write("print('test2')")
        with open("test.txt", "w") as f:
            f.write("test")

        # Call the cmd_add method with a glob pattern
        commands.cmd_add("*.py")

        # Check if the Python files have been added to the chat session
        self.assertIn(os.path.abspath("test1.py"), coder.abs_fnames)
        self.assertIn(os.path.abspath("test2.py"), coder.abs_fnames)

        # Check if the text file has not been added to the chat session
        self.assertNotIn(os.path.abspath("test.txt"), coder.abs_fnames)

    def test_cmd_add_no_match(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Call the cmd_add method with a non-existent file pattern
        commands.cmd_add("*.nonexistent")

        # Check if no files have been added to the chat session
        self.assertEqual(len(coder.abs_fnames), 0)
>>>>>>> UPDATED
```
Please let me know if you need any further changes.
2023-07-05 21:35:09 -07:00
Paul Gauthier
7b4088c507 aider: Added a new test method test_cmd_add_with_glob_patterns to the TestCommands class in tests/test_commands.py to test the /add command with glob patterns.
# Context:
USER: add some tests
ASSISTANT: To add tests for the new functionality, we need to modify the `tests/test_commands.py` file.

We will add a new test method `test_cmd_add_with_glob_patterns` to the `TestCommands` class. This method will test the `/add` command with glob patterns.

Here is the proposed change:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
    def test_cmd_add(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Call the cmd_add method with 'foo.txt' and 'bar.txt' as a single string
        commands.cmd_add("foo.txt bar.txt")

        # Check if both files have been created in the temporary directory
        self.assertTrue(os.path.exists("foo.txt"))
        self.assertTrue(os.path.exists("bar.txt"))
=======
    def test_cmd_add_with_glob_patterns(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Create some test files
        with open("test1.py", "w") as f:
            f.write("print('test1')")
        with open("test2.py", "w") as f:
            f.write("print('test2')")
        with open("test.txt", "w") as f:
            f.write("test")

        # Call the cmd_add method with a glob pattern
        commands.cmd_add("*.py")

        # Check if the Python files have been added to the chat session
        self.assertIn(os.path.abspath("test1.py"), coder.abs_fnames)
        self.assertIn(os.path.abspath("test2.py"), coder.abs_fnames)

        # Check if the text file has not been added to the chat session
        self.assertNotIn(os.path.abspath("test.txt"), coder.abs_fnames)
>>>>>>> UPDATED
```

This test creates three files: `test1.py`, `test2.py`, and `test.txt`. It then calls the `/add` command with the glob pattern `*.py`. The test checks that the Python files have been added to the chat session and that the text file has not been added.
2023-07-05 21:29:53 -07:00
Paul Gauthier
4126875425 added test_cmd_tokens 2023-07-05 21:08:12 -07:00
Paul Gauthier
c6e71b443b move import 2023-07-05 20:57:59 -07:00
Paul Gauthier
388f603ef9 aider: Created a file 'foo.bad' with non-utf8 characters before calling the 'cmd_add' method.
# Context:
USER: do the todo
ASSISTANT: To complete the TODO, we need to create a file named 'foo.bad' with a non-utf8 encoding. We can use the Python 'codecs' module to create a file with a specific encoding. In this case, we'll use 'iso-8859-15' which is a common encoding that includes characters not present in utf-8.

Here's how to modify the 'test_cmd_add_bad_encoding' method in the 'tests/test_commands.py' file:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
    def test_cmd_add_bad_encoding(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # TODO: make a new file foo.bad which will fail to decode as utf-8

        commands.cmd_add("foo.bad")

        self.assertEqual(coder.abs_fnames, set())
=======
    import codecs
    def test_cmd_add_bad_encoding(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Create a new file foo.bad which will fail to decode as utf-8
        with codecs.open('foo.bad', 'w', encoding='iso-8859-15') as f:
            f.write('ÆØÅ')  # Characters not present in utf-8

        commands.cmd_add("foo.bad")

        self.assertEqual(coder.abs_fnames, set())
>>>>>>> UPDATED
```

This will create a file 'foo.bad' with non-utf8 characters before calling the 'cmd_add' method.
2023-07-05 20:57:21 -07:00
Paul Gauthier
c8fb1ddaa7 refactor to use io.read_text 2023-07-05 20:46:15 -07:00
Paul Gauthier
5dba1624c7 fix broken test 2023-07-05 17:11:39 -07:00