From 4a15b6c01076293161c5e2d2777fdc5e7a6f438c Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 6 Jul 2023 11:57:44 -0700 Subject: [PATCH] test_run_with_file_utf_unicode_error --- tests/test_coder.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_coder.py b/tests/test_coder.py index 17ad349e8..2b38223f0 100644 --- a/tests/test_coder.py +++ b/tests/test_coder.py @@ -265,17 +265,22 @@ class TestCoder(unittest.TestCase): self.assertNotEqual(coder.fence[0], "```") def test_run_with_file_utf_unicode_error(self): + "make sure that we honor InputOutput(encoding) and don't just assume utf-8" # Create a few temporary files _, file1 = tempfile.mkstemp() _, file2 = tempfile.mkstemp() files = [file1, file2] - encoding = 'latin-1' + encoding = "utf-16" # 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 + models.GPT4, + None, + io=InputOutput(encoding=encoding), + openai_api_key="fake_key", + fnames=files, ) def mock_send(*args, **kwargs): @@ -288,7 +293,7 @@ class TestCoder(unittest.TestCase): 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') + some_content_which_will_error_if_read_with_encoding_utf8 = "ÅÍÎÏ".encode(encoding) with open(file1, "wb") as f: f.write(some_content_which_will_error_if_read_with_encoding_utf8)