| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
import unittest |
| 7 |
|
| 8 |
import brotli |
| 9 |
|
| 10 |
from . import _test_utils |
| 11 |
|
| 12 |
|
| 13 |
def _get_original_name(test_data): |
| 14 |
return test_data.split('.compressed')[0] |
| 15 |
|
| 16 |
|
| 17 |
class TestDecompress(_test_utils.TestCase): |
| 18 |
|
| 19 |
def _check_decompression(self, test_data): |
| 20 |
|
| 21 |
temp_uncompressed = _test_utils.get_temp_uncompressed_name(test_data) |
| 22 |
original = _get_original_name(test_data) |
| 23 |
self.assert_files_match(temp_uncompressed, original) |
| 24 |
|
| 25 |
def _decompress(self, test_data): |
| 26 |
temp_uncompressed = _test_utils.get_temp_uncompressed_name(test_data) |
| 27 |
with open(temp_uncompressed, 'wb') as out_file: |
| 28 |
with open(test_data, 'rb') as in_file: |
| 29 |
out_file.write(brotli.decompress(in_file.read())) |
| 30 |
|
| 31 |
def _test_decompress(self, test_data): |
| 32 |
self._decompress(test_data) |
| 33 |
self._check_decompression(test_data) |
| 34 |
|
| 35 |
def test_garbage_appended(self): |
| 36 |
with self.assertRaises(brotli.error): |
| 37 |
brotli.decompress(brotli.compress(b'a') + b'a') |
| 38 |
|
| 39 |
|
| 40 |
_test_utils.generate_test_methods(TestDecompress, for_decompression=True) |
| 41 |
|
| 42 |
if __name__ == '__main__': |
| 43 |
unittest.main() |