From c99c5db35caf4f147cfe256cd00a13905d0de1fa Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 18 Jul 2024 16:35:27 +0100 Subject: [PATCH] updated coder test --- aider/coders/base_coder.py | 15 +++++++-------- tests/basic/test_coder.py | 23 +++++++++++++++-------- tests/basic/test_commands.py | 7 ------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index d9180727a..21d951493 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -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) diff --git a/tests/basic/test_coder.py b/tests/basic/test_coder.py index 35f99c501..730eb88da 100644 --- a/tests/basic/test_coder.py +++ b/tests/basic/test_coder.py @@ -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): """ diff --git a/tests/basic/test_commands.py b/tests/basic/test_commands.py index abbcfecfc..eb4bff023 100644 --- a/tests/basic/test_commands.py +++ b/tests/basic/test_commands.py @@ -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