From 6ead145c174fca8a488b893d406161ccbe259f4f Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 28 May 2023 17:07:49 -0700 Subject: [PATCH] aider: Added test method `test_check_for_ctags_success` that patches `subprocess.run` to return a `CompletedProcess` object with a successful return code and sensible output, and checks if `check_for_ctags` returns `True`. # Context: USER: add another like that, but the patched subprocess should return sensible output for get_tags ASSISTANT: To add another test for `check_for_ctags` that patches `subprocess` to return sensible output for `get_tags`, 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 successful execution. Here's the change: ```python tests/test_repomap.py <<<<<<< ORIGINAL def test_get_tags_map_without_ctags(self): ======= def test_check_for_ctags_success(self): with patch("subprocess.run") as mock_run: mock_run.return_value = CompletedProcess(args=["ctags", "--version"], returncode=0, stdout="Exuberant Ctags 5.8") repo_map = RepoMap(use_ctags=True) result = repo_map.check_for_ctags() self.assertTrue(result) def test_get_tags_map_without_ctags(self): >>>>>>> UPDATED ``` This adds a new test method `test_check_for_ctags_success` that patches `subprocess.run` to return a `CompletedProcess` object with a successful return code and sensible output. The test then checks if `check_for_ctags` returns `True`. --- tests/test_repomap.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_repomap.py b/tests/test_repomap.py index c536cb641..1abe7fecb 100644 --- a/tests/test_repomap.py +++ b/tests/test_repomap.py @@ -62,6 +62,13 @@ def my_function(arg1, arg2): result = repo_map.check_for_ctags() self.assertFalse(result) + def test_check_for_ctags_success(self): + with patch("subprocess.run") as mock_run: + mock_run.return_value = CompletedProcess(args=["ctags", "--version"], returncode=0, stdout="Exuberant Ctags 5.8") + repo_map = RepoMap(use_ctags=True) + result = repo_map.check_for_ctags() + self.assertTrue(result) + def test_get_tags_map_without_ctags(self): # Create a temporary directory with a sample Python file containing identifiers test_files = [