Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sagemaker-core/src/sagemaker/core/iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __next__(self):
# handle API response errors and force terminate.
handle_stream_errors(chunk)
# print and move on to next response byte
print("Unknown event type:" + chunk)
print("Unknown event type:", chunk)
continue
return chunk["PayloadPart"]["Bytes"]

Expand Down Expand Up @@ -190,7 +190,7 @@ def __next__(self):
# handle API response errors and force terminate.
handle_stream_errors(chunk)
# print and move on to next response byte
print("Unknown event type:" + chunk)
print("Unknown event type:", chunk)
continue

# Check buffer size before writing to prevent unbounded memory consumption
Expand Down
16 changes: 16 additions & 0 deletions sagemaker-core/tests/unit/test_iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,19 @@ def test_line_iterator_no_trailing_newline_at_end():

with pytest.raises(StopIteration):
next(iterator)


def test_byte_iterator_skips_unknown_event_type():
"""Test that ByteIterator skips events it does not recognize."""
event_stream = [{"SomeNewEvent": {}}, {"PayloadPart": {"Bytes": b"hello"}}]
iterator = ByteIterator(event_stream)

assert next(iterator) == b"hello"


def test_line_iterator_skips_unknown_event_type():
"""Test that LineIterator skips events it does not recognize."""
event_stream = [{"SomeNewEvent": {}}, {"PayloadPart": {"Bytes": b"hello\n"}}]
iterator = LineIterator(event_stream)

assert next(iterator) == b"hello"
Loading