@@ -196,14 +196,31 @@ def test_simple_compress_bad_args(self):
196196 self .assertRaises (TypeError , ZstdCompressor , zstd_dict = {1 : 2 , 3 : 4 })
197197
198198 # valid compression level range is [-(1<<17), 22]
199- with self .assertRaises (ValueError ):
199+ with self .assertRaises (ValueError ) as cm :
200200 ZstdCompressor (23 )
201- with self .assertRaises (ValueError ):
201+ self .assertEqual (
202+ str (cm .exception ),
203+ '23 not in valid range -131072 <= compression level <= 22.' ,
204+ )
205+ with self .assertRaises (ValueError ) as cm :
202206 ZstdCompressor (- (1 << 17 )- 1 )
203- with self .assertRaises (ValueError ):
207+ self .assertEqual (- (1 << 17 )- 1 , - 131073 )
208+ self .assertEqual (
209+ str (cm .exception ),
210+ '-131073 not in valid range -131072 <= compression level <= 22.' ,
211+ )
212+ with self .assertRaises (ValueError ) as cm :
204213 ZstdCompressor (2 ** 31 )
205- with self .assertRaises (ValueError ):
214+ self .assertEqual (
215+ str (cm .exception ),
216+ 'compression level not in valid range -131072 <= level <= 22.' ,
217+ )
218+ with self .assertRaises (ValueError ) as cm :
206219 ZstdCompressor (level = - (2 ** 1000 ))
220+ self .assertEqual (
221+ str (cm .exception ),
222+ 'compression level not in valid range -131072 <= level <= 22.' ,
223+ )
207224 with self .assertRaises (ValueError ):
208225 ZstdCompressor (level = (2 ** 1000 ))
209226
@@ -260,10 +277,15 @@ def test_compress_parameters(self):
260277 }
261278 ZstdCompressor (options = d )
262279
263- # larger than signed int, ValueError
264280 d1 = d .copy ()
281+ # larger than signed int
265282 d1 [CompressionParameter .ldm_bucket_size_log ] = 2 ** 31
266- self .assertRaises (ValueError , ZstdCompressor , options = d1 )
283+ with self .assertRaises (OverflowError ):
284+ ZstdCompressor (options = d1 )
285+ # smaller than signed int
286+ d1 [CompressionParameter .ldm_bucket_size_log ] = - (2 ** 31 )- 1
287+ with self .assertRaises (OverflowError ):
288+ ZstdCompressor (options = d1 )
267289
268290 # out of bounds compression level
269291 level_min , level_max = CompressionParameter .compression_level .bounds ()
@@ -399,17 +421,17 @@ def test_simple_decompress_bad_args(self):
399421 self .assertRaises (TypeError , ZstdDecompressor , options = 'abc' )
400422 self .assertRaises (TypeError , ZstdDecompressor , options = b'abc' )
401423
402- with self .assertRaises (ValueError ):
424+ with self .assertRaises (OverflowError ):
403425 ZstdDecompressor (options = {2 ** 31 : 100 })
404- with self .assertRaises (ValueError ):
426+ with self .assertRaises (OverflowError ):
405427 ZstdDecompressor (options = {2 ** 1000 : 100 })
406- with self .assertRaises (ValueError ):
428+ with self .assertRaises (OverflowError ):
407429 ZstdDecompressor (options = {- (2 ** 31 )- 1 : 100 })
408- with self .assertRaises (ValueError ):
430+ with self .assertRaises (OverflowError ):
409431 ZstdDecompressor (options = {- (2 ** 1000 ): 100 })
410- with self .assertRaises (ValueError ):
411- ZstdDecompressor (options = {0 : 2 ** 32 })
412- with self .assertRaises (ValueError ):
432+ with self .assertRaises (OverflowError ):
433+ ZstdDecompressor (options = {0 : 2 ** 31 })
434+ with self .assertRaises (OverflowError ):
413435 ZstdDecompressor (options = {0 : - (2 ** 1000 )})
414436
415437 with self .assertRaises (ZstdError ):
@@ -428,10 +450,15 @@ def test_decompress_parameters(self):
428450 d = {DecompressionParameter .window_log_max : 15 }
429451 ZstdDecompressor (options = d )
430452
431- # larger than signed int, ValueError
432453 d1 = d .copy ()
454+ # larger than signed int
433455 d1 [DecompressionParameter .window_log_max ] = 2 ** 31
434- self .assertRaises (ValueError , ZstdDecompressor , None , d1 )
456+ with self .assertRaises (OverflowError ):
457+ ZstdDecompressor (None , d1 )
458+ # smaller than signed int
459+ d1 [DecompressionParameter .window_log_max ] = - (2 ** 31 )- 1
460+ with self .assertRaises (OverflowError ):
461+ ZstdDecompressor (None , d1 )
435462
436463 # out of bounds error msg
437464 options = {DecompressionParameter .window_log_max :100 }
@@ -443,16 +470,16 @@ def test_decompress_parameters(self):
443470
444471 # out of bounds deecompression parameter
445472 options [DecompressionParameter .window_log_max ] = 2 ** 31
446- with self .assertRaises (ValueError ):
473+ with self .assertRaises (OverflowError ):
447474 decompress (b'' , options = options )
448- options [DecompressionParameter .window_log_max ] = - (2 ** 32 )- 1
449- with self .assertRaises (ValueError ):
475+ options [DecompressionParameter .window_log_max ] = - (2 ** 31 )- 1
476+ with self .assertRaises (OverflowError ):
450477 decompress (b'' , options = options )
451478 options [DecompressionParameter .window_log_max ] = 2 ** 1000
452- with self .assertRaises (ValueError ):
479+ with self .assertRaises (OverflowError ):
453480 decompress (b'' , options = options )
454481 options [DecompressionParameter .window_log_max ] = - (2 ** 1000 )
455- with self .assertRaises (ValueError ):
482+ with self .assertRaises (OverflowError ):
456483 decompress (b'' , options = options )
457484
458485 def test_unknown_decompression_parameter (self ):
@@ -1487,7 +1514,7 @@ def test_init_bad_check(self):
14871514 with self .assertRaises (TypeError ):
14881515 ZstdFile (io .BytesIO (COMPRESSED_100_PLUS_32KB ), "r" , options = 33 )
14891516
1490- with self .assertRaises (ValueError ):
1517+ with self .assertRaises (OverflowError ):
14911518 ZstdFile (io .BytesIO (COMPRESSED_100_PLUS_32KB ),
14921519 options = {DecompressionParameter .window_log_max :2 ** 31 })
14931520
0 commit comments