From 3b23efa4d8c9e7ea6fcaf0cda57dec4ec658954f Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 28 May 2023 17:01:06 -0700 Subject: [PATCH] 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. --- tests/test_main.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 1dc4d298d..e824e24d4 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -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