From 5a61e6acd2b49cc84cd20865aadf0395855f5601 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 4 Jun 2023 14:15:25 -0700 Subject: [PATCH] aider: Added a new file that imports MyClass and calls both its methods to test_get_repo_map_with_identifiers. # Context: USER: in `test_get_repo_map_with_identifiers` make a 2nd file that imports MyClass and calls both its methods. add that to `other_files` ASSISTANT: Here are the changes you need to make: 1. Modify `test_get_repo_map_with_identifiers` in `tests/test_repomap.py` to add a new file that imports `MyClass` and calls both its methods: ```python tests/test_repomap.py <<<<<<< ORIGINAL def test_get_repo_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), os.path.join(temp_dir, "test_file_import.py")] result = repo_map.get_repo_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) ======= def test_get_repo_map_with_identifiers(self): # Create a temporary directory with a sample Python file containing identifiers test_file1 = "test_file_with_identifiers.py" file_content1 = """\ class MyClass: def my_method(self, arg1, arg2): return arg1 + arg2 def my_function(arg1, arg2): return arg1 * arg2 """ test_file2 = "test_file_import.py" file_content2 = """\ from test_file_with_identifiers import MyClass obj = MyClass() print(obj.my_method(1, 2)) print(my_function(3, 4)) """ with tempfile.TemporaryDirectory() as temp_dir: with open(os.path.join(temp_dir, test_file1), "w") as f: f.write(file_content1) with open(os.path.join(temp_dir, test_file2), "w") as f: f.write(file_content2) repo_map = RepoMap(root=temp_dir) other_files = [os.path.join(temp_dir, test_file1), os.path.join(temp_dir, test_file2)] result = repo_map.get_repo_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) >>>>>>> UPDATED ``` 2. Run the tests to make sure everything is working as expected. --- tests/test_repomap.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/test_repomap.py b/tests/test_repomap.py index e0c08b414..b1e6dcea3 100644 --- a/tests/test_repomap.py +++ b/tests/test_repomap.py @@ -34,8 +34,8 @@ class TestRepoMap(unittest.TestCase): def test_get_repo_map_with_identifiers(self): # Create a temporary directory with a sample Python file containing identifiers - test_file = "test_file_with_identifiers.py" - file_content = """\ + test_file1 = "test_file_with_identifiers.py" + file_content1 = """\ class MyClass: def my_method(self, arg1, arg2): return arg1 + arg2 @@ -44,12 +44,24 @@ def my_function(arg1, arg2): return arg1 * arg2 """ + test_file2 = "test_file_import.py" + file_content2 = """\ +from test_file_with_identifiers import MyClass + +obj = MyClass() +print(obj.my_method(1, 2)) +print(my_function(3, 4)) +""" + with tempfile.TemporaryDirectory() as temp_dir: - with open(os.path.join(temp_dir, test_file), "w") as f: - f.write(file_content) + with open(os.path.join(temp_dir, test_file1), "w") as f: + f.write(file_content1) + + with open(os.path.join(temp_dir, test_file2), "w") as f: + f.write(file_content2) repo_map = RepoMap(root=temp_dir) - other_files = [os.path.join(temp_dir, test_file)] + other_files = [os.path.join(temp_dir, test_file1), os.path.join(temp_dir, test_file2)] result = repo_map.get_repo_map([], other_files) # Check if the result contains the expected tags map with identifiers @@ -57,7 +69,6 @@ def my_function(arg1, arg2): self.assertIn("MyClass", result) self.assertIn("my_method", result) self.assertIn("my_function", result) - def test_check_for_ctags_failure(self): with patch("subprocess.run") as mock_run: mock_run.side_effect = Exception("ctags not found")