Skip to content

Commit a7e94c6

Browse files
committed
add tests
1 parent d882cce commit a7e94c6

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

src/snappy/snappy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def hadoop_stream_decompress(
333333
break
334334
buf = c.decompress(data)
335335
if buf:
336-
dst.write()
336+
dst.write(buf)
337337
dst.flush()
338338

339339

@@ -349,7 +349,7 @@ def hadoop_stream_compress(
349349
break
350350
buf = c.compress(data)
351351
if buf:
352-
dst.write()
352+
dst.write(buf)
353353
dst.flush()
354354

355355

src/snappy/snappy_formats.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ def uvarint(fin):
5353
return result
5454

5555

56-
def check_unframed_format(fin):
57-
fin.seek(0)
56+
def check_unframed_format(fin, reset=False):
57+
if reset:
58+
fin.seek(0)
5859
try:
5960
size = uvarint(fin)
6061
assert size < 2**32 - 1
@@ -87,7 +88,7 @@ def guess_format_by_header(fin):
8788
form = "framed"
8889
elif HadoopStreamDecompressor.check_format(fin):
8990
form = "hadoop"
90-
elif check_unframed_format(fin):
91+
elif check_unframed_format(fin, reset=True):
9192
form = "raw"
9293
else:
9394
raise UncompressError("Can't detect format")

test_formats.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def runTest(self):
2020
decompress_func = formats.get_decompress_function(
2121
self.decompress_format, compressed_stream
2222
)
23+
compressed_stream.seek(0)
2324
decompressed_stream = io.BytesIO()
2425
decompress_func(
2526
compressed_stream,
@@ -47,6 +48,30 @@ class TestFormatAutoFraming(TestFormatBase):
4748
success = True
4849

4950

51+
class TestFormatHadoop(TestFormatBase):
52+
compress_format = "hadoop"
53+
decompress_format = "hadoop"
54+
success = True
55+
56+
57+
class TestFormatRaw(TestFormatBase):
58+
compress_format = "raw"
59+
decompress_format = "raw"
60+
success = True
61+
62+
63+
class TestFormatHadoopAuto(TestFormatBase):
64+
compress_format = "hadoop"
65+
decompress_format = "auto"
66+
success = True
67+
68+
69+
class TestFormatRawAuto(TestFormatBase):
70+
compress_format = "raw"
71+
decompress_format = "auto"
72+
success = True
73+
74+
5075
if __name__ == "__main__":
5176
import unittest
5277
unittest.main()

0 commit comments

Comments
 (0)