mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-23 05:45:00 +00:00
aider: Changed the way subprocess.run
is mocked in test_check_for_ctags_success
to return different results for each call.
# Context: USER: in `test_check_for_ctags_success` we need to mock `subprocess`.run differently. it will be called twice and needs to return different results for each call. ASSISTANT: To modify the `test_check_for_ctags_success` method in the `tests/test_repomap.py` file, we need to change the way `subprocess.run` is mocked. It will be called twice and needs to return different results for each call. Here are the steps to make the changes: 1. Import `MagicMock` from `unittest.mock`. 2. Replace the `mock_run.return_value` with `mock_run.side_effect` which is a list of `CompletedProcess` objects. The first one simulates a successful call to `ctags --version` and the second one simulates a successful call to `ctags -R`. Here is the *edit block* for the changes: ```python tests/test_repomap.py <<<<<<< ORIGINAL from unittest.mock import patch from subprocess import CompletedProcess 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=( b'{"_type": "tag", "name": "status", "path": "aider/main.py", "pattern": "/^ ' b' status = main()$/", "kind": "variable"}' ), ) repo_map = RepoMap() result = repo_map.check_for_ctags() self.assertTrue(result) ======= from unittest.mock import patch, MagicMock from subprocess import CompletedProcess def test_check_for_ctags_success(self): with patch("subprocess.run") as mock_run: mock_run.side_effect = [ CompletedProcess( args=["ctags", "--version"], returncode=0, stdout=b"Universal Ctags 0.0.0(f25b4bb7)", ), CompletedProcess( args=["ctags", "-R"], returncode=0, stdout=b"", ), ] repo_map = RepoMap() result = repo_map.check_for_ctags() self.assertTrue(result) >>>>>>> UPDATED ``` This change will make the `test_check_for_ctags_success` method simulate two calls to `subprocess.run` with different results.
This commit is contained in:
parent
1f16b15f92
commit
1b57a395d2
1 changed files with 18 additions and 12 deletions
|
@ -88,20 +88,26 @@ print(my_function(3, 4))
|
||||||
result = repo_map.check_for_ctags()
|
result = repo_map.check_for_ctags()
|
||||||
self.assertFalse(result)
|
self.assertFalse(result)
|
||||||
|
|
||||||
|
from unittest.mock import patch, MagicMock
|
||||||
|
from subprocess import CompletedProcess
|
||||||
|
|
||||||
def test_check_for_ctags_success(self):
|
def test_check_for_ctags_success(self):
|
||||||
with patch("subprocess.run") as mock_run:
|
with patch("subprocess.run") as mock_run:
|
||||||
mock_run.return_value = CompletedProcess(
|
mock_run.side_effect = [
|
||||||
|
CompletedProcess(
|
||||||
args=["ctags", "--version"],
|
args=["ctags", "--version"],
|
||||||
returncode=0,
|
returncode=0,
|
||||||
stdout=(
|
stdout=b"Universal Ctags 0.0.0(f25b4bb7)",
|
||||||
b'{"_type": "tag", "name": "status", "path": "aider/main.py", "pattern": "/^ '
|
|
||||||
b' status = main()$/", "kind": "variable"}'
|
|
||||||
),
|
),
|
||||||
)
|
CompletedProcess(
|
||||||
|
args=["ctags", "-R"],
|
||||||
|
returncode=0,
|
||||||
|
stdout=b"",
|
||||||
|
),
|
||||||
|
]
|
||||||
repo_map = RepoMap()
|
repo_map = RepoMap()
|
||||||
result = repo_map.check_for_ctags()
|
result = repo_map.check_for_ctags()
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
|
|
||||||
def test_get_repo_map_without_ctags(self):
|
def test_get_repo_map_without_ctags(self):
|
||||||
# Create a temporary directory with a sample Python file containing identifiers
|
# Create a temporary directory with a sample Python file containing identifiers
|
||||||
test_files = [
|
test_files = [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue