aider/tests
Paul Gauthier 6c77c32d06 aider: Refactored test_check_gitignore to use a temporary git config file and set the GIT_CONFIG_GLOBAL environment variable during the test execution.
# Aider chat conversation:

USER: in `test_check_gitignore` can we have gitpython not use the global gitignore?

ASSISTANT: To ensure that GitPython does not use the global gitignore, we can set the `GIT_CONFIG_GLOBAL` environment variable to point to a non-existent file or an empty temporary file during the test execution. This will effectively ignore the global gitignore settings.

We will modify the `test_check_gitignore` method in the `tests/test_main.py` file to set the `GIT_CONFIG_GLOBAL` environment variable before the test runs and reset it after the test is completed.

Here are the *SEARCH/REPLACE* blocks:

tests/test_main.py
```python
<<<<<<< SEARCH
    def test_check_gitignore(self):
        make_repo()
        io = InputOutput(pretty=False, yes=True)
        cwd = Path.cwd()
        gitignore = cwd / ".gitignore"

        self.assertFalse(gitignore.exists())
        check_gitignore(cwd, io)
        self.assertTrue(gitignore.exists())

        self.assertEqual(".aider*", gitignore.read_text().splitlines()[0])

        gitignore.write_text("one\ntwo\n")
        check_gitignore(cwd, io)
        self.assertEqual("one\ntwo\n.aider*\n", gitignore.read_text())
=======
    def test_check_gitignore(self):
        with tempfile.NamedTemporaryFile() as temp_gitconfig:
            os.environ['GIT_CONFIG_GLOBAL'] = temp_gitconfig.name
            make_repo()
            io = InputOutput(pretty=False, yes=True)
            cwd = Path.cwd()
            gitignore = cwd / ".gitignore"

            self.assertFalse(gitignore.exists())
            check_gitignore(cwd, io)
            self.assertTrue(gitignore.exists())

            self.assertEqual(".aider*", gitignore.read_text().splitlines()[0])

            gitignore.write_text("one\ntwo\n")
            check_gitignore(cwd, io)
            self.assertEqual("one\ntwo\n.aider*\n", gitignore.read_text())
            del os.environ['GIT_CONFIG_GLOBAL']
>>>>>>> REPLACE
```

This change will create a temporary file to act as a dummy global git configuration file and set the `GIT_CONFIG_GLOBAL` environment variable to its path. After the test, it will delete the environment variable to avoid affecting other tests or operations.
2023-11-14 13:05:47 -08: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 fixed tests 2023-10-25 15:30:33 -07:00
test_commands.py Armor AutoCompleter against unicode errors #305 2023-11-03 07:26:21 -07:00
test_editblock.py find_original_update_blocks now accepts fence param, raises on mangled <source>filename.ext #317 2023-11-02 12:05:39 -07:00
test_io.py Armor AutoCompleter against unicode errors #305 2023-11-03 07:26:21 -07:00
test_main.py aider: Refactored test_check_gitignore to use a temporary git config file and set the GIT_CONFIG_GLOBAL environment variable during the test execution. 2023-11-14 13:05:47 -08:00
test_models.py lint 2023-09-01 15:53:19 -07:00
test_repo.py Give up testing aiderignore caching in github actions 2023-10-18 12:28:24 -07:00
test_repomap.py fix tests; fix off-by-one bug in output of repomap 2023-10-18 15:42:38 -07:00
test_sendchat.py move tests to test_sendchat.py 2023-07-21 14:17:14 -03:00
test_wholefile.py fix wholefile tests 2023-08-17 11:08:50 -07:00
utils.py cleanup inside GitTemporaryDirectory 2023-11-02 16:24:28 -07:00