mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 00:35:00 +00:00
feat: Add a new source file and update the RepoMap test
This commit is contained in:
parent
78a4ed69d8
commit
d875e7ebe0
1 changed files with 13 additions and 10 deletions
|
@ -49,11 +49,14 @@ class TestRepoMap(unittest.TestCase):
|
||||||
# Create two source files with one function each
|
# Create two source files with one function each
|
||||||
file1_content = "def function1():\n return 'Hello from file1'\n"
|
file1_content = "def function1():\n return 'Hello from file1'\n"
|
||||||
file2_content = "def function2():\n return 'Hello from file2'\n"
|
file2_content = "def function2():\n return 'Hello from file2'\n"
|
||||||
|
file3_content = "def function3():\n return 'Hello from file3'\n"
|
||||||
|
|
||||||
with open(os.path.join(temp_dir, "file1.py"), "w") as f:
|
with open(os.path.join(temp_dir, "file1.py"), "w") as f:
|
||||||
f.write(file1_content)
|
f.write(file1_content)
|
||||||
with open(os.path.join(temp_dir, "file2.py"), "w") as f:
|
with open(os.path.join(temp_dir, "file2.py"), "w") as f:
|
||||||
f.write(file2_content)
|
f.write(file2_content)
|
||||||
|
with open(os.path.join(temp_dir, "file3.py"), "w") as f:
|
||||||
|
f.write(file3_content)
|
||||||
|
|
||||||
# Add files to git
|
# Add files to git
|
||||||
repo.index.add(["file1.py", "file2.py"])
|
repo.index.add(["file1.py", "file2.py"])
|
||||||
|
@ -62,30 +65,30 @@ class TestRepoMap(unittest.TestCase):
|
||||||
# Initialize RepoMap with refresh="files" and one source file
|
# Initialize RepoMap with refresh="files" and one source file
|
||||||
io = InputOutput()
|
io = InputOutput()
|
||||||
repo_map = RepoMap(main_model=self.GPT35, root=temp_dir, io=io, refresh="files")
|
repo_map = RepoMap(main_model=self.GPT35, root=temp_dir, io=io, refresh="files")
|
||||||
chat_files = [os.path.join(temp_dir, "file1.py")]
|
chat_files = [os.path.join(temp_dir, "file2.py")]
|
||||||
other_files = [os.path.join(temp_dir, "file2.py")]
|
other_files = [os.path.join(temp_dir, "file1.py"), os.path.join(temp_dir, "file3.py")]
|
||||||
|
|
||||||
# Get initial repo map
|
# Get initial repo map
|
||||||
initial_map = repo_map.get_repo_map(chat_files, other_files)
|
initial_map = repo_map.get_repo_map(chat_files, other_files)
|
||||||
self.assertIn("function1", initial_map)
|
dump(initial_map)
|
||||||
self.assertNotIn("function2", initial_map)
|
self.assertNotIn("function2", initial_map)
|
||||||
|
|
||||||
# Add a 2nd function to file1.py
|
# Add a 2nd function to file1.py
|
||||||
with open(os.path.join(temp_dir, "file1.py"), "a") as f:
|
with open(os.path.join(temp_dir, "file1.py"), "w") as f:
|
||||||
f.write("\ndef function3():\n return 'Hello from function3'\n")
|
f.write("\ndef functionNEW():\n return 'Hello NEW'\n")
|
||||||
|
|
||||||
# Get another repo map
|
# Get another repo map
|
||||||
second_map = repo_map.get_repo_map(chat_files, other_files)
|
second_map = repo_map.get_repo_map(chat_files, other_files)
|
||||||
self.assertEqual(initial_map, second_map, "RepoMap should not change without refresh")
|
self.assertEqual(initial_map, second_map, "RepoMap should not change without refresh")
|
||||||
|
|
||||||
# Add the 2nd file to the chat
|
# Add the 2nd file to the chat
|
||||||
chat_files.append(os.path.join(temp_dir, "file2.py"))
|
chat_files = [os.path.join(temp_dir, "file2.py"), os.path.join(temp_dir, "file3.py")]
|
||||||
|
other_files = [os.path.join(temp_dir, "file1.py")]
|
||||||
|
|
||||||
# Get a new repo map
|
# Get a new repo map
|
||||||
final_map = repo_map.get_repo_map(chat_files, [])
|
final_map = repo_map.get_repo_map(chat_files, other_files)
|
||||||
self.assertIn("function1", final_map)
|
dump(final_map)
|
||||||
self.assertIn("function2", final_map)
|
self.assertIn("functionNEW", final_map)
|
||||||
self.assertIn("function3", final_map)
|
|
||||||
|
|
||||||
# close the open cache files, so Windows won't error
|
# close the open cache files, so Windows won't error
|
||||||
del repo_map
|
del repo_map
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue