Debian Codegraph @

python/tests/compress_test.py

raw symbols SCIP
1 # Copyright 2016 The Brotli Authors. All rights reserved.
2 #
3 # Distributed under MIT license.
4 # See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
6 import unittest
7
8 import brotli
9
10 from . import _test_utils
11
12
13 class TestCompress(_test_utils.TestCase):
14
15 VARIANTS = {'quality': (1, 6, 9, 11), 'lgwin': (10, 15, 20, 24)}
16
17 def _check_decompression(self, test_data):
18 # Write decompression to temp file and verify it matches the original.
19 temp_uncompressed = _test_utils.get_temp_uncompressed_name(test_data)
20 temp_compressed = _test_utils.get_temp_compressed_name(test_data)
21 original = test_data
22 with open(temp_uncompressed, 'wb') as out_file:
23 with open(temp_compressed, 'rb') as in_file:
24 out_file.write(brotli.decompress(in_file.read()))
25 self.assert_files_match(temp_uncompressed, original)
26
27 def _compress(self, test_data, **kwargs):
28 temp_compressed = _test_utils.get_temp_compressed_name(test_data)
29 with open(temp_compressed, 'wb') as out_file:
30 with open(test_data, 'rb') as in_file:
31 out_file.write(brotli.compress(in_file.read(), **kwargs))
32
33 def _test_compress(self, test_data, **kwargs):
34 self._compress(test_data, **kwargs)
35 self._check_decompression(test_data)
36
37
38 _test_utils.generate_test_methods(TestCompress, variants=TestCompress.VARIANTS)
39
40 if __name__ == '__main__':
41 unittest.main()