@@ -1139,27 +1139,41 @@ def test_invalid_dict(self):
11391139ZstdDecompressor (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' ):
11451149ZstdCompressor (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' ):
11471151ZstdCompressor (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' ):
11491153ZstdCompressor (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' ):
11541166ZstdDecompressor ((zd , 1 , 2 ))
1155- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1167+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
11561168ZstdDecompressor ((zd , - 1 ))
1157- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1169+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
11581170ZstdDecompressor ((zd , 3 ))
1171+ with self .assertRaises (OverflowError ):
1172+ ZstdDecompressor ((zd , 2 ** 1000 ))
1173+ with self .assertRaises (OverflowError ):
1174+ ZstdDecompressor ((zd , - 2 ** 1000 ))
11591175
11601176def test_train_dict (self ):
1161-
1162-
11631177TRAINED_DICT = train_dict (SAMPLES , DICT_SIZE1 )
11641178ZstdDict (TRAINED_DICT .dict_content , is_raw = False )
11651179
@@ -1240,18 +1254,37 @@ def test_train_dict_c(self):
12401254# argument wrong type
12411255with self .assertRaises (TypeError ):
12421256_zstd .train_dict ({}, (), 100 )
1257+ with self .assertRaises (TypeError ):
1258+ _zstd .train_dict (bytearray (), (), 100 )
12431259with self .assertRaises (TypeError ):
12441260_zstd .train_dict (b'' , 99 , 100 )
1261+ with self .assertRaises (TypeError ):
1262+ _zstd .train_dict (b'' , [], 100 )
12451263with 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
12491275with 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
12531281with 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
12561289def test_finalize_dict_c (self ):
12571290with self .assertRaises (TypeError ):
@@ -1260,22 +1293,51 @@ def test_finalize_dict_c(self):
12601293# argument wrong type
12611294with 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 )
12631298with 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 )
12651302with 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 )
12671306with self .assertRaises (TypeError ):
12681307_zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 100.1 , 5 )
12691308with 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
12731319with 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
12771325with 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
12801342def test_train_buffer_protocol_samples (self ):
12811343def _nbytes (dat ):
0 commit comments