From 8f2447078cbea7f44a74bd6792b97cc91d699cd8 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 24 May 2023 19:01:02 -0700 Subject: [PATCH] aider: Added a new test to check if the `get_tags_map` function returns the expected tags map containing the identifiers from a Python file. # Context: USER: add another test. pass in a python file which defines a few identifiers. make sure they appear in the map. ASSISTANT: I will add a new test to the `tests/test_repomap.py` file that checks if the identifiers from a Python file appear in the map. ```python tests/test_repomap.py <<<<<<< ORIGINAL self.assertNotIn("test_file4.json:", result) if __name__ == "__main__": unittest.main() ======= self.assertNotIn("test_file4.json:", result) def test_get_tags_map_with_identifiers(self): # Create a temporary directory with a sample Python file containing identifiers test_file = "test_file_with_identifiers.py" file_content = """\ class MyClass: def my_method(self, arg1, arg2): return arg1 + arg2 def my_function(arg1, arg2): return arg1 * arg2 """ with tempfile.TemporaryDirectory() as temp_dir: with open(os.path.join(temp_dir, test_file), "w") as f: f.write(file_content) repo_map = RepoMap(root=temp_dir) other_files = [os.path.join(temp_dir, test_file)] result = repo_map.get_tags_map(other_files) # Check if the result contains the expected tags map with identifiers self.assertIn("test_file_with_identifiers.py:", result) self.assertIn("MyClass", result) self.assertIn("my_method", result) self.assertIn("my_function", result) if __name__ == "__main__": unittest.main() >>>>>>> UPDATED ``` This new test creates a temporary directory with a sample Python file containing a class, a method, and a function. It then checks if the `get_tags_map` function returns the expected tags map containing the identifiers from the Python file. --- tests/test_repomap.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_repomap.py b/tests/test_repomap.py index b7473daeb..2d4d00ce9 100644 --- a/tests/test_repomap.py +++ b/tests/test_repomap.py @@ -28,5 +28,31 @@ class TestRepoMap(unittest.TestCase): self.assertNotIn("test_file3.md:", result) self.assertNotIn("test_file4.json:", result) + def test_get_tags_map_with_identifiers(self): + # Create a temporary directory with a sample Python file containing identifiers + test_file = "test_file_with_identifiers.py" + file_content = """\ +class MyClass: + def my_method(self, arg1, arg2): + return arg1 + arg2 + +def my_function(arg1, arg2): + return arg1 * arg2 +""" + + with tempfile.TemporaryDirectory() as temp_dir: + with open(os.path.join(temp_dir, test_file), "w") as f: + f.write(file_content) + + repo_map = RepoMap(root=temp_dir) + other_files = [os.path.join(temp_dir, test_file)] + result = repo_map.get_tags_map(other_files) + + # Check if the result contains the expected tags map with identifiers + self.assertIn("test_file_with_identifiers.py:", result) + self.assertIn("MyClass", result) + self.assertIn("my_method", result) + self.assertIn("my_function", result) + if __name__ == "__main__": unittest.main()