@@ -1139,27 +1139,41 @@ def test_invalid_dict(self):
1139
1139
ZstdDecompressor (zd )
1140
1140
1141
1141
# 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' ):
1145
1149
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' ):
1147
1151
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' ):
1149
1153
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' ):
1154
1166
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' ):
1156
1168
ZstdDecompressor ((zd , - 1 ))
1157
- with self .assertRaisesRegex (TypeError , r'should be ZstdDict object' ):
1169
+ with self .assertRaisesRegex (TypeError , r'should be a ZstdDict object' ):
1158
1170
ZstdDecompressor ((zd , 3 ))
1171
+ with self .assertRaises (OverflowError ):
1172
+ ZstdDecompressor ((zd , 2 ** 1000 ))
1173
+ with self .assertRaises (OverflowError ):
1174
+ ZstdDecompressor ((zd , - 2 ** 1000 ))
1159
1175
1160
1176
def test_train_dict (self ):
1161
-
1162
-
1163
1177
TRAINED_DICT = train_dict (SAMPLES , DICT_SIZE1 )
1164
1178
ZstdDict (TRAINED_DICT .dict_content , is_raw = False )
1165
1179
@@ -1240,18 +1254,37 @@ def test_train_dict_c(self):
1240
1254
# argument wrong type
1241
1255
with self .assertRaises (TypeError ):
1242
1256
_zstd .train_dict ({}, (), 100 )
1257
+ with self .assertRaises (TypeError ):
1258
+ _zstd .train_dict (bytearray (), (), 100 )
1243
1259
with self .assertRaises (TypeError ):
1244
1260
_zstd .train_dict (b'' , 99 , 100 )
1261
+ with self .assertRaises (TypeError ):
1262
+ _zstd .train_dict (b'' , [], 100 )
1245
1263
with self .assertRaises (TypeError ):
1246
1264
_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 )
1247
1273
1248
1274
# size > size_t
1249
1275
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 )
1251
1279
1252
1280
# dict_size <= 0
1253
1281
with self .assertRaises (ValueError ):
1254
1282
_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 )
1255
1288
1256
1289
def test_finalize_dict_c (self ):
1257
1290
with self .assertRaises (TypeError ):
@@ -1260,22 +1293,51 @@ def test_finalize_dict_c(self):
1260
1293
# argument wrong type
1261
1294
with self .assertRaises (TypeError ):
1262
1295
_zstd .finalize_dict ({}, b'' , (), 100 , 5 )
1296
+ with self .assertRaises (TypeError ):
1297
+ _zstd .finalize_dict (bytearray (TRAINED_DICT .dict_content ), b'' , (), 100 , 5 )
1263
1298
with self .assertRaises (TypeError ):
1264
1299
_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 )
1265
1302
with self .assertRaises (TypeError ):
1266
1303
_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 )
1267
1306
with self .assertRaises (TypeError ):
1268
1307
_zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 100.1 , 5 )
1269
1308
with self .assertRaises (TypeError ):
1270
1309
_zstd .finalize_dict (TRAINED_DICT .dict_content , b'' , (), 100 , 5.1 )
1271
1310
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
+
1272
1318
# size > size_t
1273
1319
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 )
1275
1323
1276
1324
# dict_size <= 0
1277
1325
with self .assertRaises (ValueError ):
1278
1326
_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 )
1279
1341
1280
1342
def test_train_buffer_protocol_samples (self ):
1281
1343
def _nbytes (dat ):
0 commit comments