From f1b61d49e93dc563fa4251e0cf92f9ae15fb3161 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 11 Jul 2023 08:18:39 -0700 Subject: [PATCH] aider: Added a test that creates a temporary directory, initializes a git repository there, adds three empty files, creates a `Coder` object on that directory, and asserts that `coder.get_tracked_files()` returns the three filenames. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Aider chat conversation: USER: make a test which creates a tempdir and inits a git repo there. it should add 3 empty files with the filenames below. the test should create a Coder on that and make sure that coder.get_tracked_files() returns the 3 filenames. Here are the filenames: README.md doc/fänny_dirname/README.md doc/systemüberblick.md ASSISTANT: To create this test, we need to modify the `tests/test_coder.py` file. We will add a new test method named `test_get_tracked_files` in the `TestCoder` class. This method will create a temporary directory, initialize a git repository there, add three empty files, create a `Coder` object on that directory, and assert that `coder.get_tracked_files()` returns the three filenames. Here is the code change: ```python tests/test_coder.py <<<<<<< ORIGINAL if __name__ == "__main__": unittest.main() ======= def test_get_tracked_files(self): # Create a temporary directory tempdir = Path(tempfile.mkdtemp()) # Initialize a git repository in the temporary directory repo = git.Repo.init(tempdir) # Create three empty files and add them to the git repository filenames = ["README.md", "doc/fänny_dirname/README.md", "doc/systemüberblick.md"] for filename in filenames: (tempdir / filename).touch() repo.git.add(filename) # Create a Coder object on the temporary directory coder = Coder.create(models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", root=tempdir) # Assert that coder.get_tracked_files() returns the three filenames self.assertEqual(set(coder.get_tracked_files()), set(filenames)) if __name__ == "__main__": unittest.main() >>>>>>> UPDATED ``` This code assumes that the `Coder` class has a `get_tracked_files` method that returns the filenames of the tracked files in the git repository. If such a method does not exist, it should be implemented in the `Coder` class. --- tests/test_coder.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_coder.py b/tests/test_coder.py index a7fc0fc92..89b1f32ff 100644 --- a/tests/test_coder.py +++ b/tests/test_coder.py @@ -360,5 +360,24 @@ class TestCoder(unittest.TestCase): with self.assertRaises(openai.error.InvalidRequestError): coder.run(with_message="hi") + def test_get_tracked_files(self): + # Create a temporary directory + tempdir = Path(tempfile.mkdtemp()) + + # Initialize a git repository in the temporary directory + repo = git.Repo.init(tempdir) + + # Create three empty files and add them to the git repository + filenames = ["README.md", "doc/fänny_dirname/README.md", "doc/systemüberblick.md"] + for filename in filenames: + (tempdir / filename).touch() + repo.git.add(filename) + + # Create a Coder object on the temporary directory + coder = Coder.create(models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", root=tempdir) + + # Assert that coder.get_tracked_files() returns the three filenames + self.assertEqual(set(coder.get_tracked_files()), set(filenames)) + if __name__ == "__main__": unittest.main()