mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 21:04:59 +00:00
working test
This commit is contained in:
parent
391088fd14
commit
3c443d68d0
3 changed files with 38 additions and 2 deletions
|
@ -290,9 +290,10 @@ class Coder:
|
||||||
def get_abs_fnames_content(self):
|
def get_abs_fnames_content(self):
|
||||||
for fname in list(self.abs_fnames):
|
for fname in list(self.abs_fnames):
|
||||||
content = self.io.read_text(fname)
|
content = self.io.read_text(fname)
|
||||||
|
dump(fname, content)
|
||||||
if content is None:
|
if content is None:
|
||||||
relative_fname = self.get_rel_fname(fname)
|
relative_fname = self.get_rel_fname(fname)
|
||||||
self.tool_error(f"Dropping {relative_fname} from the chat.")
|
self.io.tool_error(f"Dropping {relative_fname} from the chat.")
|
||||||
self.abs_fnames.remove(fname)
|
self.abs_fnames.remove(fname)
|
||||||
else:
|
else:
|
||||||
yield fname, content
|
yield fname, content
|
||||||
|
|
|
@ -141,7 +141,10 @@ class InputOutput:
|
||||||
try:
|
try:
|
||||||
with open(str(filename), "r", encoding=self.encoding) as f:
|
with open(str(filename), "r", encoding=self.encoding) as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
except (FileNotFoundError, UnicodeError) as e:
|
except FileNotFoundError:
|
||||||
|
self.tool_error(f"{filename}: file not found error")
|
||||||
|
return
|
||||||
|
except UnicodeError as e:
|
||||||
self.tool_error(f"{filename}: {e}")
|
self.tool_error(f"{filename}: {e}")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
@ -7,6 +8,8 @@ import requests
|
||||||
|
|
||||||
from aider import models
|
from aider import models
|
||||||
from aider.coders import Coder
|
from aider.coders import Coder
|
||||||
|
from aider.dump import dump # noqa: F401
|
||||||
|
from aider.io import InputOutput
|
||||||
|
|
||||||
|
|
||||||
class TestCoder(unittest.TestCase):
|
class TestCoder(unittest.TestCase):
|
||||||
|
@ -177,6 +180,35 @@ 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()
|
||||||
|
|
||||||
|
def test_run_with_file_deletion(self):
|
||||||
|
# Create a few temporary files
|
||||||
|
_, file1 = tempfile.mkstemp()
|
||||||
|
_, file2 = tempfile.mkstemp()
|
||||||
|
|
||||||
|
files = [file1, file2]
|
||||||
|
|
||||||
|
# Initialize the Coder object with the mocked IO and mocked repo
|
||||||
|
coder = Coder.create(
|
||||||
|
models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", fnames=files
|
||||||
|
)
|
||||||
|
|
||||||
|
def mock_send(*args, **kwargs):
|
||||||
|
coder.partial_response_content = "ok"
|
||||||
|
coder.partial_response_function_call = dict()
|
||||||
|
|
||||||
|
coder.send = MagicMock(side_effect=mock_send)
|
||||||
|
|
||||||
|
# Call the run method with a message
|
||||||
|
coder.run(with_message="hi")
|
||||||
|
self.assertEqual(len(coder.abs_fnames), 2)
|
||||||
|
|
||||||
|
# Delete one of the files
|
||||||
|
os.remove(file1)
|
||||||
|
|
||||||
|
# Call the run method again with a message
|
||||||
|
coder.run(with_message="hi")
|
||||||
|
self.assertEqual(len(coder.abs_fnames), 1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue