mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 12:55:00 +00:00
updated coder test
This commit is contained in:
parent
6fdb4f8214
commit
c99c5db35c
3 changed files with 22 additions and 23 deletions
|
@ -668,9 +668,7 @@ class Coder:
|
||||||
return inp
|
return inp
|
||||||
|
|
||||||
def check_for_urls(self, inp):
|
def check_for_urls(self, inp):
|
||||||
url_pattern = re.compile(
|
url_pattern = re.compile(r"(https?://[^\s/$.?#].[^\s]*[^\s,.])")
|
||||||
r"(https?://[^\s/$.?#].[^\s]*[^\s,.])"
|
|
||||||
)
|
|
||||||
urls = url_pattern.findall(inp)
|
urls = url_pattern.findall(inp)
|
||||||
for url in urls:
|
for url in urls:
|
||||||
if self.io.confirm_ask(f"Add {url} to the chat?"):
|
if self.io.confirm_ask(f"Add {url} to the chat?"):
|
||||||
|
@ -1062,8 +1060,8 @@ class Coder:
|
||||||
mentioned_rel_fnames = set()
|
mentioned_rel_fnames = set()
|
||||||
fname_to_rel_fnames = {}
|
fname_to_rel_fnames = {}
|
||||||
for rel_fname in addable_rel_fnames:
|
for rel_fname in addable_rel_fnames:
|
||||||
normalized_rel_fname = rel_fname.replace('\\', '/')
|
normalized_rel_fname = rel_fname.replace("\\", "/")
|
||||||
normalized_words = set(word.replace('\\', '/') for word in words)
|
normalized_words = set(word.replace("\\", "/") for word in words)
|
||||||
if normalized_rel_fname in normalized_words:
|
if normalized_rel_fname in normalized_words:
|
||||||
mentioned_rel_fnames.add(rel_fname)
|
mentioned_rel_fnames.add(rel_fname)
|
||||||
|
|
||||||
|
@ -1297,9 +1295,10 @@ class Coder:
|
||||||
if not self.repo.is_dirty(path):
|
if not self.repo.is_dirty(path):
|
||||||
return
|
return
|
||||||
|
|
||||||
fullp = Path(self.abs_root_path(path))
|
# We need a committed copy of the file in order to /undo, so skip this
|
||||||
if not fullp.stat().st_size:
|
# fullp = Path(self.abs_root_path(path))
|
||||||
return
|
# if not fullp.stat().st_size:
|
||||||
|
# return
|
||||||
|
|
||||||
self.io.tool_output(f"Committing {path} before applying edits.")
|
self.io.tool_output(f"Committing {path} before applying edits.")
|
||||||
self.need_commit_before_edits.add(path)
|
self.need_commit_before_edits.add(path)
|
||||||
|
|
|
@ -221,11 +221,15 @@ class TestCoder(unittest.TestCase):
|
||||||
# Windows paths in content, Unix paths in get_addable_relative_files
|
# Windows paths in content, Unix paths in get_addable_relative_files
|
||||||
("Check file1.txt and dir\\file2.txt", ["file1.txt", "dir/file2.txt"]),
|
("Check file1.txt and dir\\file2.txt", ["file1.txt", "dir/file2.txt"]),
|
||||||
# Mixed paths in content, Unix paths in get_addable_relative_files
|
# Mixed paths in content, Unix paths in get_addable_relative_files
|
||||||
("Check file1.txt, dir/file2.txt, and other\\file3.txt",
|
(
|
||||||
["file1.txt", "dir/file2.txt", "other/file3.txt"]),
|
"Check file1.txt, dir/file2.txt, and other\\file3.txt",
|
||||||
|
["file1.txt", "dir/file2.txt", "other/file3.txt"],
|
||||||
|
),
|
||||||
# Mixed paths in content, Windows paths in get_addable_relative_files
|
# Mixed paths in content, Windows paths in get_addable_relative_files
|
||||||
("Check file1.txt, dir/file2.txt, and other\\file3.txt",
|
(
|
||||||
["file1.txt", "dir\\file2.txt", "other\\file3.txt"]),
|
"Check file1.txt, dir/file2.txt, and other\\file3.txt",
|
||||||
|
["file1.txt", "dir\\file2.txt", "other\\file3.txt"],
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
for content, addable_files in test_cases:
|
for content, addable_files in test_cases:
|
||||||
|
@ -233,8 +237,11 @@ class TestCoder(unittest.TestCase):
|
||||||
coder.get_addable_relative_files = MagicMock(return_value=set(addable_files))
|
coder.get_addable_relative_files = MagicMock(return_value=set(addable_files))
|
||||||
mentioned_files = coder.get_file_mentions(content)
|
mentioned_files = coder.get_file_mentions(content)
|
||||||
expected_files = set(addable_files)
|
expected_files = set(addable_files)
|
||||||
self.assertEqual(mentioned_files, expected_files,
|
self.assertEqual(
|
||||||
f"Failed for content: {content}, addable_files: {addable_files}")
|
mentioned_files,
|
||||||
|
expected_files,
|
||||||
|
f"Failed for content: {content}, addable_files: {addable_files}",
|
||||||
|
)
|
||||||
|
|
||||||
def test_run_with_file_deletion(self):
|
def test_run_with_file_deletion(self):
|
||||||
# Create a few temporary files
|
# Create a few temporary files
|
||||||
|
@ -361,7 +368,7 @@ class TestCoder(unittest.TestCase):
|
||||||
self.assertEqual(len(coder.abs_fnames), 2)
|
self.assertEqual(len(coder.abs_fnames), 2)
|
||||||
|
|
||||||
def test_new_file_edit_one_commit(self):
|
def test_new_file_edit_one_commit(self):
|
||||||
"""A new file shouldn't get pre-committed before the GPT edit commit"""
|
"""A new file should get pre-committed before the GPT edit commit"""
|
||||||
with GitTemporaryDirectory():
|
with GitTemporaryDirectory():
|
||||||
repo = git.Repo()
|
repo = git.Repo()
|
||||||
|
|
||||||
|
@ -400,7 +407,7 @@ new
|
||||||
self.assertEqual(content, "new\n")
|
self.assertEqual(content, "new\n")
|
||||||
|
|
||||||
num_commits = len(list(repo.iter_commits(repo.active_branch.name)))
|
num_commits = len(list(repo.iter_commits(repo.active_branch.name)))
|
||||||
self.assertEqual(num_commits, 1)
|
self.assertEqual(num_commits, 2)
|
||||||
|
|
||||||
def test_only_commit_gpt_edited_file(self):
|
def test_only_commit_gpt_edited_file(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -621,13 +621,6 @@ class TestCommands(TestCase):
|
||||||
self.assertEqual(last_commit_hash, repo.head.commit.hexsha[:7])
|
self.assertEqual(last_commit_hash, repo.head.commit.hexsha[:7])
|
||||||
self.assertTrue(file_path.exists())
|
self.assertTrue(file_path.exists())
|
||||||
|
|
||||||
# Check that an error message was displayed
|
|
||||||
self.assertIn("This is the first commit in the repository. Cannot undo.", io.get_last_error())
|
|
||||||
|
|
||||||
# Check that the last commit is still present
|
|
||||||
self.assertEqual(last_commit_hash, repo.head.commit.hexsha[:7])
|
|
||||||
self.assertTrue(file_path.exists())
|
|
||||||
|
|
||||||
del coder
|
del coder
|
||||||
del commands
|
del commands
|
||||||
del repo
|
del repo
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue