Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martindurant committed May 23, 2024
1 parent d882cce commit a7e94c6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/snappy/snappy.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def hadoop_stream_decompress(
break
buf = c.decompress(data)
if buf:
dst.write()
dst.write(buf)
dst.flush()


Expand All @@ -349,7 +349,7 @@ def hadoop_stream_compress(
break
buf = c.compress(data)
if buf:
dst.write()
dst.write(buf)
dst.flush()


Expand Down
7 changes: 4 additions & 3 deletions src/snappy/snappy_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ def uvarint(fin):
return result


def check_unframed_format(fin):
fin.seek(0)
def check_unframed_format(fin, reset=False):
if reset:
fin.seek(0)
try:
size = uvarint(fin)
assert size < 2**32 - 1
Expand Down Expand Up @@ -87,7 +88,7 @@ def guess_format_by_header(fin):
form = "framed"
elif HadoopStreamDecompressor.check_format(fin):
form = "hadoop"
elif check_unframed_format(fin):
elif check_unframed_format(fin, reset=True):
form = "raw"
else:
raise UncompressError("Can't detect format")
Expand Down
25 changes: 25 additions & 0 deletions test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def runTest(self):
decompress_func = formats.get_decompress_function(
self.decompress_format, compressed_stream
)
compressed_stream.seek(0)
decompressed_stream = io.BytesIO()
decompress_func(
compressed_stream,
Expand Down Expand Up @@ -47,6 +48,30 @@ class TestFormatAutoFraming(TestFormatBase):
success = True


class TestFormatHadoop(TestFormatBase):
compress_format = "hadoop"
decompress_format = "hadoop"
success = True


class TestFormatRaw(TestFormatBase):
compress_format = "raw"
decompress_format = "raw"
success = True


class TestFormatHadoopAuto(TestFormatBase):
compress_format = "hadoop"
decompress_format = "auto"
success = True


class TestFormatRawAuto(TestFormatBase):
compress_format = "raw"
decompress_format = "auto"
success = True


if __name__ == "__main__":
import unittest
unittest.main()

0 comments on commit a7e94c6

Please sign in to comment.