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
20 changes: 20 additions & 0 deletions tests/test_compressor_stream_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,26 @@ def test_bad_size(self):
with cctx.stream_reader(source, size=42):
pass

def test_bad_size_error_message(self):
for size, prefix in (
(2, "zstd compress error"),
(42, "error ending compression stream"),
):
message = "%s: Src size is incorrect" % prefix
for method in ("read", "readinto", "read1", "readinto1"):
with self.subTest(size=size, method=method):
cctx = zstd.ZstdCompressor()
source = io.BytesIO(b"foobar")
with cctx.stream_reader(source, size=size) as reader:
argument = bytearray(10) if "into" in method else 10
with self.assertRaises(zstd.ZstdError) as raised:
getattr(reader, method)(argument)

self.assertEqual(len(raised.exception.args), 1)
self.assertNotIn("%s", str(raised.exception))
self.assertEqual(raised.exception.args, (message,))
self.assertEqual(str(raised.exception), message)

def test_readall(self):
cctx = zstd.ZstdCompressor()
frame = cctx.compress(b"foo" * 1024)
Expand Down
6 changes: 3 additions & 3 deletions zstandard/backend_cffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ def _compress_into_buffer(self, out_buffer):
self._finished_input = True

if lib.ZSTD_isError(zresult):
raise ZstdError("zstd compress error: %s", _zstd_error(zresult))
raise ZstdError("zstd compress error: %s" % _zstd_error(zresult))

return out_buffer.pos and out_buffer.pos == out_buffer.size

Expand Down Expand Up @@ -1572,7 +1572,7 @@ def read(self, size=-1):

if lib.ZSTD_isError(zresult):
raise ZstdError(
"error ending compression stream: %s", _zstd_error(zresult)
"error ending compression stream: %s" % _zstd_error(zresult)
)

if zresult == 0:
Expand Down Expand Up @@ -1679,7 +1679,7 @@ def readinto(self, b):

if lib.ZSTD_isError(zresult):
raise ZstdError(
"error ending compression stream: %s", _zstd_error(zresult)
"error ending compression stream: %s" % _zstd_error(zresult)
)

if zresult == 0:
Expand Down