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