test: add test for Unicode to ASCII fallback in tool messages

This commit is contained in:
Paul Gauthier (aider) 2025-01-11 15:46:28 -08:00
parent 4ece6d2a9b
commit 01af629399

View file

@ -285,6 +285,25 @@ class TestInputOutputMultilineMode(unittest.TestCase):
self.io.toggle_multiline_mode() self.io.toggle_multiline_mode()
self.assertFalse(self.io.multiline_mode) self.assertFalse(self.io.multiline_mode)
def test_tool_message_unicode_fallback(self):
"""Test that Unicode messages are properly converted to ASCII with replacement"""
io = InputOutput(pretty=False, fancy_input=False)
# Create a message with Unicode characters
unicode_message = "Hello こんにちは Привет"
# Mock console.print to capture the output
with patch.object(io.console, 'print') as mock_print:
io._tool_message(unicode_message)
# Verify that the message was converted to ASCII with replacement
mock_print.assert_called_once()
args, kwargs = mock_print.call_args
converted_message = args[0]
# The Unicode characters should be replaced with '?'
self.assertEqual(converted_message, "Hello ????? ?????")
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()