updated coder test

This commit is contained in:
Paul Gauthier 2024-07-18 16:35:27 +01:00
parent 6fdb4f8214
commit c99c5db35c
3 changed files with 22 additions and 23 deletions

View file

@ -668,9 +668,7 @@ class Coder:
return inp
def check_for_urls(self, inp):
url_pattern = re.compile(
r"(https?://[^\s/$.?#].[^\s]*[^\s,.])"
)
url_pattern = re.compile(r"(https?://[^\s/$.?#].[^\s]*[^\s,.])")
urls = url_pattern.findall(inp)
for url in urls:
if self.io.confirm_ask(f"Add {url} to the chat?"):
@ -1062,8 +1060,8 @@ class Coder:
mentioned_rel_fnames = set()
fname_to_rel_fnames = {}
for rel_fname in addable_rel_fnames:
normalized_rel_fname = rel_fname.replace('\\', '/')
normalized_words = set(word.replace('\\', '/') for word in words)
normalized_rel_fname = rel_fname.replace("\\", "/")
normalized_words = set(word.replace("\\", "/") for word in words)
if normalized_rel_fname in normalized_words:
mentioned_rel_fnames.add(rel_fname)
@ -1297,9 +1295,10 @@ class Coder:
if not self.repo.is_dirty(path):
return
fullp = Path(self.abs_root_path(path))
if not fullp.stat().st_size:
return
# We need a committed copy of the file in order to /undo, so skip this
# fullp = Path(self.abs_root_path(path))
# if not fullp.stat().st_size:
# return
self.io.tool_output(f"Committing {path} before applying edits.")
self.need_commit_before_edits.add(path)

View file

@ -221,11 +221,15 @@ class TestCoder(unittest.TestCase):
# Windows paths in content, Unix paths in get_addable_relative_files
("Check file1.txt and dir\\file2.txt", ["file1.txt", "dir/file2.txt"]),
# 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
("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:
@ -233,8 +237,11 @@ class TestCoder(unittest.TestCase):
coder.get_addable_relative_files = MagicMock(return_value=set(addable_files))
mentioned_files = coder.get_file_mentions(content)
expected_files = set(addable_files)
self.assertEqual(mentioned_files, expected_files,
f"Failed for content: {content}, addable_files: {addable_files}")
self.assertEqual(
mentioned_files,
expected_files,
f"Failed for content: {content}, addable_files: {addable_files}",
)
def test_run_with_file_deletion(self):
# Create a few temporary files
@ -361,7 +368,7 @@ class TestCoder(unittest.TestCase):
self.assertEqual(len(coder.abs_fnames), 2)
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():
repo = git.Repo()
@ -400,7 +407,7 @@ new
self.assertEqual(content, "new\n")
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):
"""

View file

@ -621,13 +621,6 @@ class TestCommands(TestCase):
self.assertEqual(last_commit_hash, repo.head.commit.hexsha[:7])
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 commands
del repo