Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-132983: Split _zstd_set_c_parameters#133921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
d44dd9b6f58a95f40f0081fb521a86860c85b851a283297c96b3c74436a45174b2b442316195d5636fd862d085e60eed1a1e62fd20b37454c877a4fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -64,6 +64,10 @@ | ||
| SUPPORT_MULTITHREADING = False | ||
| C_INT_MIN = -(2**31) | ||
| C_INT_MAX = (2**31) - 1 | ||
| def setUpModule(): | ||
| global SUPPORT_MULTITHREADING | ||
| SUPPORT_MULTITHREADING = CompressionParameter.nb_workers.bounds() != (0, 0) | ||
| @@ -195,14 +199,21 @@ def test_simple_compress_bad_args(self): | ||
| self.assertRaises(TypeError, ZstdCompressor, zstd_dict=b"abcd1234") | ||
| self.assertRaises(TypeError, ZstdCompressor, zstd_dict={1: 2, 3: 4}) | ||
| with self.assertRaises(ValueError): | ||
| ZstdCompressor(2**31) | ||
| with self.assertRaises(ValueError): | ||
| ZstdCompressor(options={2**31: 100}) | ||
| # valid range for compression level is [-(1<<17), 22] | ||
| msg = r'illegal compression level {}; the valid range is \[-?\d+, -?\d+\]' | ||
| with self.assertRaisesRegex(ValueError, msg.format(C_INT_MAX)): | ||
| ZstdCompressor(C_INT_MAX) | ||
| with self.assertRaisesRegex(ValueError, msg.format(C_INT_MIN)): | ||
| ZstdCompressor(C_INT_MIN) | ||
| msg = r'illegal compression level; the valid range is \[-?\d+, -?\d+\]' | ||
| with self.assertRaisesRegex(ValueError, msg): | ||
| ZstdCompressor(level=-(2**1000)) | ||
| with self.assertRaisesRegex(ValueError, msg): | ||
| ZstdCompressor(level=2**1000) | ||
| with self.assertRaises(ZstdError): | ||
| with self.assertRaises(ValueError): | ||
| ZstdCompressor(options={CompressionParameter.window_log: 100}) | ||
| with self.assertRaises(ZstdError): | ||
| with self.assertRaises(ValueError): | ||
| ZstdCompressor(options={3333: 100}) | ||
| # Method bad arguments | ||
| @@ -253,18 +264,32 @@ def test_compress_parameters(self): | ||
| } | ||
| ZstdCompressor(options=d) | ||
| # larger than signed int, ValueError | ||
| d1 = d.copy() | ||
| d1[CompressionParameter.ldm_bucket_size_log] = 2**31 | ||
| self.assertRaises(ValueError, ZstdCompressor, options=d1) | ||
| # larger than signed int | ||
| d1[CompressionParameter.ldm_bucket_size_log] = C_INT_MAX | ||
| with self.assertRaises(ValueError): | ||
| ZstdCompressor(options=d1) | ||
| # smaller than signed int | ||
| d1[CompressionParameter.ldm_bucket_size_log] = C_INT_MIN | ||
| with self.assertRaises(ValueError): | ||
| ZstdCompressor(options=d1) | ||
| # clamp compressionLevel | ||
| # out of bounds compression level | ||
| level_min, level_max = CompressionParameter.compression_level.bounds() | ||
| compress(b'', level_max+1) | ||
| compress(b'', level_min-1) | ||
| compress(b'', options={CompressionParameter.compression_level:level_max+1}) | ||
| compress(b'', options={CompressionParameter.compression_level:level_min-1}) | ||
| with self.assertRaises(ValueError): | ||
| compress(b'', level_max+1) | ||
| with self.assertRaises(ValueError): | ||
| compress(b'', level_min-1) | ||
| with self.assertRaises(ValueError): | ||
| compress(b'', 2**1000) | ||
| with self.assertRaises(ValueError): | ||
| compress(b'', -(2**1000)) | ||
| with self.assertRaises(ValueError): | ||
| compress(b'', options={ | ||
| CompressionParameter.compression_level: level_max+1}) | ||
| with self.assertRaises(ValueError): | ||
| compress(b'', options={ | ||
| CompressionParameter.compression_level: level_min-1}) | ||
| # zstd lib doesn't support MT compression | ||
| if not SUPPORT_MULTITHREADING: | ||
| @@ -277,19 +302,19 @@ def test_compress_parameters(self): | ||
| # out of bounds error msg | ||
| option = {CompressionParameter.window_log:100} | ||
| with self.assertRaisesRegex(ZstdError, | ||
| (r'Error when setting zstd compression parameter "window_log", ' | ||
| r'it should \d+ <= value <= \d+, provided value is 100\. ' | ||
| r'\((?:32|64)-bit build\)')): | ||
| with self.assertRaisesRegex( | ||
| ValueError, | ||
| "compression parameter 'window_log' received an illegal value 100; " | ||
| r'the valid range is \[-?\d+, -?\d+\]', | ||
| ): | ||
| compress(b'', options=option) | ||
| def test_unknown_compression_parameter(self): | ||
| KEY = 100001234 | ||
| option = {CompressionParameter.compression_level: 10, | ||
| KEY: 200000000} | ||
| pattern = (r'Invalid zstd compression parameter.*?' | ||
| fr'"unknown parameter \(key {KEY}\)"') | ||
| with self.assertRaisesRegex(ZstdError, pattern): | ||
| pattern = rf"invalid compression parameter 'unknown parameter \(key {KEY}\)'" | ||
| with self.assertRaisesRegex(ValueError, pattern): | ||
| ZstdCompressor(options=option) | ||
| @unittest.skipIf(not SUPPORT_MULTITHREADING, | ||
| @@ -384,12 +409,22 @@ def test_simple_decompress_bad_args(self): | ||
| self.assertRaises(TypeError, ZstdDecompressor, options=b'abc') | ||
| with self.assertRaises(ValueError): | ||
| ZstdDecompressor(options={2**31 : 100}) | ||
| ZstdDecompressor(options={C_INT_MAX: 100}) | ||
| with self.assertRaises(ValueError): | ||
| ZstdDecompressor(options={C_INT_MIN: 100}) | ||
| with self.assertRaises(ValueError): | ||
| ZstdDecompressor(options={0: C_INT_MAX}) | ||
| with self.assertRaises(OverflowError): | ||
| ZstdDecompressor(options={2**1000: 100}) | ||
| with self.assertRaises(OverflowError): | ||
| ZstdDecompressor(options={-(2**1000): 100}) | ||
| with self.assertRaises(OverflowError): | ||
| ZstdDecompressor(options={0: -(2**1000)}) | ||
| with self.assertRaises(ZstdError): | ||
| ZstdDecompressor(options={DecompressionParameter.window_log_max:100}) | ||
| with self.assertRaises(ZstdError): | ||
| ZstdDecompressor(options={3333: 100}) | ||
| with self.assertRaises(ValueError): | ||
| ZstdDecompressor(options={DecompressionParameter.window_log_max:100}) | ||
| with self.assertRaises(ValueError): | ||
| ZstdDecompressor(options={3333: 100}) | ||
| empty = compress(b'') | ||
| lzd = ZstdDecompressor() | ||
| @@ -402,26 +437,52 @@ def test_decompress_parameters(self): | ||
| d = {DecompressionParameter.window_log_max : 15} | ||
| ZstdDecompressor(options=d) | ||
| # larger than signed int, ValueError | ||
| d1 = d.copy() | ||
| d1[DecompressionParameter.window_log_max] = 2**31 | ||
| self.assertRaises(ValueError, ZstdDecompressor, None, d1) | ||
| # larger than signed int | ||
AA-Turner marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| d1[DecompressionParameter.window_log_max] = 2**1000 | ||
| with self.assertRaises(OverflowError): | ||
| ZstdDecompressor(None, d1) | ||
| # smaller than signed int | ||
| d1[DecompressionParameter.window_log_max] = -(2**1000) | ||
| with self.assertRaises(OverflowError): | ||
| ZstdDecompressor(None, d1) | ||
| d1[DecompressionParameter.window_log_max] = C_INT_MAX | ||
AA-Turner marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| with self.assertRaises(ValueError): | ||
| ZstdDecompressor(None, d1) | ||
| d1[DecompressionParameter.window_log_max] = C_INT_MIN | ||
| with self.assertRaises(ValueError): | ||
| ZstdDecompressor(None, d1) | ||
| # out of bounds error msg | ||
| options = {DecompressionParameter.window_log_max:100} | ||
| with self.assertRaisesRegex(ZstdError, | ||
| (r'Error when setting zstd decompression parameter "window_log_max", ' | ||
| r'it should \d+ <= value <= \d+, provided value is 100\. ' | ||
| r'\((?:32|64)-bit build\)')): | ||
| with self.assertRaisesRegex( | ||
| ValueError, | ||
| "decompression parameter 'window_log_max' received an illegal value 100; " | ||
| r'the valid range is \[-?\d+, -?\d+\]', | ||
| ): | ||
| decompress(b'', options=options) | ||
| # out of bounds deecompression parameter | ||
| options[DecompressionParameter.window_log_max] = C_INT_MAX | ||
| with self.assertRaises(ValueError): | ||
| decompress(b'', options=options) | ||
| options[DecompressionParameter.window_log_max] = C_INT_MIN | ||
| with self.assertRaises(ValueError): | ||
| decompress(b'', options=options) | ||
| options[DecompressionParameter.window_log_max] = 2**1000 | ||
| with self.assertRaises(OverflowError): | ||
| decompress(b'', options=options) | ||
| options[DecompressionParameter.window_log_max] = -(2**1000) | ||
| with self.assertRaises(OverflowError): | ||
| decompress(b'', options=options) | ||
| def test_unknown_decompression_parameter(self): | ||
| KEY = 100001234 | ||
| options = {DecompressionParameter.window_log_max: DecompressionParameter.window_log_max.bounds()[1], | ||
| KEY: 200000000} | ||
| pattern = (r'Invalid zstd decompression parameter.*?' | ||
| fr'"unknown parameter \(key {KEY}\)"') | ||
| with self.assertRaisesRegex(ZstdError, pattern): | ||
| pattern = rf"invalid decompression parameter 'unknown parameter \(key {KEY}\)'" | ||
| with self.assertRaisesRegex(ValueError, pattern): | ||
| ZstdDecompressor(options=options) | ||
| def test_decompress_epilogue_flags(self): | ||
| @@ -1424,11 +1485,11 @@ def test_init_bad_mode(self): | ||
| ZstdFile(io.BytesIO(COMPRESSED_100_PLUS_32KB), "rw") | ||
| with self.assertRaisesRegex(TypeError, | ||
| r"NOT be a CompressionParameter"): | ||
| r"not be a CompressionParameter"): | ||
| ZstdFile(io.BytesIO(), 'rb', | ||
| options={CompressionParameter.compression_level:5}) | ||
| with self.assertRaisesRegex(TypeError, | ||
| r"NOT be a DecompressionParameter"): | ||
| r"not be a DecompressionParameter"): | ||
| ZstdFile(io.BytesIO(), 'wb', | ||
| options={DecompressionParameter.window_log_max:21}) | ||
| @@ -1439,19 +1500,19 @@ def test_init_bad_check(self): | ||
| with self.assertRaises(TypeError): | ||
| ZstdFile(io.BytesIO(), "w", level='asd') | ||
| # CHECK_UNKNOWN and anything above CHECK_ID_MAX should be invalid. | ||
| with self.assertRaises(ZstdError): | ||
| with self.assertRaises(ValueError): | ||
| ZstdFile(io.BytesIO(), "w", options={999:9999}) | ||
| with self.assertRaises(ZstdError): | ||
| with self.assertRaises(ValueError): | ||
| ZstdFile(io.BytesIO(), "w", options={CompressionParameter.window_log:99}) | ||
| with self.assertRaises(TypeError): | ||
| ZstdFile(io.BytesIO(COMPRESSED_100_PLUS_32KB), "r", options=33) | ||
| with self.assertRaises(ValueError): | ||
| with self.assertRaises(OverflowError): | ||
| ZstdFile(io.BytesIO(COMPRESSED_100_PLUS_32KB), | ||
| options={DecompressionParameter.window_log_max:2**31}) | ||
| with self.assertRaises(ZstdError): | ||
| with self.assertRaises(ValueError): | ||
| ZstdFile(io.BytesIO(COMPRESSED_100_PLUS_32KB), | ||
| options={444:333}) | ||
| @@ -1467,7 +1528,7 @@ def test_init_close_fp(self): | ||
| tmp_f.write(DAT_130K_C) | ||
| filename = tmp_f.name | ||
| with self.assertRaises(ValueError): | ||
| with self.assertRaises(TypeError): | ||
| ZstdFile(filename, options={'a':'b'}) | ||
| # for PyPy | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.