From 2b07e2de3010c4dfb0a79184ba054a0762f6344e Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 5 Jul 2023 21:35:09 -0700 Subject: [PATCH] aider: Add a test for cmd_add where nothing matches. # Context: USER: add a test for cmd_add where nothing matches ASSISTANT: To add a test for the `cmd_add` method where nothing matches, we need to modify the `tests/test_commands.py` file. Here's the step-by-step process: 1. Add a new test method `test_cmd_add_no_match` in the `TestCommands` class. 2. In this method, initialize the `Commands` and `InputOutput` objects. 3. Call the `cmd_add` method with a non-existent file pattern. 4. Check if no files have been added to the chat session. Here's the code change: ```python tests/test_commands.py <<<<<<< ORIGINAL def test_cmd_add_with_glob_patterns(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 some test files with open("test1.py", "w") as f: f.write("print('test1')") with open("test2.py", "w") as f: f.write("print('test2')") with open("test.txt", "w") as f: f.write("test") # Call the cmd_add method with a glob pattern commands.cmd_add("*.py") # Check if the Python files have been added to the chat session self.assertIn(os.path.abspath("test1.py"), coder.abs_fnames) self.assertIn(os.path.abspath("test2.py"), coder.abs_fnames) # Check if the text file has not been added to the chat session self.assertNotIn(os.path.abspath("test.txt"), coder.abs_fnames) ======= def test_cmd_add_with_glob_patterns(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 some test files with open("test1.py", "w") as f: f.write("print('test1')") with open("test2.py", "w") as f: f.write("print('test2')") with open("test.txt", "w") as f: f.write("test") # Call the cmd_add method with a glob pattern commands.cmd_add("*.py") # Check if the Python files have been added to the chat session self.assertIn(os.path.abspath("test1.py"), coder.abs_fnames) self.assertIn(os.path.abspath("test2.py"), coder.abs_fnames) # Check if the text file has not been added to the chat session self.assertNotIn(os.path.abspath("test.txt"), coder.abs_fnames) def test_cmd_add_no_match(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) # Call the cmd_add method with a non-existent file pattern commands.cmd_add("*.nonexistent") # Check if no files have been added to the chat session self.assertEqual(len(coder.abs_fnames), 0) >>>>>>> UPDATED ``` Please let me know if you need any further changes. --- tests/test_commands.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_commands.py b/tests/test_commands.py index 6217b5cbb..71739395c 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -43,3 +43,17 @@ class TestCommands(TestCase): # Check if the text file has not been added to the chat session self.assertNotIn(os.path.abspath("test.txt"), coder.abs_fnames) + + def test_cmd_add_no_match(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) + + # Call the cmd_add method with a non-existent file pattern + commands.cmd_add("*.nonexistent") + + # Check if no files have been added to the chat session + self.assertEqual(len(coder.abs_fnames), 0)