diff --git a/.github/workflows/wheel.yml b/.github/workflows/wheel.yml index f36ea56..2cf7eff 100644 --- a/.github/workflows/wheel.yml +++ b/.github/workflows/wheel.yml @@ -35,7 +35,7 @@ jobs: run: python setup.py sdist - name: Install python-snappy sdist - run: pip install dist/python-snappy*.tar.gz + run: pip install dist/python_snappy*.tar.gz - name: Pytest run: pytest --verbose test_snappy.py @@ -44,26 +44,26 @@ jobs: uses: actions/upload-artifact@v4 with: name: wheels - path: dist/python-snappy*.tar.gz + path: dist/python_snappy*.tar.gz build: runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - os: [ubuntu-20.04, macos-12, windows-2019] + os: [ubuntu-22.04, macos-14, windows-2022] architecture: ["x64"] linux_archs: ["auto s390x"] include: - - os: windows-2019 + - os: windows-2022 architecture: "x86" skip: "*2*win* *win_amd64" environment_windows: INCLUDE="C:/Program Files (x86)/Snappy/include" LIB="C:/Program Files (x86)/Snappy/lib" - - os: windows-2019 + - os: windows-2022 architecture: "x64" skip: "*2*win* *win32" environment_windows: INCLUDE="C:/Program Files/Snappy/include" LIB="C:/Program Files/Snappy/lib" - - os: ubuntu-20.04 + - os: ubuntu-22.04 architecture: "x64" linux_archs: aarch64 ppc64le diff --git a/src/snappy/__main__.py b/src/snappy/__main__.py index 07c95f7..507da48 100644 --- a/src/snappy/__main__.py +++ b/src/snappy/__main__.py @@ -76,13 +76,12 @@ def cmdline_main(): 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 method(args.infile, args.outfile, **additional_args) diff --git a/test_formats.py b/test_formats.py index 6453b1e..3e65a38 100644 --- a/test_formats.py +++ b/test_formats.py @@ -1,7 +1,9 @@ import io import os from unittest import TestCase - +import subprocess +import sys +import tempfile from snappy import snappy_formats as formats @@ -71,6 +73,58 @@ class TestFormatRawAuto(TestFormatBase): decompress_format = "auto" success = True +class TestDecompressFunction(TestCase): + def test_auto_returns_function(self): + data = b"hello world" + + compressed = io.BytesIO() + formats.get_compress_function("auto")( + io.BytesIO(data), + compressed + ) + compressed.seek(0) + + decompress_func = formats.get_decompress_function( + "auto", + compressed + ) + + decompressed = io.BytesIO() + decompress_func(compressed, decompressed) + + self.assertEqual(data, decompressed.getvalue()) + + def test_cli_decompress(self): + data = b"hello world" + + with tempfile.TemporaryDirectory() as tmpdir: + compressed = os.path.join(tmpdir, "input.snappy") + output = os.path.join(tmpdir, "output.txt") + + with open(compressed, "wb") as f: + formats.get_compress_function("auto")( + io.BytesIO(data), + f + ) + + result = subprocess.run( + [ + sys.executable, + "-m", + "snappy", + "-d", + compressed, + output, + ], + capture_output=True, + text=True, + ) + + self.assertEqual(result.returncode, 0) + + with open(output, "rb") as f: + self.assertEqual(data, f.read()) + if __name__ == "__main__": import unittest