• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
6import unittest
7
8from . import _test_utils
9import brotli
10
11
12def _get_original_name(test_data):
13    return test_data.split('.compressed')[0]
14
15
16class TestDecompress(_test_utils.TestCase):
17
18    def _check_decompression(self, test_data):
19        # Verify decompression matches the original.
20        temp_uncompressed = _test_utils.get_temp_uncompressed_name(test_data)
21        original = _get_original_name(test_data)
22        self.assertFilesMatch(temp_uncompressed, original)
23
24    def _decompress(self, test_data):
25        temp_uncompressed = _test_utils.get_temp_uncompressed_name(test_data)
26        with open(temp_uncompressed, 'wb') as out_file:
27            with open(test_data, 'rb') as in_file:
28                out_file.write(brotli.decompress(in_file.read()))
29
30    def _test_decompress(self, test_data):
31        self._decompress(test_data)
32        self._check_decompression(test_data)
33
34
35_test_utils.generate_test_methods(TestDecompress, for_decompression=True)
36
37if __name__ == '__main__':
38    unittest.main()
39