From 0fc40df8e6a172931e28e03bcf141b49058fbb11 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 27 May 2023 08:26:16 -0700 Subject: [PATCH] aider: Replaced manual setting of `abs_fnames` with a mocked `git.Repo` object that has its `ls_files` method return the desired file paths. # Context: USER: don't set the files in abs_fnames. patch self.repo.git.ls_files to return them ASSISTANT: To patch `self.repo.git.ls_files` to return the files in `abs_fnames`, we will modify the `test_check_for_file_mentions` function in the `tests/test_coder.py` file. ```python tests/test_coder.py <<<<<<< ORIGINAL # Initialize the Coder object with the mocked IO coder = Coder(io=mock_io, openai_api_key="fake_key") # Add sample files to the Coder object coder.abs_fnames = { "/path/to/repo/file1.txt", "/path/to/repo/file2.py", } coder.root = "/path/to/repo" ======= # Mock the git repo mock_repo = MagicMock() mock_repo.git.ls_files.return_value = "file1.txt\nfile2.py" # Initialize the Coder object with the mocked IO and mocked repo coder = Coder(io=mock_io, openai_api_key="fake_key", repo=mock_repo) coder.root = "/path/to/repo" >>>>>>> UPDATED ``` This change replaces the manual setting of `abs_fnames` with a mocked `git.Repo` object that has its `ls_files` method return the desired file paths. --- tests/test_coder.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/test_coder.py b/tests/test_coder.py index e6b43c269..e39571645 100644 --- a/tests/test_coder.py +++ b/tests/test_coder.py @@ -9,14 +9,12 @@ class TestCoder(unittest.TestCase): mock_io.get_input.return_value = "Please check file1.txt and file2.py" mock_io.confirm_ask.return_value = True - # Initialize the Coder object with the mocked IO - coder = Coder(io=mock_io, openai_api_key="fake_key") + # Mock the git repo + mock_repo = MagicMock() + mock_repo.git.ls_files.return_value = "file1.txt\nfile2.py" - # Add sample files to the Coder object - coder.abs_fnames = { - "/path/to/repo/file1.txt", - "/path/to/repo/file2.py", - } + # Initialize the Coder object with the mocked IO and mocked repo + coder = Coder(io=mock_io, openai_api_key="fake_key", repo=mock_repo) coder.root = "/path/to/repo" # Call the check_for_file_mentions method