mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 21:04:59 +00:00
aider: Added a new test test_run_with_file_unicode_error
that expects a UnicodeDecodeError
to be raised when the run
method of the Coder
object is called with a file containing non-UTF8 text.
# Context: USER: I did `git reset --hard HEAD~1` to discard the last edits. ASSISTANT: Okay, your last commit has been discarded and your repository is now at the state before the last commit. If you need to make any further changes or need assistance with anything else, feel free to ask. USER: try again, but don't elide code with ... ASSISTANT: Understood. Here's the updated *edit block* without eliding any code: ```python tests/test_coder.py <<<<<<< ORIGINAL 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__": unittest.main() ======= 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) def test_run_with_file_unicode_error(self): # Create a temporary file _, file = tempfile.mkstemp() # Write some non-UTF8 text into the file with open(file, "wb") as f: f.write(b"\x80abc") # Initialize the Coder object with the temporary file coder = Coder.create( models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", fnames=[file] ) # Expect a UnicodeDecodeError to be raised when the run method is called with self.assertRaises(UnicodeDecodeError): coder.run(with_message="hi") if __name__ == "__main__": unittest.main() >>>>>>> UPDATED ``` This new test `test_run_with_file_unicode_error` will write non-UTF8 text into a temporary file and expect a `UnicodeDecodeError` to be raised when the `run` method of the `Coder` object is called.
This commit is contained in:
parent
3c443d68d0
commit
5647240207
1 changed files with 18 additions and 2 deletions
|
@ -209,6 +209,22 @@ class TestCoder(unittest.TestCase):
|
|||
coder.run(with_message="hi")
|
||||
self.assertEqual(len(coder.abs_fnames), 1)
|
||||
|
||||
def test_run_with_file_unicode_error(self):
|
||||
# Create a temporary file
|
||||
_, file = tempfile.mkstemp()
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
# Write some non-UTF8 text into the file
|
||||
with open(file, "wb") as f:
|
||||
f.write(b"\x80abc")
|
||||
|
||||
# Initialize the Coder object with the temporary file
|
||||
coder = Coder.create(
|
||||
models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", fnames=[file]
|
||||
)
|
||||
|
||||
# Expect a UnicodeDecodeError to be raised when the run method is called
|
||||
with self.assertRaises(UnicodeDecodeError):
|
||||
coder.run(with_message="hi")
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue