mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 14:25:00 +00:00
refac
This commit is contained in:
parent
e22373b55a
commit
070f0a2919
7 changed files with 22 additions and 22 deletions
|
@ -1,5 +1,5 @@
|
||||||
from .base import Coder
|
from .base_coder import Coder
|
||||||
from .editblock import EditBlockCoder
|
from .editblock_coder import EditBlockCoder
|
||||||
from .wholefile import WholeFileCoder
|
from .wholefile_coder import WholeFileCoder
|
||||||
|
|
||||||
__all__ = [Coder, EditBlockCoder, WholeFileCoder]
|
__all__ = [Coder, EditBlockCoder, WholeFileCoder]
|
||||||
|
|
|
@ -4,7 +4,7 @@ import re
|
||||||
from difflib import SequenceMatcher
|
from difflib import SequenceMatcher
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from .base import Coder
|
from .base_coder import Coder
|
||||||
from .editblock_prompts import EditBlockPrompts
|
from .editblock_prompts import EditBlockPrompts
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from pathlib import Path
|
||||||
|
|
||||||
from aider import diffs
|
from aider import diffs
|
||||||
|
|
||||||
from .base import Coder
|
from .base_coder import Coder
|
||||||
from .wholefile_prompts import WholeFilePrompts
|
from .wholefile_prompts import WholeFilePrompts
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ from aider.coders import Coder
|
||||||
|
|
||||||
class TestCoder(unittest.TestCase):
|
class TestCoder(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.patcher = patch("aider.coders.base.check_model_availability")
|
self.patcher = patch("aider.coders.base_coder.check_model_availability")
|
||||||
self.mock_check = self.patcher.start()
|
self.mock_check = self.patcher.start()
|
||||||
self.mock_check.return_value = True
|
self.mock_check.return_value = True
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ class TestCoder(unittest.TestCase):
|
||||||
# Assert that the returned message is the expected one
|
# Assert that the returned message is the expected one
|
||||||
self.assertEqual(result, 'a good "commit message"')
|
self.assertEqual(result, 'a good "commit message"')
|
||||||
|
|
||||||
@patch("aider.coders.base.openai.ChatCompletion.create")
|
@patch("aider.coders.base_coder.openai.ChatCompletion.create")
|
||||||
@patch("builtins.print")
|
@patch("builtins.print")
|
||||||
def test_send_with_retries_rate_limit_error(self, mock_print, mock_chat_completion_create):
|
def test_send_with_retries_rate_limit_error(self, mock_print, mock_chat_completion_create):
|
||||||
# Mock the IO object
|
# Mock the IO object
|
||||||
|
@ -143,7 +143,7 @@ class TestCoder(unittest.TestCase):
|
||||||
# Assert that print was called once
|
# Assert that print was called once
|
||||||
mock_print.assert_called_once()
|
mock_print.assert_called_once()
|
||||||
|
|
||||||
@patch("aider.coders.base.openai.ChatCompletion.create")
|
@patch("aider.coders.base_coder.openai.ChatCompletion.create")
|
||||||
@patch("builtins.print")
|
@patch("builtins.print")
|
||||||
def test_send_with_retries_connection_error(self, mock_print, mock_chat_completion_create):
|
def test_send_with_retries_connection_error(self, mock_print, mock_chat_completion_create):
|
||||||
# Mock the IO object
|
# Mock the IO object
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from aider.coders import editblock
|
from aider.coders import editblock_coder as eb
|
||||||
|
|
||||||
|
|
||||||
class TestUtils(unittest.TestCase):
|
class TestUtils(unittest.TestCase):
|
||||||
|
@ -12,7 +12,7 @@ class TestUtils(unittest.TestCase):
|
||||||
replace = "This is a replaced text."
|
replace = "This is a replaced text."
|
||||||
expected_output = "This is a replaced text..\nAnother line of text.\nYet another line.\n"
|
expected_output = "This is a replaced text..\nAnother line of text.\nYet another line.\n"
|
||||||
|
|
||||||
result = editblock.replace_most_similar_chunk(whole, part, replace)
|
result = eb.replace_most_similar_chunk(whole, part, replace)
|
||||||
self.assertEqual(result, expected_output)
|
self.assertEqual(result, expected_output)
|
||||||
|
|
||||||
def test_replace_most_similar_chunk_not_perfect_match(self):
|
def test_replace_most_similar_chunk_not_perfect_match(self):
|
||||||
|
@ -21,7 +21,7 @@ class TestUtils(unittest.TestCase):
|
||||||
replace = "This is a replaced text.\nModified line of text."
|
replace = "This is a replaced text.\nModified line of text."
|
||||||
expected_output = "This is a replaced text.\nModified line of text.\nYet another line."
|
expected_output = "This is a replaced text.\nModified line of text.\nYet another line."
|
||||||
|
|
||||||
result = editblock.replace_most_similar_chunk(whole, part, replace)
|
result = eb.replace_most_similar_chunk(whole, part, replace)
|
||||||
self.assertEqual(result, expected_output)
|
self.assertEqual(result, expected_output)
|
||||||
|
|
||||||
def test_strip_quoted_wrapping(self):
|
def test_strip_quoted_wrapping(self):
|
||||||
|
@ -29,19 +29,19 @@ class TestUtils(unittest.TestCase):
|
||||||
"filename.ext\n```\nWe just want this content\nNot the filename and triple quotes\n```"
|
"filename.ext\n```\nWe just want this content\nNot the filename and triple quotes\n```"
|
||||||
)
|
)
|
||||||
expected_output = "We just want this content\nNot the filename and triple quotes\n"
|
expected_output = "We just want this content\nNot the filename and triple quotes\n"
|
||||||
result = editblock.strip_quoted_wrapping(input_text, "filename.ext")
|
result = eb.strip_quoted_wrapping(input_text, "filename.ext")
|
||||||
self.assertEqual(result, expected_output)
|
self.assertEqual(result, expected_output)
|
||||||
|
|
||||||
def test_strip_quoted_wrapping_no_filename(self):
|
def test_strip_quoted_wrapping_no_filename(self):
|
||||||
input_text = "```\nWe just want this content\nNot the triple quotes\n```"
|
input_text = "```\nWe just want this content\nNot the triple quotes\n```"
|
||||||
expected_output = "We just want this content\nNot the triple quotes\n"
|
expected_output = "We just want this content\nNot the triple quotes\n"
|
||||||
result = editblock.strip_quoted_wrapping(input_text)
|
result = eb.strip_quoted_wrapping(input_text)
|
||||||
self.assertEqual(result, expected_output)
|
self.assertEqual(result, expected_output)
|
||||||
|
|
||||||
def test_strip_quoted_wrapping_no_wrapping(self):
|
def test_strip_quoted_wrapping_no_wrapping(self):
|
||||||
input_text = "We just want this content\nNot the triple quotes\n"
|
input_text = "We just want this content\nNot the triple quotes\n"
|
||||||
expected_output = "We just want this content\nNot the triple quotes\n"
|
expected_output = "We just want this content\nNot the triple quotes\n"
|
||||||
result = editblock.strip_quoted_wrapping(input_text)
|
result = eb.strip_quoted_wrapping(input_text)
|
||||||
self.assertEqual(result, expected_output)
|
self.assertEqual(result, expected_output)
|
||||||
|
|
||||||
def test_find_original_update_blocks(self):
|
def test_find_original_update_blocks(self):
|
||||||
|
@ -60,7 +60,7 @@ Tooooo
|
||||||
Hope you like it!
|
Hope you like it!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
edits = list(editblock.find_original_update_blocks(edit))
|
edits = list(eb.find_original_update_blocks(edit))
|
||||||
self.assertEqual(edits, [("foo.txt", "Two\n", "Tooooo\n")])
|
self.assertEqual(edits, [("foo.txt", "Two\n", "Tooooo\n")])
|
||||||
|
|
||||||
def test_find_original_update_blocks_quote_below_filename(self):
|
def test_find_original_update_blocks_quote_below_filename(self):
|
||||||
|
@ -79,7 +79,7 @@ Tooooo
|
||||||
Hope you like it!
|
Hope you like it!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
edits = list(editblock.find_original_update_blocks(edit))
|
edits = list(eb.find_original_update_blocks(edit))
|
||||||
self.assertEqual(edits, [("foo.txt", "Two\n", "Tooooo\n")])
|
self.assertEqual(edits, [("foo.txt", "Two\n", "Tooooo\n")])
|
||||||
|
|
||||||
def test_find_original_update_blocks_unclosed(self):
|
def test_find_original_update_blocks_unclosed(self):
|
||||||
|
@ -98,7 +98,7 @@ oops!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with self.assertRaises(ValueError) as cm:
|
with self.assertRaises(ValueError) as cm:
|
||||||
list(editblock.find_original_update_blocks(edit))
|
list(eb.find_original_update_blocks(edit))
|
||||||
self.assertIn("Incomplete", str(cm.exception))
|
self.assertIn("Incomplete", str(cm.exception))
|
||||||
|
|
||||||
def test_find_original_update_blocks_missing_filename(self):
|
def test_find_original_update_blocks_missing_filename(self):
|
||||||
|
@ -116,7 +116,7 @@ oops!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with self.assertRaises(ValueError) as cm:
|
with self.assertRaises(ValueError) as cm:
|
||||||
list(editblock.find_original_update_blocks(edit))
|
list(eb.find_original_update_blocks(edit))
|
||||||
self.assertIn("filename", str(cm.exception))
|
self.assertIn("filename", str(cm.exception))
|
||||||
|
|
||||||
def test_find_original_update_blocks_no_final_newline(self):
|
def test_find_original_update_blocks_no_final_newline(self):
|
||||||
|
@ -152,7 +152,7 @@ aider/coder.py
|
||||||
>>>>>>> UPDATED"""
|
>>>>>>> UPDATED"""
|
||||||
|
|
||||||
# Should not raise a ValueError
|
# Should not raise a ValueError
|
||||||
list(editblock.find_original_update_blocks(edit))
|
list(eb.find_original_update_blocks(edit))
|
||||||
|
|
||||||
def test_incomplete_edit_block_missing_filename(self):
|
def test_incomplete_edit_block_missing_filename(self):
|
||||||
edit = """
|
edit = """
|
||||||
|
@ -195,7 +195,7 @@ tests/test_repomap.py
|
||||||
|
|
||||||
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.
|
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(editblock.find_original_update_blocks(edit))
|
edit_blocks = list(eb.find_original_update_blocks(edit))
|
||||||
self.assertEqual(len(edit_blocks), 2) # 2 edits
|
self.assertEqual(len(edit_blocks), 2) # 2 edits
|
||||||
self.assertEqual(edit_blocks[0][0], "tests/test_repomap.py")
|
self.assertEqual(edit_blocks[0][0], "tests/test_repomap.py")
|
||||||
self.assertEqual(edit_blocks[1][0], "tests/test_repomap.py")
|
self.assertEqual(edit_blocks[1][0], "tests/test_repomap.py")
|
||||||
|
@ -206,7 +206,7 @@ These changes replace the `subprocess.run` patches with `subprocess.check_output
|
||||||
replace = "new_line1\nnew_line2"
|
replace = "new_line1\nnew_line2"
|
||||||
expected_output = " new_line1\n new_line2\n line3\n"
|
expected_output = " new_line1\n new_line2\n line3\n"
|
||||||
|
|
||||||
result = editblock.replace_part_with_missing_leading_whitespace(whole, part, replace)
|
result = eb.replace_part_with_missing_leading_whitespace(whole, part, replace)
|
||||||
self.assertEqual(result, expected_output)
|
self.assertEqual(result, expected_output)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ class TestMain(TestCase):
|
||||||
self.original_cwd = os.getcwd()
|
self.original_cwd = os.getcwd()
|
||||||
self.tempdir = tempfile.mkdtemp()
|
self.tempdir = tempfile.mkdtemp()
|
||||||
os.chdir(self.tempdir)
|
os.chdir(self.tempdir)
|
||||||
self.patcher = patch("aider.coders.base.check_model_availability")
|
self.patcher = patch("aider.coders.base_coder.check_model_availability")
|
||||||
self.mock_check = self.patcher.start()
|
self.mock_check = self.patcher.start()
|
||||||
self.mock_check.return_value = True
|
self.mock_check.return_value = True
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue