Skip to content
Merged
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
2 changes: 1 addition & 1 deletion b2sdk/_internal/stream/chained.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def read(self, size=None):
"""
byte_arrays = []

if size < 0 or size is None:
if size is None or size < 0:
while 1:
current_stream = self.stream
buff = current_stream.read()
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+chained-stream-read-none.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix reading a chained stream when the size is omitted or None.
18 changes: 3 additions & 15 deletions test/unit/stream/test_regression_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
UploadSourceStreamRange,
)
from b2sdk._internal.utils import hex_sha1_of_unlimited_stream
from test.known_defect import DefectStillPresent, defect_raises, expect, known_defect
from test.known_defect import DefectStillPresent, expect, known_defect


class ShortReadStream(io.RawIOBase):
Expand Down Expand Up @@ -88,28 +88,16 @@ def test_c46_read_none_stays_within_range(self):


class TestChainedStream:
@known_defect(
'C11',
'ChainedStream.read() with the default size raises TypeError instead of reading everything',
raises=DefectStillPresent,
)
def test_c11_default_read_returns_everything(self):
"""C11: read() with default size reads everything (docs), not a TypeError."""
stream = ChainedStream([lambda: io.BytesIO(b'abc'), lambda: io.BytesIO(b'def')])
with defect_raises(TypeError, match="'<' not supported between instances of 'NoneType'"):
data = stream.read()
data = stream.read()
assert data == b'abcdef', 'read() did not return all data'

@known_defect(
'C11',
'ChainedStream.read(None) raises TypeError instead of reading everything',
raises=DefectStillPresent,
)
def test_c11_explicit_none_returns_everything(self):
"""C11: read(None) is documented as 'read everything'."""
stream = ChainedStream([lambda: io.BytesIO(b'abc'), lambda: io.BytesIO(b'def')])
with defect_raises(TypeError, match="'<' not supported between instances of 'NoneType'"):
data = stream.read(None)
data = stream.read(None)
assert data == b'abcdef', 'read(None) did not return all data'

def test_c12_guard_sized_reads_cross_stream_boundaries(self):
Expand Down
Loading