aider/tests
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
..
__init__.py aider: Added empty __init__.py file to tests directory to fix ModuleNotFoundError when running tests. 2023-05-11 17:12:42 -07:00
test_coder.py Whitelist more /cmds for no dirty commit 2023-07-16 13:42:36 -03:00
test_commands.py 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. 2023-07-17 15:58:28 -03:00
test_editblock.py updated tests 2023-07-11 15:17:00 -07:00
test_io.py Fix test 2023-07-10 15:33:46 -07:00
test_main.py test_main_git_ignore 2023-07-16 12:56:55 -03:00
test_models.py More Model test cases 2023-06-21 14:13:34 -07:00
test_repomap.py aider: Change the relative import to an absolute import for the IgnorantTemporaryDirectory class in test_repomap.py. 2023-07-16 09:05:18 -03:00
test_wholefile.py updated tests 2023-07-11 15:17:00 -07:00
utils.py refac make_repo 2023-07-16 12:25:18 -03:00