@@ -1138,27 +1138,41 @@ def test_invalid_dict(self):
11381138 ZstdDecompressor (zd )
11391139
11401140 # wrong type
1141- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1142- ZstdCompressor (zstd_dict = (zd , b'123' ))
1143- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1141+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
1142+ ZstdCompressor (zstd_dict = [zd , 1 ])
1143+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
1144+ ZstdCompressor (zstd_dict = (zd , 1.0 ))
1145+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
1146+ ZstdCompressor (zstd_dict = (zd ,))
1147+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
11441148 ZstdCompressor (zstd_dict = (zd , 1 , 2 ))
1145- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1149+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
11461150 ZstdCompressor (zstd_dict = (zd , - 1 ))
1147- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1151+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
11481152 ZstdCompressor (zstd_dict = (zd , 3 ))
1149-
1150- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1151- ZstdDecompressor (zstd_dict = (zd , b'123' ))
1152- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1153+ with self .assertRaises (OverflowError ):
1154+ ZstdCompressor (zstd_dict = (zd , 2 ** 1000 ))
1155+ with self .assertRaises (OverflowError ):
1156+ ZstdCompressor (zstd_dict = (zd , - 2 ** 1000 ))
1157+
1158+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
1159+ ZstdDecompressor (zstd_dict = [zd , 1 ])
1160+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
1161+ ZstdDecompressor (zstd_dict = (zd , 1.0 ))
1162+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
1163+ ZstdDecompressor ((zd ,))
1164+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
11531165 ZstdDecompressor ((zd , 1 , 2 ))
1154- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1166+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
11551167 ZstdDecompressor ((zd , - 1 ))
1156- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1168+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
11571169 ZstdDecompressor ((zd , 3 ))
1170+ with self .assertRaises (OverflowError ):
1171+ ZstdDecompressor ((zd , 2 ** 1000 ))
1172+ with self .assertRaises (OverflowError ):
1173+ ZstdDecompressor ((zd , - 2 ** 1000 ))
11581174
11591175 def test_train_dict (self ):
1160-
1161-
11621176 TRAINED_DICT = train_dict (SAMPLES , DICT_SIZE1 )
11631177 ZstdDict (TRAINED_DICT .dict_content , is_raw = False )
11641178
@@ -1239,18 +1253,37 @@ def test_train_dict_c(self):
12391253 # argument wrong type
12401254 with self .assertRaises (TypeError ):
12411255 _zstd .train_dict ({}, (), 100 )
1256+ with self .assertRaises (TypeError ):
1257+ _zstd .train_dict (bytearray (), (), 100 )
12421258 with self .assertRaises (TypeError ):
12431259 _zstd .train_dict (b'' , 99 , 100 )
1260+ with self .assertRaises (TypeError ):
1261+ _zstd .train_dict (b'' , [], 100 )
12441262 with self .assertRaises (TypeError ):
12451263 _zstd .train_dict (b'' , (), 100.1 )
1264+ with self .assertRaises (TypeError ):
1265+ _zstd .train_dict (b'' , (99.1 ,), 100 )
1266+ with self .assertRaises (ValueError ):
1267+ _zstd .train_dict (b'abc' , (4 , - 1 ), 100 )
1268+ with self .assertRaises (ValueError ):
1269+ _zstd .train_dict (b'abc' , (2 ,), 100 )
1270+ with self .assertRaises (ValueError ):
1271+ _zstd .train_dict (b'' , (99 ,), 100 )
12461272
12471273 # size > size_t
12481274 with self .assertRaises (ValueError ):
1249- _zstd .train_dict (b'' , (2 ** 64 + 1 ,), 100 )
1275+ _zstd .train_dict (b'' , (2 ** 1000 ,), 100 )
1276+ with self .assertRaises (ValueError ):
1277+ _zstd .train_dict (b'' , (- 2 ** 1000 ,), 100 )
12501278
12511279 # dict_size <= 0
12521280 with self .assertRaises (ValueError ):
12531281 _zstd .train_dict (b'' , (), 0 )
1282+ with self .assertRaises (ValueError ):
1283+ _zstd .train_dict (b'' , (), - 1 )
1284+
1285+ with self .assertRaises (ZstdError ):
1286+ _zstd .train_dict (b'' , (), 1 )
12541287
12551288 def test_finalize_dict_c (self ):
12561289 with self .assertRaises (TypeError ):
@@ -1259,22 +1292,51 @@ def test_finalize_dict_c(self):
12591292 # argument wrong type
12601293 with self .assertRaises (TypeError ):
12611294 _zstd .finalize_dict ({}, b'' , (), 100 , 5 )
1295+ with self .assertRaises (TypeError ):
1296+ _zstd .finalize_dict (bytearray (TRAINED_DICT .dict_content ), b'' , (), 100 , 5 )
12621297 with self .assertRaises (TypeError ):
12631298 _zstd .finalize_dict (TRAINED_DICT .dict_content , {}, (), 100 , 5 )
1299+ with self .assertRaises (TypeError ):
1300+ _zstd .finalize_dict (TRAINED_DICT .dict_content , bytearray (), (), 100 , 5 )
12641301 with self .assertRaises (TypeError ):
12651302 _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , 99 , 100 , 5 )
1303+ with self .assertRaises (TypeError ):
1304+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , [], 100 , 5 )
12661305 with self .assertRaises (TypeError ):
12671306 _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 100.1 , 5 )
12681307 with self .assertRaises (TypeError ):
12691308 _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 100 , 5.1 )
12701309
1310+ with self .assertRaises (ValueError ):
1311+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'abc' , (4 , - 1 ), 100 , 5 )
1312+ with self .assertRaises (ValueError ):
1313+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'abc' , (2 ,), 100 , 5 )
1314+ with self .assertRaises (ValueError ):
1315+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (99 ,), 100 , 5 )
1316+
12711317 # size > size_t
12721318 with self .assertRaises (ValueError ):
1273- _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (2 ** 64 + 1 ,), 100 , 5 )
1319+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (2 ** 1000 ,), 100 , 5 )
1320+ with self .assertRaises (ValueError ):
1321+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (- 2 ** 1000 ,), 100 , 5 )
12741322
12751323 # dict_size <= 0
12761324 with self .assertRaises (ValueError ):
12771325 _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 0 , 5 )
1326+ with self .assertRaises (ValueError ):
1327+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), - 1 , 5 )
1328+ with self .assertRaises (OverflowError ):
1329+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 2 ** 1000 , 5 )
1330+ with self .assertRaises (OverflowError ):
1331+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), - 2 ** 1000 , 5 )
1332+
1333+ with self .assertRaises (OverflowError ):
1334+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 100 , 2 ** 1000 )
1335+ with self .assertRaises (OverflowError ):
1336+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 100 , - 2 ** 1000 )
1337+
1338+ with self .assertRaises (ZstdError ):
1339+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 100 , 5 )
12781340
12791341 def test_train_buffer_protocol_samples (self ):
12801342 def _nbytes (dat ):
0 commit comments