mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-22 05:14:59 +00:00
test for unicode errors
This commit is contained in:
parent
5647240207
commit
ffee2c9511
1 changed files with 23 additions and 10 deletions
|
@ -210,21 +210,34 @@ class TestCoder(unittest.TestCase):
|
||||||
self.assertEqual(len(coder.abs_fnames), 1)
|
self.assertEqual(len(coder.abs_fnames), 1)
|
||||||
|
|
||||||
def test_run_with_file_unicode_error(self):
|
def test_run_with_file_unicode_error(self):
|
||||||
# Create a temporary file
|
# Create a few temporary files
|
||||||
_, file = tempfile.mkstemp()
|
_, file1 = tempfile.mkstemp()
|
||||||
|
_, file2 = tempfile.mkstemp()
|
||||||
|
|
||||||
# Write some non-UTF8 text into the file
|
files = [file1, file2]
|
||||||
with open(file, "wb") as f:
|
|
||||||
f.write(b"\x80abc")
|
|
||||||
|
|
||||||
# Initialize the Coder object with the temporary file
|
# Initialize the Coder object with the mocked IO and mocked repo
|
||||||
coder = Coder.create(
|
coder = Coder.create(
|
||||||
models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", fnames=[file]
|
models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", fnames=files
|
||||||
)
|
)
|
||||||
|
|
||||||
# Expect a UnicodeDecodeError to be raised when the run method is called
|
def mock_send(*args, **kwargs):
|
||||||
with self.assertRaises(UnicodeDecodeError):
|
coder.partial_response_content = "ok"
|
||||||
coder.run(with_message="hi")
|
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)
|
||||||
|
|
||||||
|
# Write some non-UTF8 text into the file
|
||||||
|
with open(file1, "wb") as f:
|
||||||
|
f.write(b"\x80abc")
|
||||||
|
|
||||||
|
# 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