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
12 changes: 6 additions & 6 deletions .github/workflows/wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
3 changes: 1 addition & 2 deletions src/snappy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
56 changes: 55 additions & 1 deletion test_formats.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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
Expand Down