mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 22:34:59 +00:00
test: update test to use invalid Unicode that triggers encoding error
This commit is contained in:
parent
8b6863dc40
commit
571a5962b7
1 changed files with 10 additions and 6 deletions
|
@ -289,20 +289,24 @@ class TestInputOutputMultilineMode(unittest.TestCase):
|
||||||
"""Test that Unicode messages are properly converted to ASCII with replacement"""
|
"""Test that Unicode messages are properly converted to ASCII with replacement"""
|
||||||
io = InputOutput(pretty=False, fancy_input=False)
|
io = InputOutput(pretty=False, fancy_input=False)
|
||||||
|
|
||||||
# Create a message with Unicode characters
|
# Create a message with invalid Unicode that can't be encoded in UTF-8
|
||||||
unicode_message = "Hello こんにちは Привет"
|
# Using a surrogate pair that's invalid in UTF-8
|
||||||
|
invalid_unicode = "Hello \ud800World"
|
||||||
|
|
||||||
# Mock console.print to capture the output
|
# Mock console.print to capture the output
|
||||||
with patch.object(io.console, "print") as mock_print:
|
with patch.object(io.console, "print") as mock_print:
|
||||||
io._tool_message(unicode_message)
|
# First call will raise UnicodeEncodeError
|
||||||
|
mock_print.side_effect = [UnicodeEncodeError('utf-8', '', 0, 1, 'invalid'), None]
|
||||||
|
|
||||||
|
io._tool_message(invalid_unicode)
|
||||||
|
|
||||||
# Verify that the message was converted to ASCII with replacement
|
# Verify that the message was converted to ASCII with replacement
|
||||||
mock_print.assert_called_once()
|
self.assertEqual(mock_print.call_count, 2)
|
||||||
args, kwargs = mock_print.call_args
|
args, kwargs = mock_print.call_args
|
||||||
converted_message = args[0]
|
converted_message = args[0]
|
||||||
|
|
||||||
# The Unicode characters should be replaced with '?'
|
# The invalid Unicode should be replaced with '?'
|
||||||
self.assertEqual(converted_message, "Hello ????? ?????")
|
self.assertEqual(converted_message, "Hello ?World")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue