Commit graph

55 commits

Author SHA1 Message Date
Paul Gauthier
9352bc67ca Added test case for issue #139 2023-07-23 08:34:19 -03:00
Paul Gauthier
47b550c62f aider: Switched open calls to use Path.write_text.
# Aider chat conversation:

USER: also swith the open calls to use Path.write_text

ASSISTANT: To switch the `open` calls to use `Path.write_text` in `test_cmd_add_drop_directory`, we need to modify the `tests/test_commands.py` file. Here are the changes:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
        with open(Path("test_dir/test_file1.txt"), "w") as f:
            f.write("Test file 1")
        with open(Path("test_dir/test_file2.txt"), "w") as f:
            f.write("Test file 2")
        with open(Path("test_dir/another_dir/test_file.txt"), "w") as f:
            f.write("Test file 3")
=======
        Path("test_dir/test_file1.txt").write_text("Test file 1")
        Path("test_dir/test_file2.txt").write_text("Test file 2")
        Path("test_dir/another_dir/test_file.txt").write_text("Test file 3")
>>>>>>> UPDATED
```

This change replaces the `open` calls with `Path().write_text()` from the pathlib module.
2023-07-23 08:19:17 -03:00
Paul Gauthier
d695fe103b aider: Switched all the os calls to use pathlib in test_cmd_add_drop_directory.
# Aider chat conversation:

USER: switch all the os calls to use pathlib in `test_cmd_add_drop_directory`

ASSISTANT: To switch all the os calls to use pathlib in `test_cmd_add_drop_directory`, we need to modify the `tests/test_commands.py` file. Here are the changes:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
        # Create a directory and add files to it
        os.mkdir("test_dir")
        os.mkdir("test_dir/another_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")
        with open("test_dir/another_dir/test_file.txt", "w") as f:
            f.write("Test file 3")
=======
        # Create a directory and add files to it using pathlib
        Path("test_dir").mkdir()
        Path("test_dir/another_dir").mkdir()
        with open(Path("test_dir/test_file1.txt"), "w") as f:
            f.write("Test file 1")
        with open(Path("test_dir/test_file2.txt"), "w") as f:
            f.write("Test file 2")
        with open(Path("test_dir/another_dir/test_file.txt"), "w") as f:
            f.write("Test file 3")
>>>>>>> UPDATED
```

This change replaces the `os.mkdir` calls with `Path().mkdir()` from the pathlib module. It also changes the file paths in the `open` calls to use `Path()`.
2023-07-23 08:18:34 -03:00
Paul Gauthier
77f8be10b1 restore test_cmd_tokens 2023-07-17 16:01:37 -03:00
Paul Gauthier
fd6ceb167c fixed test 2023-07-17 16:00:29 -03:00
Paul Gauthier
8dcff175bc aider: Added a test for cmd_git that creates a temporary git repository, adds a file, runs the cmd_git method with the arguments "commit -a -m msg", and confirms that the file is in the repository.
# Aider chat conversation:

USER: write a test for `cmd_git`. use `GitTemporaryDirectory` to make a temp git repo. add a file. then run `/git commit -a -m msg` and confirm that the file is in the repo

ASSISTANT: To write a test for `cmd_git`, we need to modify the `tests/test_commands.py` file.

Here are the steps we need to follow:

1. Import `GitTemporaryDirectory` from `tests.utils`.
2. Create a new test method `test_cmd_git`.
3. Inside this method, create a temporary git repository using `GitTemporaryDirectory`.
4. Add a file to the repository.
5. Run the `cmd_git` method with the arguments `"commit -a -m msg"`.
6. Check if the file has been committed to the repository.

Here is the *edit block* for these changes:

<source>python
tests/test_commands.py
<<<<<<< ORIGINAL
from unittest import TestCase

from aider import models
from aider.coders import Coder
from aider.commands import Commands
from aider.dump import dump  # noqa: F401
from aider.io import InputOutput
=======
from unittest import TestCase
from tests.utils import GitTemporaryDirectory

from aider import models
from aider.coders import Coder
from aider.commands import Commands
from aider.dump import dump  # noqa: F401
from aider.io import InputOutput
>>>>>>> UPDATED
</source>

<source>python
tests/test_commands.py
<<<<<<< ORIGINAL
    def test_cmd_tokens(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)

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

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

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

        commands.cmd_tokens("")

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

        # Get the console output
        console_output = stdout.getvalue()

        self.assertIn("foo.txt", console_output)
        self.assertIn("bar.txt", console_output)
=======
    def test_cmd_git(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)

        with GitTemporaryDirectory() as tempdir:
            # Create a file in the temporary directory
            with open(f"{tempdir}/test.txt", "w") as f:
                f.write("test")

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

            # Run the cmd_git method with the arguments "commit -a -m msg"
            commands.cmd_git("commit -a -m msg")

            # Check if the file has been committed to the repository
            repo = git.Repo(tempdir)
            files_in_repo = [item.a_path for item in repo.index.diff(None)]
            self.assertIn("test.txt", files_in_repo)
>>>>>>> UPDATED
</source>
2023-07-17 15:58:28 -03:00
Paul Gauthier
bcdf8968f1 updated tests 2023-07-11 15:15:56 -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
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
2c037a009c add debug to failing test 2023-07-07 16:23:56 -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
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
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
4b69e2b85c fixed test 2023-06-21 21:33:51 -07:00
Paul Gauthier
124ab7dd99 fixed test 2023-06-20 17:27:48 -07:00
Paul Gauthier
e43a48ee10 patch check_model_availability in tests 2023-06-01 08:58:35 -07:00
Paul Gauthier
92cd2f3ce6 isort 2023-05-28 22:47:38 -07:00
Paul Gauthier
e50fe2469d aider: Added setUp and tearDown methods to TestCommands class to remember the current working directory, create a temporary directory, and change the working directory to the temporary directory in setUp, and change the working directory back to the original directory in tearDown.
# Context:
USER: add setUp and tearDown. in setUp, make a remember the cwd, make a tempdir and chdir there. in teardown, chdir back to the original dir
ASSISTANT: I will add `setUp` and `tearDown` methods to the `TestCommands` class in the `tests/test_commands.py` file. In the `setUp` method, I will
^C KeyboardInterrupt
USER: add setUp and tearDown. in setUp, make a remember the cwd, make a tempdir and chdir there. in teardown, chdir back to the original dir
ASSISTANT: I will add `setUp` and `tearDown` methods to the `TestCommands` class in the `tests/test_commands.py` file. In the `setUp` method, I will remember the current working directory, create a temporary directory, and change the working directory to the temporary directory. In the `tearDown` method, I will change the working directory back to the original directory.

Here are the changes:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
class TestCommands(TestCase):
    def test_cmd_add(self):
=======
import shutil

class TestCommands(TestCase):
    def setUp(self):
        self.original_cwd = os.getcwd()
        self.tempdir = tempfile.mkdtemp()
        os.chdir(self.tempdir)

    def tearDown(self):
        os.chdir(self.original_cwd)
        shutil.rmtree(self.tempdir)

    def test_cmd_add(self):
>>>>>>> UPDATED
```
2023-05-28 22:40:37 -07:00
Paul Gauthier
bb969c7197 aider: Added a temporary directory and changed the current working directory in tests/test_commands.py and restored the working directory after the context manager exits.
# Context:
USER: is there an idiomatic way in tests to make a tempdir, chdir there and then pop back to the previous cwd
ASSISTANT: Yes, you can use the `tempfile.TemporaryDirectory` context manager along with the `os.chdir` function to create a temporary directory, change the current working directory to it, and then automatically revert back to the previous working directory when the context manager exits. Here's an example:

```python
import os
import tempfile

def test_tempdir_example():
    original_cwd = os.getcwd()

    with tempfile.TemporaryDirectory() as tempdir:
        os.chdir(tempdir)
        # Perform your tests here

    # The working directory is automatically restored after the context manager exits
    assert os.getcwd() == original_cwd
```

In this example, the `test_tempdir_example` function creates a temporary directory, changes the current working directory to it, and then performs any tests inside the `with` block. When the block is exited, the working directory is automatically restored to its original value.
USER: do that in tests/test_commands.py
ASSISTANT: Here's the updated `tests/test_commands.py` with the temporary directory and working directory change:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
import os
import tempfile
from unittest import TestCase
from aider.commands import Commands
from aider.io import InputOutput

class TestCommands(TestCase):
    def test_cmd_add(self):
        # Create a temporary directory and change the current working directory
        with tempfile.TemporaryDirectory() as tmpdir:
            os.chdir(tmpdir)

            # Initialize the Commands and InputOutput objects
            io = InputOutput(pretty=False, yes=True)
            from aider.coder import Coder

            coder = Coder(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"))
=======
import os
import tempfile
from unittest import TestCase
from aider.commands import Commands
from aider.io import InputOutput

class TestCommands(TestCase):
    def test_cmd_add(self):
        original_cwd = os.getcwd()

        with tempfile.TemporaryDirectory() as tmpdir:
            os.chdir(tmpdir)

            # Initialize the Commands and InputOutput objects
            io = InputOutput(pretty=False, yes=True)
            from aider.coder import Coder

            coder = Coder(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"))

        # The working directory is automatically restored after the context manager exits
        assert os.getcwd() == original_cwd
>>>>>>> UPDATED
```

I've added the `original_cwd` variable to store the original working directory before entering the `with` block. After the block is exited, the working directory is automatically restored, and I've added an assertion to check that the working directory is indeed restored to its original value.
2023-05-28 22:35:00 -07:00
Paul Gauthier
3f5e4130ea fixed test 2023-05-27 06:25:16 -07:00
Paul Gauthier
680fc45fb3 improved prompting, fix ctags bug 2023-05-19 09:47:06 -07:00
Paul Gauthier
d1551b46be aider: Updated test to pass a string instead of a list when calling cmd_add method.
# Context:
USER: I ran this command:

 pytest tests/test_commands.py

Which produced this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/gauthier/Projects/aider
collected 1 item

tests/test_commands.py F                                                 [100%]

=================================== FAILURES ===================================
__________________________ TestCommands.test_cmd_add ___________________________

self = <tests.test_commands.TestCommands testMethod=test_cmd_add>

    def test_cmd_add(self):
        # Create a temporary directory and change the current working directory
        with tempfile.TemporaryDirectory() as tmpdir:
            os.chdir(tmpdir)

            # Initialize the Commands and InputOutput objects
            io = InputOutput(pretty=False, yes=True)
            coder = MagicMock()
            commands = Commands(io, coder)

            # Call the cmd_add method with 'foo.txt' and 'bar.txt'
>           commands.cmd_add(["foo.txt", "bar.txt"])

/Users/gauthier/Projects/aider/tests/test_commands.py:20:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <aider.commands.Commands object at 0x103e2fa50>
args = ['foo.txt', 'bar.txt']

    def cmd_add(self, args):
        "Add matching files to the chat session"

        added_fnames = []
        files = self.coder.get_all_relative_files()
>       for word in args.split():
E       AttributeError: 'list' object has no attribute 'split'

/Users/gauthier/Projects/aider/aider/commands.py:161: AttributeError
=========================== short test summary info ============================
FAILED tests/test_commands.py::TestCommands::test_cmd_add - AttributeError: '...
============================== 1 failed in 0.28s ===============================

ASSISTANT: It seems that the `cmd_add` method in `aider/commands.py` is expecting a string as input, but in the test, we are passing a list. I will update the test to pass a string instead of a list.

Here's the code change:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
            # Call the cmd_add method with 'foo.txt' and 'bar.txt'
            commands.cmd_add(["foo.txt", "bar.txt"])
=======
            # Call the cmd_add method with 'foo.txt' and 'bar.txt' as a single string
            commands.cmd_add("foo.txt bar.txt")
>>>>>>> UPDATED
```

Now, run the test again with the updated test method:

```
pytest tests/test_commands.py
```
2023-05-19 09:16:51 -07:00
Paul Gauthier
e2d5212eec aider: Added a test method test_cmd_add that creates a temporary directory, calls the cmd_add method with 'foo.txt' and 'bar.txt', and checks if both files have been created in the temporary directory.
# Context:
USER: add a test for cmd_add that passes in 'foo.txt' and 'bar.txt' and ensures they have both been created after the test. run the test in a tmp dir.
ASSISTANT: I will add a new test method called `test_cmd_add` in the `tests/test_commands.py` file. This test will create a temporary directory, change the current working directory to the temporary directory, and then call the `cmd_add` method with 'foo.txt' and 'bar.txt' as arguments. After that, it will check if both files have been created in the temporary directory.

Here's the code change:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
=======
import os
import tempfile
from unittest import TestCase
from unittest.mock import MagicMock
from aider.commands import Commands
from aider.io import InputOutput

class TestCommands(TestCase):
    def test_cmd_add(self):
        # Create a temporary directory and change the current working directory
        with tempfile.TemporaryDirectory() as tmpdir:
            os.chdir(tmpdir)

            # Initialize the Commands and InputOutput objects
            io = InputOutput(pretty=False, yes=True)
            coder = MagicMock()
            commands = Commands(io, coder)

            # Call the cmd_add method with 'foo.txt' and 'bar.txt'
            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"))
>>>>>>> UPDATED
```

This test will ensure that the `cmd_add` method creates the specified files in the current working directory.
2023-05-19 09:16:14 -07:00
Paul Gauthier
b9cea2cdb1 Added new files to the git repo: tests/test_commands.py 2023-05-19 09:15:06 -07:00
Paul Gauthier
6900e7a282 byebye 2023-05-19 09:09:36 -07:00
Paul Gauthier
5d06cab9e6 aider: Fixed cmd_add method to accept string input instead of list.
# Context:
USER: I ran this command:

 pytest tests/test_commands.py

Which produced this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/gauthier/Projects/aider
collected 1 item

tests/test_commands.py F                                                 [100%]

=================================== FAILURES ===================================
__________________________ TestCommands.test_cmd_add ___________________________

self = <tests.test_commands.TestCommands testMethod=test_cmd_add>

    def test_cmd_add(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            original_cwd = os.getcwd()
            os.chdir(tmpdir)

            io = InputOutput(pretty=True, yes=True)
            coder = Coder(io)
            commands = Commands(io, coder)

>           commands.cmd_add(['foo.txt', 'bar.txt'])

/Users/gauthier/Projects/aider/tests/test_commands.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <aider.commands.Commands object at 0x107e74210>
args = ['foo.txt', 'bar.txt']

    def cmd_add(self, args):
        "Add matching files to the chat session"

        added_fnames = []
        files = self.coder.get_all_relative_files()
>       for word in args.split():
E       AttributeError: 'list' object has no attribute 'split'

/Users/gauthier/Projects/aider/aider/commands.py:161: AttributeError
----------------------------- Captured stdout call -----------------------------
Files are not in a git repo.
No suitable git repo, will not automatically commit edits.
Common root directory:
/private/var/folders/49/kxrdwwbx0h9bchx99397477c0000gn/T/tmptf5hloir
=========================== short test summary info ============================
FAILED tests/test_commands.py::TestCommands::test_cmd_add - AttributeError: '...
============================== 1 failed in 0.73s ===============================

ASSISTANT: I apologize for the mistake. The `cmd_add` method expects a string as input, not a list. We need to modify the test to pass the arguments as a single string.

Here's the code change:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
            commands.cmd_add(['foo.txt', 'bar.txt'])
=======
            commands.cmd_add('foo.txt bar.txt')
>>>>>>> UPDATED
```

This should fix the `AttributeError` and allow the test to run successfully.
2023-05-19 09:08:37 -07:00
Paul Gauthier
3998bf4c2e aider: Fixed InputOutput instantiation in test_cmd_add.
# Context:
USER: I ran this command:

 pytest tests/test_commands.py

Which produced this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/gauthier/Projects/aider
collected 1 item

tests/test_commands.py F                                                 [100%]

=================================== FAILURES ===================================
__________________________ TestCommands.test_cmd_add ___________________________

self = <tests.test_commands.TestCommands testMethod=test_cmd_add>

    def test_cmd_add(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            original_cwd = os.getcwd()
            os.chdir(tmpdir)

>           io = InputOutput()
E           TypeError: InputOutput.__init__() missing 2 required positional arguments: 'pretty' and 'yes'

/Users/gauthier/Projects/aider/tests/test_commands.py:14: TypeError
=========================== short test summary info ============================
FAILED tests/test_commands.py::TestCommands::test_cmd_add - TypeError: InputO...
============================== 1 failed in 0.77s ===============================

ASSISTANT: I apologize for the oversight. The `InputOutput` class requires two positional arguments: `pretty` and `yes`. Let's update the test to provide these arguments.

Here's the code change:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
            io = InputOutput()
=======
            io = InputOutput(pretty=True, yes=True)
>>>>>>> UPDATED
```

This should fix the `TypeError` and allow the test to run successfully.
2023-05-19 09:07:56 -07:00
Paul Gauthier
922d28216a aider: Added a test for cmd_add that passes in 'foo.txt' and 'bar.txt' and ensures they have both been created after the test.
# Context:
USER: add a test for cmd_add that passes in 'foo.txt' and 'bar.txt' and ensures they have both been created after the test. run the test in a tmp dir.
ASSISTANT: To add the test for `cmd_add`, we will modify the `tests/test_commands.py` file. Here's the step-by-step plan:

1. Import the necessary libraries and classes.
2. Create a new test method called `test_cmd_add` inside the `TestCommands` class.
3. In the `test_cmd_add` method, create a temporary directory using `tempfile.TemporaryDirectory`.
4. Change the current working directory to the temporary directory.
5. Create an instance of the `InputOutput` and `Coder` classes.
6. Create an instance of the `Commands` class, passing the `InputOutput` and `Coder` instances.
7. Call the `cmd_add` method with the arguments `['foo.txt', 'bar.txt']`.
8. Check if both 'foo.txt' and 'bar.txt' files have been created in the temporary directory.
9. Change the current working directory back to the original directory.

Here's the code change:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
=======
import os
import tempfile
from unittest import TestCase
from aider.io import InputOutput
from aider.coder import Coder
from aider.commands import Commands

class TestCommands(TestCase):
    def test_cmd_add(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            original_cwd = os.getcwd()
            os.chdir(tmpdir)

            io = InputOutput()
            coder = Coder(io)
            commands = Commands(io, coder)

            commands.cmd_add(['foo.txt', 'bar.txt'])

            self.assertTrue(os.path.exists('foo.txt'))
            self.assertTrue(os.path.exists('bar.txt'))

            os.chdir(original_cwd)
>>>>>>> UPDATED
```

This will add the test for `cmd_add` and ensure that both 'foo.txt' and 'bar.txt' have been created after the test.
2023-05-19 09:06:56 -07:00
Paul Gauthier
73853d42ce Added new files to the git repo: tests/test_commands.py 2023-05-19 09:04:59 -07:00
Paul Gauthier
37812084c1 forget about cmd_add test 2023-05-19 09:04:35 -07:00
Paul Gauthier
ba9307374e cleanup Coder params 2023-05-18 18:21:44 -07:00
Paul Gauthier
a59575fa4b wip: Removed unused import from test_commands.py. 2023-05-18 18:17:38 -07:00
Paul Gauthier
78af36ffda cleanup 2023-05-18 18:17:02 -07:00
Paul Gauthier
ad865fe0f4 removed yes 2023-05-18 18:12:27 -07:00
Paul Gauthier
59c3fef150 aider: Updated test_cmd_add method in tests/test_commands.py to pass yes=True when creating a Coder instance.
# Context:
USER: call Coder with yes=True
ASSISTANT: I will update the `test_cmd_add` method in the `tests/test_commands.py` file to pass `yes=True` when creating a `Coder` instance.

```python
tests/test_commands.py
<<<<<<< ORIGINAL
            coder = Coder(main_model="gpt-3.5-turbo", fnames=[], pretty=False, show_diffs=False, auto_commits=False, io=io, dry_run=False)
=======
            coder = Coder(main_model="gpt-3.5-turbo", fnames=[], pretty=False, show_diffs=False, auto_commits=False, io=io, dry_run=False, yes=True)
>>>>>>> UPDATED
```
2023-05-18 18:10:30 -07:00
Paul Gauthier
240bdf03df aider: Fixed call to Coder class in tests/test_commands.py.
# Context:
USER: I ran this command:

 pytest tests/test_commands.py

Which produced this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/gauthier/Projects/aider
collected 1 item

tests/test_commands.py F                                                 [100%]

=================================== FAILURES ===================================
__________________________ TestCommands.test_cmd_add ___________________________

self = <tests.test_commands.TestCommands testMethod=test_cmd_add>

    def test_cmd_add(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            io = IO(pretty=False, yes=True)
>           coder = Coder(root=tmpdir)
E           TypeError: Coder.__init__() got an unexpected keyword argument 'root'

tests/test_commands.py:13: TypeError
=========================== short test summary info ============================
FAILED tests/test_commands.py::TestCommands::test_cmd_add - TypeError: Coder....
============================== 1 failed in 0.52s ===============================

ASSISTANT: It seems like the `Coder` class in `aider/coder.py` does not accept a `root` keyword argument in its `__init__` method. To fix this issue, we need to modify the `__init__` method of the `Coder` class to accept the `root` keyword argument and set it as an instance variable
^C KeyboardInterrupt
USER: no, fix the call
ASSISTANT: To fix the call to the `Coder` class in `tests/test_commands.py`, we need to remove the `root` keyword argument and pass the required arguments according to the `__init__` method of the `Coder` class.

Here's the change you need to make in `tests/test_commands.py`:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
            coder = Coder(root=tmpdir)
=======
            coder = Coder(main_model="gpt-3.5-turbo", fnames=[], pretty=False, show_diffs=False, auto_commits=False, io=io, dry_run=False)
>>>>>>> UPDATED
```

This change removes the `root` keyword argument and provides the required arguments for the `Coder` class.
2023-05-18 18:07:21 -07:00
Paul Gauthier
b0f573bde3 Refactor IO instantiation in test_commands.py. 2023-05-18 17:31:00 -07:00