From 285458314f78f8b877f090f58f92b4e4ca76b297 Mon Sep 17 00:00:00 2001 From: cristianchiriac <80774326+cristianchiriac@users.noreply.github.com> Date: Thu, 8 Oct 2026 06:34:10 +0300 Subject: [PATCH 1/2] Fix 'python -m snappy -d' get_decompress_function() returns a single function since d882cce, but the command line still unpacked a (function, chunk) tuple from it, so every decompression failed with "cannot unpack non-iterable function object". Use the returned function directly and rewind the input after guessing the format, as the format tests do. Fixes #153 --- src/snappy/__main__.py | 9 +++++---- test_formats.py | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/snappy/__main__.py b/src/snappy/__main__.py index 07c95f7..c558b48 100644 --- a/src/snappy/__main__.py +++ b/src/snappy/__main__.py @@ -71,20 +71,21 @@ def cmdline_main(): if isinstance(args.outfile, io.TextIOWrapper): args.outfile = stdout - additional_args = {} if args.compress: method = formats.get_compress_function(args.target_format) else: try: - method, read_chunk = formats.get_decompress_function( + method = formats.get_decompress_function( args.target_format, args.infile ) except UncompressError as err: sys.exit("Failed to get decompress function: {}".format(err)) - additional_args['start_chunk'] = read_chunk + if args.target_format == "auto": + # guessing the format reads from the input, so rewind it + args.infile.seek(0) - method(args.infile, args.outfile, **additional_args) + method(args.infile, args.outfile) if __name__ == "__main__": diff --git a/test_formats.py b/test_formats.py index 6453b1e..fa6893b 100644 --- a/test_formats.py +++ b/test_formats.py @@ -1,5 +1,8 @@ import io import os +import subprocess +import sys +import tempfile from unittest import TestCase from snappy import snappy_formats as formats @@ -72,6 +75,30 @@ class TestFormatRawAuto(TestFormatBase): success = True +class TestCommandLine(TestCase): + def test_compress_decompress_roundtrip(self): + data = os.urandom(1024 * 256 * 2) + os.urandom(13245 * 2) + with tempfile.TemporaryDirectory() as tmp_dir: + plain = os.path.join(tmp_dir, "plain") + compressed = os.path.join(tmp_dir, "compressed.snappy") + with open(plain, "wb") as f: + f.write(data) + subprocess.run( + [sys.executable, "-m", "snappy", "-c", plain, compressed], + check=True, + ) + for target_format in formats.ALL_SUPPORTED_FORMATS: + with self.subTest(target_format=target_format): + decompressed = os.path.join(tmp_dir, target_format) + subprocess.run( + [sys.executable, "-m", "snappy", "-d", + "-t", target_format, compressed, decompressed], + check=True, + ) + with open(decompressed, "rb") as f: + self.assertEqual(data, f.read()) + + if __name__ == "__main__": import unittest unittest.main() From c984db274d916a4b5118338771730278c01f1723 Mon Sep 17 00:00:00 2001 From: Cristian <80774326+cristianchiriac@users.noreply.github.com> Date: Sat, 10 Oct 2026 20:23:41 +0300 Subject: [PATCH 2/2] ci: execute CLI decompression regression tests --- .github/workflows/wheel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wheel.yml b/.github/workflows/wheel.yml index f36ea56..f9e543f 100644 --- a/.github/workflows/wheel.yml +++ b/.github/workflows/wheel.yml @@ -38,7 +38,7 @@ jobs: run: pip install dist/python-snappy*.tar.gz - name: Pytest - run: pytest --verbose test_snappy.py + run: pytest --verbose test_snappy.py test_formats.py - name: Archive sdist uses: actions/upload-artifact@v4