Debian Codegraph @

contrib/python-zstandard/tests/test_decompressor.py

raw
1 import unittest
2
3 import zstandard as zstd
4
5
6 class TestFrameHeaderSize(unittest.TestCase):
7 def test_empty(self):
8 with self.assertRaisesRegex(
9 zstd.ZstdError,
10 "could not determine frame header size: Src size " "is incorrect",
11 ):
12 zstd.frame_header_size(b"")
13
14 def test_too_small(self):
15 with self.assertRaisesRegex(
16 zstd.ZstdError,
17 "could not determine frame header size: Src size " "is incorrect",
18 ):
19 zstd.frame_header_size(b"foob")
20
21 def test_basic(self):
22 # It doesn't matter that it isn't a valid frame.
23 self.assertEqual(zstd.frame_header_size(b"long enough but no magic"), 6)
24
25
26 class TestFrameContentSize(unittest.TestCase):
27 def test_empty_input(self):
28 with self.assertRaisesRegex(
29 zstd.ZstdError, "error when determining content size"
30 ):
31 zstd.frame_content_size(b"")
32
33 def test_too_small(self):
34 with self.assertRaisesRegex(
35 zstd.ZstdError, "error when determining content size"
36 ):
37 zstd.frame_content_size(b"foob")
38
39 def test_bad_frame(self):
40 with self.assertRaisesRegex(
41 zstd.ZstdError, "error when determining content size"
42 ):
43 zstd.frame_content_size(b"invalid frame header")
44
45 def test_unknown(self):
46 cctx = zstd.ZstdCompressor(write_content_size=False)
47 frame = cctx.compress(b"foobar")
48
49 self.assertEqual(zstd.frame_content_size(frame), -1)
50
51 def test_empty(self):
52 cctx = zstd.ZstdCompressor()
53 frame = cctx.compress(b"")
54
55 self.assertEqual(zstd.frame_content_size(frame), 0)
56
57 def test_basic(self):
58 cctx = zstd.ZstdCompressor()
59 frame = cctx.compress(b"foobar")
60
61 self.assertEqual(zstd.frame_content_size(frame), 6)
62
63
64 class TestDecompressor(unittest.TestCase):
65 def test_memory_size(self):
66 dctx = zstd.ZstdDecompressor()
67
68 self.assertGreater(dctx.memory_size(), 100)