mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 04:44:59 +00:00
aider: Changed encoding to 'latin-1' and provided content that will cause an error when read with 'utf-8' encoding in the test_run_with_file_utf_unicode_error
method.
# Context: USER: do the TODOs ASSISTANT: I see two TODOs in the provided code. 1. In the `test_run_with_file_utf_unicode_error` method, you need to specify an encoding other than 'utf-8'. 2. In the same method, you need to provide content that will cause an error when read with 'utf-8' encoding. Here are the proposed changes: ```python tests/test_coder.py <<<<<<< ORIGINAL encoding = 'pick something other than utf-8' # TODO ======= encoding = 'latin-1' >>>>>>> UPDATED ``` ```python tests/test_coder.py <<<<<<< ORIGINAL some_content_which_will_error_if_read_with_encoding_utf8 = '' # TODO ======= some_content_which_will_error_if_read_with_encoding_utf8 = 'ÅÍÎÏ'.encode('utf-16') >>>>>>> UPDATED ``` In the first change, I've chosen 'latin-1' as the encoding. It's a common encoding that's different from 'utf-8'. In the second change, I've provided a string of characters that are not valid 'utf-8' when encoded with 'utf-16'. This will cause an error when trying to read the file with 'utf-8' encoding.
This commit is contained in:
parent
5ec5b60660
commit
7cadfd9b4c
1 changed files with 33 additions and 0 deletions
|
@ -264,5 +264,38 @@ class TestCoder(unittest.TestCase):
|
|||
|
||||
self.assertNotEqual(coder.fence[0], "```")
|
||||
|
||||
def test_run_with_file_utf_unicode_error(self):
|
||||
# Create a few temporary files
|
||||
_, file1 = tempfile.mkstemp()
|
||||
_, file2 = tempfile.mkstemp()
|
||||
|
||||
files = [file1, file2]
|
||||
|
||||
encoding = 'latin-1'
|
||||
|
||||
# Initialize the Coder object with the mocked IO and mocked repo
|
||||
coder = Coder.create(
|
||||
models.GPT4, None, io=InputOutput(encoding=encoding), 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)
|
||||
|
||||
some_content_which_will_error_if_read_with_encoding_utf8 = 'ÅÍÎÏ'.encode('utf-16')
|
||||
with open(file1, "wb") as f:
|
||||
f.write(some_content_which_will_error_if_read_with_encoding_utf8)
|
||||
|
||||
coder.run(with_message="hi")
|
||||
|
||||
# both files should still be here
|
||||
self.assertEqual(len(coder.abs_fnames), 2)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue