@@ -1139,27 +1139,41 @@ def test_invalid_dict(self):
11391139 ZstdDecompressor (zd )
11401140
11411141 # wrong type
1142- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1143- ZstdCompressor (zstd_dict = (zd , b'123' ))
1144- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1142+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
1143+ ZstdCompressor (zstd_dict = [zd , 1 ])
1144+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
1145+ ZstdCompressor (zstd_dict = (zd , 1.0 ))
1146+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
1147+ ZstdCompressor (zstd_dict = (zd ,))
1148+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
11451149 ZstdCompressor (zstd_dict = (zd , 1 , 2 ))
1146- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1150+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
11471151 ZstdCompressor (zstd_dict = (zd , - 1 ))
1148- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1152+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
11491153 ZstdCompressor (zstd_dict = (zd , 3 ))
1150-
1151- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1152- ZstdDecompressor (zstd_dict = (zd , b'123' ))
1153- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1154+ with self .assertRaises (OverflowError ):
1155+ ZstdCompressor (zstd_dict = (zd , 2 ** 1000 ))
1156+ with self .assertRaises (OverflowError ):
1157+ ZstdCompressor (zstd_dict = (zd , - 2 ** 1000 ))
1158+
1159+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
1160+ ZstdDecompressor (zstd_dict = [zd , 1 ])
1161+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
1162+ ZstdDecompressor (zstd_dict = (zd , 1.0 ))
1163+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
1164+ ZstdDecompressor ((zd ,))
1165+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
11541166 ZstdDecompressor ((zd , 1 , 2 ))
1155- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1167+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
11561168 ZstdDecompressor ((zd , - 1 ))
1157- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1169+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
11581170 ZstdDecompressor ((zd , 3 ))
1171+ with self .assertRaises (OverflowError ):
1172+ ZstdDecompressor ((zd , 2 ** 1000 ))
1173+ with self .assertRaises (OverflowError ):
1174+ ZstdDecompressor ((zd , - 2 ** 1000 ))
11591175
11601176 def test_train_dict (self ):
1161-
1162-
11631177 TRAINED_DICT = train_dict (SAMPLES , DICT_SIZE1 )
11641178 ZstdDict (TRAINED_DICT .dict_content , is_raw = False )
11651179
@@ -1240,18 +1254,37 @@ def test_train_dict_c(self):
12401254 # argument wrong type
12411255 with self .assertRaises (TypeError ):
12421256 _zstd .train_dict ({}, (), 100 )
1257+ with self .assertRaises (TypeError ):
1258+ _zstd .train_dict (bytearray (), (), 100 )
12431259 with self .assertRaises (TypeError ):
12441260 _zstd .train_dict (b'' , 99 , 100 )
1261+ with self .assertRaises (TypeError ):
1262+ _zstd .train_dict (b'' , [], 100 )
12451263 with self .assertRaises (TypeError ):
12461264 _zstd .train_dict (b'' , (), 100.1 )
1265+ with self .assertRaises (TypeError ):
1266+ _zstd .train_dict (b'' , (99.1 ,), 100 )
1267+ with self .assertRaises (ValueError ):
1268+ _zstd .train_dict (b'abc' , (4 , - 1 ), 100 )
1269+ with self .assertRaises (ValueError ):
1270+ _zstd .train_dict (b'abc' , (2 ,), 100 )
1271+ with self .assertRaises (ValueError ):
1272+ _zstd .train_dict (b'' , (99 ,), 100 )
12471273
12481274 # size > size_t
12491275 with self .assertRaises (ValueError ):
1250- _zstd .train_dict (b'' , (2 ** 64 + 1 ,), 100 )
1276+ _zstd .train_dict (b'' , (2 ** 1000 ,), 100 )
1277+ with self .assertRaises (ValueError ):
1278+ _zstd .train_dict (b'' , (- 2 ** 1000 ,), 100 )
12511279
12521280 # dict_size <= 0
12531281 with self .assertRaises (ValueError ):
12541282 _zstd .train_dict (b'' , (), 0 )
1283+ with self .assertRaises (ValueError ):
1284+ _zstd .train_dict (b'' , (), - 1 )
1285+
1286+ with self .assertRaises (ZstdError ):
1287+ _zstd .train_dict (b'' , (), 1 )
12551288
12561289 def test_finalize_dict_c (self ):
12571290 with self .assertRaises (TypeError ):
@@ -1260,22 +1293,51 @@ def test_finalize_dict_c(self):
12601293 # argument wrong type
12611294 with self .assertRaises (TypeError ):
12621295 _zstd .finalize_dict ({}, b'' , (), 100 , 5 )
1296+ with self .assertRaises (TypeError ):
1297+ _zstd .finalize_dict (bytearray (TRAINED_DICT .dict_content ), b'' , (), 100 , 5 )
12631298 with self .assertRaises (TypeError ):
12641299 _zstd .finalize_dict (TRAINED_DICT .dict_content , {}, (), 100 , 5 )
1300+ with self .assertRaises (TypeError ):
1301+ _zstd .finalize_dict (TRAINED_DICT .dict_content , bytearray (), (), 100 , 5 )
12651302 with self .assertRaises (TypeError ):
12661303 _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , 99 , 100 , 5 )
1304+ with self .assertRaises (TypeError ):
1305+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , [], 100 , 5 )
12671306 with self .assertRaises (TypeError ):
12681307 _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 100.1 , 5 )
12691308 with self .assertRaises (TypeError ):
12701309 _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 100 , 5.1 )
12711310
1311+ with self .assertRaises (ValueError ):
1312+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'abc' , (4 , - 1 ), 100 , 5 )
1313+ with self .assertRaises (ValueError ):
1314+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'abc' , (2 ,), 100 , 5 )
1315+ with self .assertRaises (ValueError ):
1316+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (99 ,), 100 , 5 )
1317+
12721318 # size > size_t
12731319 with self .assertRaises (ValueError ):
1274- _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (2 ** 64 + 1 ,), 100 , 5 )
1320+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (2 ** 1000 ,), 100 , 5 )
1321+ with self .assertRaises (ValueError ):
1322+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (- 2 ** 1000 ,), 100 , 5 )
12751323
12761324 # dict_size <= 0
12771325 with self .assertRaises (ValueError ):
12781326 _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 0 , 5 )
1327+ with self .assertRaises (ValueError ):
1328+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), - 1 , 5 )
1329+ with self .assertRaises (OverflowError ):
1330+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 2 ** 1000 , 5 )
1331+ with self .assertRaises (OverflowError ):
1332+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), - 2 ** 1000 , 5 )
1333+
1334+ with self .assertRaises (OverflowError ):
1335+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 100 , 2 ** 1000 )
1336+ with self .assertRaises (OverflowError ):
1337+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 100 , - 2 ** 1000 )
1338+
1339+ with self .assertRaises (ZstdError ):
1340+ _zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 100 , 5 )
12791341
12801342 def test_train_buffer_protocol_samples (self ):
12811343 def _nbytes (dat ):
0 commit comments