aider: Changed test_main_with_ctags_mocked_failure to run within a temporary directory.

# Context:
USER: we need to cwd into a temp dir before the test
ASSISTANT: To change the working directory to a temporary directory before running the test, you can use the `tempfile.TemporaryDirectory()` context manager in the `test_main_with_ctags_mocked_failure` method. Here's the updated code for `tests/test_main.py`:

```python
tests/test_main.py
<<<<<<< ORIGINAL
    def test_main_with_ctags_mocked_failure(self):
        with patch("subprocess.run", side_effect=subprocess.CalledProcessError(1, "ctags")):
            with patch("aider.main.Coder") as MockCoder:
                main(["--ctags"])
                _, kwargs = MockCoder.call_args
                assert kwargs["use_ctags"] is False
=======
    def test_main_with_ctags_mocked_failure(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            with patch("subprocess.run", side_effect=subprocess.CalledProcessError(1, "ctags")):
                with patch("aider.main.Coder") as MockCoder:
                    main(["--ctags"])
                    _, kwargs = MockCoder.call_args
                    assert kwargs["use_ctags"] is False
>>>>>>> UPDATED
```

This change will ensure that the test is run within a temporary directory.
This commit is contained in:
Paul Gauthier 2023-05-28 17:01:06 -07:00
parent 640479dafb
commit 3b23efa4d8

View file

@ -82,8 +82,10 @@ class TestMain(TestCase):
assert kwargs["dirty_commits"] is True
def test_main_with_ctags_mocked_failure(self):
with patch("subprocess.run", side_effect=subprocess.CalledProcessError(1, "ctags")):
with patch("aider.main.Coder") as MockCoder:
main(["--ctags"])
_, kwargs = MockCoder.call_args
assert kwargs["use_ctags"] is False
with tempfile.TemporaryDirectory() as temp_dir:
os.chdir(temp_dir)
with patch("subprocess.run", side_effect=subprocess.CalledProcessError(1, "ctags")):
with patch("aider.main.Coder") as MockCoder:
main(["--ctags"])
_, kwargs = MockCoder.call_args
assert kwargs["use_ctags"] is False