(self)
| 1240 | ZstdDict(desk333=345) |
| 1241 | |
| 1242 | def test_invalid_dict(self): |
| 1243 | DICT_MAGIC = 0xEC30A437.to_bytes(4, byteorder='little') |
| 1244 | dict_content = DICT_MAGIC + b'abcdefghighlmnopqrstuvwxyz' |
| 1245 | |
| 1246 | # corrupted |
| 1247 | zd = ZstdDict(dict_content, is_raw=False) |
| 1248 | with self.assertRaisesRegex(ZstdError, r'ZSTD_CDict.*?content\.$'): |
| 1249 | ZstdCompressor(zstd_dict=zd.as_digested_dict) |
| 1250 | with self.assertRaisesRegex(ZstdError, r'ZSTD_DDict.*?content\.$'): |
| 1251 | ZstdDecompressor(zd) |
| 1252 | |
| 1253 | # wrong type |
| 1254 | with self.assertRaisesRegex(TypeError, r'should be a ZstdDict object'): |
| 1255 | ZstdCompressor(zstd_dict=[zd, 1]) |
| 1256 | with self.assertRaisesRegex(TypeError, r'should be a ZstdDict object'): |
| 1257 | ZstdCompressor(zstd_dict=(zd, 1.0)) |
| 1258 | with self.assertRaisesRegex(TypeError, r'should be a ZstdDict object'): |
| 1259 | ZstdCompressor(zstd_dict=(zd,)) |
| 1260 | with self.assertRaisesRegex(TypeError, r'should be a ZstdDict object'): |
| 1261 | ZstdCompressor(zstd_dict=(zd, 1, 2)) |
| 1262 | with self.assertRaisesRegex(TypeError, r'should be a ZstdDict object'): |
| 1263 | ZstdCompressor(zstd_dict=(zd, -1)) |
| 1264 | with self.assertRaisesRegex(TypeError, r'should be a ZstdDict object'): |
| 1265 | ZstdCompressor(zstd_dict=(zd, 3)) |
| 1266 | with self.assertRaises(OverflowError): |
| 1267 | ZstdCompressor(zstd_dict=(zd, 2**1000)) |
| 1268 | with self.assertRaises(OverflowError): |
| 1269 | ZstdCompressor(zstd_dict=(zd, -2**1000)) |
| 1270 | |
| 1271 | with self.assertRaisesRegex(TypeError, r'should be a ZstdDict object'): |
| 1272 | ZstdDecompressor(zstd_dict=[zd, 1]) |
| 1273 | with self.assertRaisesRegex(TypeError, r'should be a ZstdDict object'): |
| 1274 | ZstdDecompressor(zstd_dict=(zd, 1.0)) |
| 1275 | with self.assertRaisesRegex(TypeError, r'should be a ZstdDict object'): |
| 1276 | ZstdDecompressor((zd,)) |
| 1277 | with self.assertRaisesRegex(TypeError, r'should be a ZstdDict object'): |
| 1278 | ZstdDecompressor((zd, 1, 2)) |
| 1279 | with self.assertRaisesRegex(TypeError, r'should be a ZstdDict object'): |
| 1280 | ZstdDecompressor((zd, -1)) |
| 1281 | with self.assertRaisesRegex(TypeError, r'should be a ZstdDict object'): |
| 1282 | ZstdDecompressor((zd, 3)) |
| 1283 | with self.assertRaises(OverflowError): |
| 1284 | ZstdDecompressor((zd, 2**1000)) |
| 1285 | with self.assertRaises(OverflowError): |
| 1286 | ZstdDecompressor((zd, -2**1000)) |
| 1287 | |
| 1288 | def test_train_dict(self): |
| 1289 | TRAINED_DICT = train_dict(SAMPLES, DICT_SIZE1) |
nothing calls this directly
no test coverage detected