diff options
Diffstat (limited to 'python/tests/compress_test.py')
-rw-r--r-- | python/tests/compress_test.py | 92 |
1 files changed, 15 insertions, 77 deletions
diff --git a/python/tests/compress_test.py b/python/tests/compress_test.py index 62a07a1..7ad6efd 100644 --- a/python/tests/compress_test.py +++ b/python/tests/compress_test.py @@ -11,7 +11,14 @@ import brotli class TestCompress(_test_utils.TestCase): + VARIANTS = {'quality': (1, 6, 9, 11), 'lgwin': (10, 15, 20, 24)} + def _check_decompression(self, test_data, **kwargs): + # Only dictionary is supported as a kwarg to brotli.decompress. + if 'dictionary' in kwargs: + kwargs = {'dictionary': kwargs['dictionary']} + else: + kwargs = {} # Write decompression to temp file and verify it matches the original. temp_uncompressed = _test_utils.get_temp_uncompressed_name(test_data) temp_compressed = _test_utils.get_temp_compressed_name(test_data) @@ -27,88 +34,19 @@ class TestCompress(_test_utils.TestCase): with open(test_data, 'rb') as in_file: out_file.write(brotli.compress(in_file.read(), **kwargs)) - def _test_compress_quality_1(self, test_data): - self._compress(test_data, quality=1) - self._check_decompression(test_data) - - def _test_compress_quality_6(self, test_data): - self._compress(test_data, quality=6) - self._check_decompression(test_data) - - def _test_compress_quality_9(self, test_data): - self._compress(test_data, quality=9) - self._check_decompression(test_data) - - def _test_compress_quality_11(self, test_data): - self._compress(test_data, quality=11) - self._check_decompression(test_data) - - def _test_compress_quality_1_lgwin_10(self, test_data): - self._compress(test_data, quality=1, lgwin=10) - self._check_decompression(test_data) - - def _test_compress_quality_6_lgwin_15(self, test_data): - self._compress(test_data, quality=6, lgwin=15) - self._check_decompression(test_data) - - def _test_compress_quality_9_lgwin_20(self, test_data): - self._compress(test_data, quality=9, lgwin=20) - self._check_decompression(test_data) - - def _test_compress_quality_11_lgwin_24(self, test_data): - self._compress(test_data, quality=11, lgwin=24) - self._check_decompression(test_data) - - def _test_compress_quality_1_custom_dictionary(self, test_data): - with open(test_data, 'rb') as in_file: - dictionary = in_file.read() - self._compress(test_data, quality=1, dictionary=dictionary) - self._check_decompression(test_data, dictionary=dictionary) - - def _test_compress_quality_6_custom_dictionary(self, test_data): - with open(test_data, 'rb') as in_file: - dictionary = in_file.read() - self._compress(test_data, quality=6, dictionary=dictionary) - self._check_decompression(test_data, dictionary=dictionary) - - def _test_compress_quality_9_custom_dictionary(self, test_data): - with open(test_data, 'rb') as in_file: - dictionary = in_file.read() - self._compress(test_data, quality=9, dictionary=dictionary) - self._check_decompression(test_data, dictionary=dictionary) - - def _test_compress_quality_11_custom_dictionary(self, test_data): - with open(test_data, 'rb') as in_file: - dictionary = in_file.read() - self._compress(test_data, quality=11, dictionary=dictionary) - self._check_decompression(test_data, dictionary=dictionary) - - def _test_compress_quality_1_lgwin_10_custom_dictionary(self, test_data): - with open(test_data, 'rb') as in_file: - dictionary = in_file.read() - self._compress(test_data, quality=1, lgwin=10, dictionary=dictionary) - self._check_decompression(test_data, dictionary=dictionary) - - def _test_compress_quality_6_lgwin_15_custom_dictionary(self, test_data): - with open(test_data, 'rb') as in_file: - dictionary = in_file.read() - self._compress(test_data, quality=6, lgwin=15, dictionary=dictionary) - self._check_decompression(test_data, dictionary=dictionary) - - def _test_compress_quality_9_lgwin_20_custom_dictionary(self, test_data): - with open(test_data, 'rb') as in_file: - dictionary = in_file.read() - self._compress(test_data, quality=9, lgwin=20, dictionary=dictionary) - self._check_decompression(test_data, dictionary=dictionary) + def _test_compress(self, test_data, **kwargs): + self._compress(test_data, **kwargs) + self._check_decompression(test_data, **kwargs) - def _test_compress_quality_11_lgwin_24_custom_dictionary(self, test_data): + def _test_compress_custom_dictionary(self, test_data, **kwargs): with open(test_data, 'rb') as in_file: dictionary = in_file.read() - self._compress(test_data, quality=11, lgwin=24, dictionary=dictionary) - self._check_decompression(test_data, dictionary=dictionary) + kwargs['dictionary'] = dictionary + self._compress(test_data, **kwargs) + self._check_decompression(test_data, **kwargs) -_test_utils.generate_test_methods(TestCompress) +_test_utils.generate_test_methods(TestCompress, variants=TestCompress.VARIANTS) if __name__ == '__main__': unittest.main() |