Skip to content

Commit

Permalink
fix: Pass dividers to find_original_update_locks in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Oct 5, 2024
1 parent 2029a0c commit 3da8b4c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Define edit block dividers as class attributes to enable easier experimentation.

# Release history

Expand Down
48 changes: 38 additions & 10 deletions tests/basic/test_editblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ def test_find_original_update_blocks(self):
Hope you like it!
"""

edits = list(eb.find_original_update_blocks(edit))
edits = list(
eb.find_original_update_blocks(edit, **eb.EditBlockCoder.edit_block_config)
)
self.assertEqual(edits, [("foo.txt", "Two\n", "Tooooo\n")])

def test_find_original_update_blocks_mangled_filename_w_source_tag(self):
Expand All @@ -127,7 +129,11 @@ def test_find_original_update_blocks_mangled_filename_w_source_tag(self):
fence = ("<%s>" % source, "</%s>" % source)

with self.assertRaises(ValueError) as cm:
_edits = list(eb.find_original_update_blocks(edit, fence))
_edits = list(
eb.find_original_update_blocks(
edit, fence, **eb.EditBlockCoder.edit_block_config
)
)
self.assertIn("missing filename", str(cm.exception))

def test_find_original_update_blocks_quote_below_filename(self):
Expand All @@ -146,7 +152,9 @@ def test_find_original_update_blocks_quote_below_filename(self):
Hope you like it!
"""

edits = list(eb.find_original_update_blocks(edit))
edits = list(
eb.find_original_update_blocks(edit, **eb.EditBlockCoder.edit_block_config)
)
self.assertEqual(edits, [("foo.txt", "Two\n", "Tooooo\n")])

def test_find_original_update_blocks_unclosed(self):
Expand All @@ -165,7 +173,11 @@ def test_find_original_update_blocks_unclosed(self):
"""

with self.assertRaises(ValueError) as cm:
list(eb.find_original_update_blocks(edit))
list(
eb.find_original_update_blocks(
edit, **eb.EditBlockCoder.edit_block_config
)
)
self.assertIn("Expected `>>>>>>> REPLACE` or `=======`", str(cm.exception))

def test_find_original_update_blocks_missing_filename(self):
Expand All @@ -183,7 +195,11 @@ def test_find_original_update_blocks_missing_filename(self):
"""

with self.assertRaises(ValueError) as cm:
list(eb.find_original_update_blocks(edit))
list(
eb.find_original_update_blocks(
edit, **eb.EditBlockCoder.edit_block_config
)
)
self.assertIn("filename", str(cm.exception))

def test_find_original_update_blocks_no_final_newline(self):
Expand Down Expand Up @@ -219,7 +235,9 @@ def test_find_original_update_blocks_no_final_newline(self):
>>>>>>> REPLACE"""

# Should not raise a ValueError
list(eb.find_original_update_blocks(edit))
list(
eb.find_original_update_blocks(edit, **eb.EditBlockCoder.edit_block_config)
)

def test_incomplete_edit_block_missing_filename(self):
edit = """
Expand Down Expand Up @@ -262,7 +280,9 @@ def test_check_for_ctags_success(self):
These changes replace the `subprocess.run` patches with `subprocess.check_output` patches in both `test_check_for_ctags_failure` and `test_check_for_ctags_success` tests.
"""
edit_blocks = list(eb.find_original_update_blocks(edit))
edit_blocks = list(
eb.find_original_update_blocks(edit, **eb.EditBlockCoder.edit_block_config)
)
self.assertEqual(len(edit_blocks), 2) # 2 edits
self.assertEqual(edit_blocks[0][0], "tests/test_repomap.py")
self.assertEqual(edit_blocks[1][0], "tests/test_repomap.py")
Expand Down Expand Up @@ -421,7 +441,9 @@ def test_find_original_update_blocks_mupltiple_same_file(self):
Hope you like it!
"""

edits = list(eb.find_original_update_blocks(edit))
edits = list(
eb.find_original_update_blocks(edit, **eb.EditBlockCoder.edit_block_config)
)
self.assertEqual(
edits,
[
Expand All @@ -448,7 +470,9 @@ def test_deepseek_coder_v2_filename_mangling(self):
Hope you like it!
"""

edits = list(eb.find_original_update_blocks(edit))
edits = list(
eb.find_original_update_blocks(edit, **eb.EditBlockCoder.edit_block_config)
)
self.assertEqual(
edits,
[
Expand Down Expand Up @@ -483,7 +507,11 @@ def test_new_file_created_in_same_folder(self):
"""

edits = list(
eb.find_original_update_blocks(edit, valid_fnames=["path/to/a/file1.txt"])
eb.find_original_update_blocks(
edit,
valid_fnames=["path/to/a/file1.txt"],
**eb.EditBlockCoder.edit_block_config,
)
)
self.assertEqual(
edits,
Expand Down
8 changes: 6 additions & 2 deletions tests/basic/test_find_or_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import unittest

from aider.coders.base_coder import all_fences
from aider.coders.editblock_coder import find_original_update_blocks
from aider.coders.editblock_coder import EditBlockCoder, find_original_update_blocks
from aider.dump import dump # noqa: F401


Expand Down Expand Up @@ -47,7 +47,11 @@ def process_markdown(filename, fh):

# Process the content with find_original_update_blocks
try:
blocks = list(find_original_update_blocks(content, fence))
blocks = list(
find_original_update_blocks(
content, fence, **EditBlockCoder.edit_block_config
)
)
except ValueError as e:
print("\n\n@@@", header, "@" * 20, file=fh, flush=True)
print(str(e), file=fh, flush=True)
Expand Down

0 comments on commit 3da8b4c

Please sign in to comment.