MCPcopy Index your code
hub / github.com/python/cpython / test_simple_compress_bad_args

Method test_simple_compress_bad_args

Lib/test/test_zstd.py:194–241  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

192class CompressorTestCase(unittest.TestCase):
193
194 def test_simple_compress_bad_args(self):
195 # ZstdCompressor
196 self.assertRaises(TypeError, ZstdCompressor, [])
197 self.assertRaises(TypeError, ZstdCompressor, level=3.14)
198 self.assertRaises(TypeError, ZstdCompressor, level="abc")
199 self.assertRaises(TypeError, ZstdCompressor, options=b"abc")
200
201 self.assertRaises(TypeError, ZstdCompressor, zstd_dict=123)
202 self.assertRaises(TypeError, ZstdCompressor, zstd_dict=b"abcd1234")
203 self.assertRaises(TypeError, ZstdCompressor, zstd_dict={1: 2, 3: 4})
204
205 # valid range for compression level is [-(1<<17), 22]
206 msg = r'illegal compression level {}; the valid range is \[-?\d+, -?\d+\]'
207 with self.assertRaisesRegex(ValueError, msg.format(C_INT_MAX)):
208 ZstdCompressor(C_INT_MAX)
209 with self.assertRaisesRegex(ValueError, msg.format(C_INT_MIN)):
210 ZstdCompressor(C_INT_MIN)
211 msg = r'illegal compression level; the valid range is \[-?\d+, -?\d+\]'
212 with self.assertRaisesRegex(ValueError, msg):
213 ZstdCompressor(level=-(2**1000))
214 with self.assertRaisesRegex(ValueError, msg):
215 ZstdCompressor(level=2**1000)
216
217 with self.assertRaises(ValueError):
218 ZstdCompressor(options={CompressionParameter.window_log: 100})
219 with self.assertRaises(ValueError):
220 ZstdCompressor(options={3333: 100})
221
222 # Method bad arguments
223 zc = ZstdCompressor()
224 self.assertRaises(TypeError, zc.compress)
225 self.assertRaises((TypeError, ValueError), zc.compress, b"foo", b"bar")
226 self.assertRaises(TypeError, zc.compress, "str")
227 self.assertRaises((TypeError, ValueError), zc.flush, b"foo")
228 self.assertRaises(TypeError, zc.flush, b"blah", 1)
229
230 self.assertRaises(ValueError, zc.compress, b'', -1)
231 self.assertRaises(ValueError, zc.compress, b'', 3)
232 self.assertRaises(ValueError, zc.flush, zc.CONTINUE) # 0
233 self.assertRaises(ValueError, zc.flush, 3)
234
235 zc.compress(b'')
236 zc.compress(b'', zc.CONTINUE)
237 zc.compress(b'', zc.FLUSH_BLOCK)
238 zc.compress(b'', zc.FLUSH_FRAME)
239 empty = zc.flush()
240 zc.flush(zc.FLUSH_BLOCK)
241 zc.flush(zc.FLUSH_FRAME)
242
243 def test_compress_parameters(self):
244 d = {CompressionParameter.compression_level : 10,

Callers

nothing calls this directly

Calls 5

assertRaisesRegexMethod · 0.80
assertRaisesMethod · 0.45
formatMethod · 0.45
compressMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected