From 4b91adabdcf3c085d623a6b61f409fd6d6eb6bbe Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 10 Jul 2023 13:19:11 -0700 Subject: [PATCH] aider: The test case has been modified to add files to the directory and ensure they are added correctly. # Aider chat conversation: USER: put some files in the test_dir, and the test shouldn't look for the exception. it should make sure the files were added ASSISTANT: To modify the test case to add files to the directory and ensure they are added correctly, we need to modify the `tests/test_commands.py` file. Here is the proposed change: ```python tests/test_commands.py <<<<<<< ORIGINAL def test_cmd_add_directory(self): # Initialize the Commands and InputOutput objects io = InputOutput(pretty=False, yes=True) from aider.coders import Coder coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef") commands = Commands(io, coder) # Create a directory os.mkdir("test_dir") # Call the cmd_add method with a directory with self.assertRaises(IsADirectoryError): commands.cmd_add("test_dir") ======= def test_cmd_add_directory(self): # Initialize the Commands and InputOutput objects io = InputOutput(pretty=False, yes=True) from aider.coders import Coder coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef") commands = Commands(io, coder) # Create a directory and add files to it os.mkdir("test_dir") with open("test_dir/test_file1.txt", "w") as f: f.write("Test file 1") with open("test_dir/test_file2.txt", "w") as f: f.write("Test file 2") # Call the cmd_add method with a directory commands.cmd_add("test_dir") # Check if the files have been added to the chat session self.assertIn(str(Path("test_dir/test_file1.txt").resolve()), coder.abs_fnames) self.assertIn(str(Path("test_dir/test_file2.txt").resolve()), coder.abs_fnames) >>>>>>> UPDATED ``` This new test case `test_cmd_add_directory` creates a directory named `test_dir`, adds two files to it, and attempts to add the directory using the `cmd_add` method. We then check if the files in the directory have been added to the chat session. --- tests/test_commands.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/test_commands.py b/tests/test_commands.py index 1aa4fcba1..3a2749122 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -87,12 +87,19 @@ class TestCommands(TestCase): coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef") commands = Commands(io, coder) - # Create a directory + # Create a directory and add files to it os.mkdir("test_dir") + with open("test_dir/test_file1.txt", "w") as f: + f.write("Test file 1") + with open("test_dir/test_file2.txt", "w") as f: + f.write("Test file 2") # Call the cmd_add method with a directory - with self.assertRaises(IsADirectoryError): - commands.cmd_add("test_dir") + commands.cmd_add("test_dir") + + # Check if the files have been added to the chat session + self.assertIn(str(Path("test_dir/test_file1.txt").resolve()), coder.abs_fnames) + self.assertIn(str(Path("test_dir/test_file2.txt").resolve()), coder.abs_fnames) def test_cmd_drop_with_glob_patterns(self): # Initialize the Commands and InputOutput objects