From 06da8a5fbc666c9dcc7bb4798a8633a258d1ac0b Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 22 Nov 2024 16:07:45 -0800 Subject: [PATCH] test_convert_raw_bytes_to_str_lines --- .../test_unit_test_streaming.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/pass_through_unit_tests/test_unit_test_streaming.py b/tests/pass_through_unit_tests/test_unit_test_streaming.py index 845052382..bbbc465fc 100644 --- a/tests/pass_through_unit_tests/test_unit_test_streaming.py +++ b/tests/pass_through_unit_tests/test_unit_test_streaming.py @@ -91,3 +91,28 @@ async def test_chunk_processor_yields_raw_bytes(endpoint_type, url_route): assert b"".join(received_chunks) == b"".join( raw_chunks ), "Collected chunks do not match raw chunks" + + +def test_convert_raw_bytes_to_str_lines(): + """ + Test that the _convert_raw_bytes_to_str_lines method correctly converts raw bytes to a list of strings + """ + # Test case 1: Single chunk + raw_bytes = [b'data: {"content": "Hello"}\n'] + result = PassThroughStreamingHandler._convert_raw_bytes_to_str_lines(raw_bytes) + assert result == ['data: {"content": "Hello"}'] + + # Test case 2: Multiple chunks + raw_bytes = [b'data: {"content": "Hello"}\n', b'data: {"content": "World"}\n'] + result = PassThroughStreamingHandler._convert_raw_bytes_to_str_lines(raw_bytes) + assert result == ['data: {"content": "Hello"}', 'data: {"content": "World"}'] + + # Test case 3: Empty input + raw_bytes = [] + result = PassThroughStreamingHandler._convert_raw_bytes_to_str_lines(raw_bytes) + assert result == [] + + # Test case 4: Chunks with empty lines + raw_bytes = [b'data: {"content": "Hello"}\n\n', b'\ndata: {"content": "World"}\n'] + result = PassThroughStreamingHandler._convert_raw_bytes_to_str_lines(raw_bytes) + assert result == ['data: {"content": "Hello"}', 'data: {"content": "World"}']