From f2a116e0e1df4e568e9ef92521a4685e8c183243 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 28 May 2023 17:06:09 -0700 Subject: [PATCH] aider: Added test method `test_check_for_ctags_failure` that patches `subprocess.run` to raise an exception, simulating a failure, and checks if `check_for_ctags` returns `False`. # Context: USER: in tests/test_repomap.py add a test for check_for_ctags which patches subprocess to fail. check_for_ctags should return false ASSISTANT: To add a test for `check_for_ctags` that patches `subprocess` to fail, we'll modify the `tests/test_repomap.py` file. We'll use the `unittest.mock` library to patch the `subprocess.run` function to simulate a failure. Here's the change: ```python tests/test_repomap.py <<<<<<< ORIGINAL def test_get_tags_map_without_ctags(self): ======= from unittest.mock import patch def test_check_for_ctags_failure(self): with patch("subprocess.run") as mock_run: mock_run.side_effect = Exception("ctags not found") repo_map = RepoMap(use_ctags=True) result = repo_map.check_for_ctags() self.assertFalse(result) def test_get_tags_map_without_ctags(self): >>>>>>> UPDATED ``` This adds a new test method `test_check_for_ctags_failure` that patches `subprocess.run` to raise an exception, simulating a failure. The test then checks if `check_for_ctags` returns `False`. --- tests/test_repomap.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_repomap.py b/tests/test_repomap.py index aa7e10b36..55c3b6852 100644 --- a/tests/test_repomap.py +++ b/tests/test_repomap.py @@ -55,6 +55,15 @@ def my_function(arg1, arg2): self.assertIn("my_method", result) self.assertIn("my_function", result) + from unittest.mock import patch + + def test_check_for_ctags_failure(self): + with patch("subprocess.run") as mock_run: + mock_run.side_effect = Exception("ctags not found") + repo_map = RepoMap(use_ctags=True) + result = repo_map.check_for_ctags() + self.assertFalse(result) + def test_get_tags_map_without_ctags(self): # Create a temporary directory with a sample Python file containing identifiers test_files = [