From 23aa1475a37b7ff2e536ea2a68411c438e16a3a1 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Mon, 24 Feb 2025 13:00:35 -0300 Subject: [PATCH] fix encoding thing test --- tests/models/test_gemini.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/models/test_gemini.py b/tests/models/test_gemini.py index 52dcde2d..ade7e465 100644 --- a/tests/models/test_gemini.py +++ b/tests/models/test_gemini.py @@ -672,12 +672,19 @@ async def test_stream_invalid_unicode_text(get_gemini_client: GetGeminiClient): gemini_response(_content_model_response(ModelResponse(parts=[TextPart('€def')]))), ] json_data = _gemini_streamed_response_ta.dump_json(responses, by_alias=True) - parts = [json_data[:307], json_data[307:]] - # TODO(Marcelo): David, can you check this? - # with pytest.raises(UnicodeDecodeError): - # # Ensure the first part is _not_ valid unicode - # parts[0].decode() + for i in range(10, 1000): + parts = [json_data[:i], json_data[i:]] + try: + parts[0].decode() + except UnicodeDecodeError: + break + else: + assert False, 'failed to find a spot in payload that would break unicode parsing' + + with pytest.raises(UnicodeDecodeError): + # Ensure the first part is _not_ valid unicode + parts[0].decode() stream = AsyncByteStreamList(parts) gemini_client = get_gemini_client(stream)