From 437300613747559eb6c91a2665f3d974a64c5072 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 4 Jul 2023 12:37:23 -0700 Subject: [PATCH] aider: Added a test for `AutoCompleter` that passes in a non-existent file and checks that `self.words` is an empty set. # Context: USER: add a test for `AutoCompleter` that passes in a non-existant file. make sure self.words is empty. ASSISTANT: To add a test for `AutoCompleter` that passes in a non-existent file, we need to modify the `tests/test_io.py` file. We will add a new test method `test_autocompleter_with_non_existent_file` in the `TestInputOutput` class. Here is the change: ```python tests/test_io.py <<<<<<< ORIGINAL import os import unittest from unittest.mock import patch from aider.io import InputOutput class TestInputOutput(unittest.TestCase): def test_no_color_environment_variable(self): with patch.dict(os.environ, {"NO_COLOR": "1"}): io = InputOutput() self.assertFalse(io.pretty) if __name__ == "__main__": unittest.main() ======= import os import unittest from unittest.mock import patch from aider.io import InputOutput, AutoCompleter class TestInputOutput(unittest.TestCase): def test_no_color_environment_variable(self): with patch.dict(os.environ, {"NO_COLOR": "1"}): io = InputOutput() self.assertFalse(io.pretty) def test_autocompleter_with_non_existent_file(self): root = "" rel_fnames = ["non_existent_file"] addable_rel_fnames = [] commands = None autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands) self.assertEqual(autocompleter.words, set()) if __name__ == "__main__": unittest.main() >>>>>>> UPDATED ``` This new test creates an instance of `AutoCompleter` with a non-existent file and checks that `self.words` is an empty set. --- tests/test_io.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_io.py b/tests/test_io.py index dfc3806ff..6863384a4 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -2,7 +2,7 @@ import os import unittest from unittest.mock import patch -from aider.io import InputOutput +from aider.io import InputOutput, AutoCompleter class TestInputOutput(unittest.TestCase): @@ -11,6 +11,14 @@ class TestInputOutput(unittest.TestCase): io = InputOutput() self.assertFalse(io.pretty) + def test_autocompleter_with_non_existent_file(self): + root = "" + rel_fnames = ["non_existent_file"] + addable_rel_fnames = [] + commands = None + autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands) + self.assertEqual(autocompleter.words, set()) + if __name__ == "__main__": unittest.main()