Exemplo n.º 1
0
 def _test_single_process(self, test_data):
     # Write single-shot compression to temp file.
     temp_compressed = _test_utils.get_temp_compressed_name(test_data)
     with open(temp_compressed, 'wb') as out_file:
         with open(test_data, 'rb') as in_file:
             out_file.write(self.compressor.process(in_file.read()))
         out_file.write(self.compressor.finish())
     self._check_decompression(test_data)
Exemplo n.º 2
0
 def _check_decompression(self, test_data):
     # 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)
     original = test_data
     with open(temp_uncompressed, 'wb') as out_file:
         with open(temp_compressed, 'rb') as in_file:
             out_file.write(brotli.decompress(in_file.read()))
     self.assertFilesMatch(temp_uncompressed, original)
Exemplo n.º 3
0
 def _test_multiple_process(self, test_data):
     # Write chunked compression to temp file.
     temp_compressed = _test_utils.get_temp_compressed_name(test_data)
     with open(temp_compressed, 'wb') as out_file:
         with open(test_data, 'rb') as in_file:
             read_chunk = functools.partial(in_file.read, self.CHUNK_SIZE)
             for data in iter(read_chunk, b''):
                 out_file.write(self.compressor.process(data))
         out_file.write(self.compressor.finish())
     self._check_decompression(test_data)
Exemplo n.º 4
0
 def _compress_file(self, test_data, **kwargs):
     temp_compressed = _test_utils.get_temp_compressed_name(test_data)
     args = [PYTHON, BRO, '-f']
     if 'quality' in kwargs:
         args.extend(['-q', str(kwargs['quality'])])
     if 'lgwin' in kwargs:
         args.extend(['--lgwin', str(kwargs['lgwin'])])
     if 'dictionary' in kwargs:
         args.extend(['--custom-dictionary', str(kwargs['dictionary'])])
     args.extend(['-i', test_data, '-o', temp_compressed])
     subprocess.check_call(args, env=TEST_ENV)
Exemplo n.º 5
0
 def _check_decompression(self, test_data, **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)
     original = test_data
     args = [PYTHON, BRO, '-f', '-d']
     if 'dictionary' in kwargs:
         args.extend(['--custom-dictionary', str(kwargs['dictionary'])])
     args.extend(['-i', temp_compressed, '-o', temp_uncompressed])
     subprocess.check_call(args, env=TEST_ENV)
     self.assertFilesMatch(temp_uncompressed, original)
Exemplo n.º 6
0
 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)
     original = test_data
     with open(temp_uncompressed, 'wb') as out_file:
         with open(temp_compressed, 'rb') as in_file:
             out_file.write(brotli.decompress(in_file.read(), **kwargs))
     self.assertFilesMatch(temp_uncompressed, original)
Exemplo n.º 7
0
 def _compress_pipe(self, test_data, **kwargs):
     temp_compressed = _test_utils.get_temp_compressed_name(test_data)
     args = [PYTHON, BRO]
     if 'quality' in kwargs:
         args.extend(['-q', str(kwargs['quality'])])
     if 'lgwin' in kwargs:
         args.extend(['--lgwin', str(kwargs['lgwin'])])
     if 'dictionary' in kwargs:
         args.extend(['--custom-dictionary', str(kwargs['dictionary'])])
     with open(temp_compressed, 'wb') as out_file:
         with open(test_data, 'rb') as in_file:
             subprocess.check_call(args,
                                   stdin=in_file,
                                   stdout=out_file,
                                   env=TEST_ENV)
Exemplo n.º 8
0
 def _compress(self, test_data, **kwargs):
     temp_compressed = _test_utils.get_temp_compressed_name(test_data)
     with open(temp_compressed, 'wb') as out_file:
         with open(test_data, 'rb') as in_file:
             out_file.write(brotli.compress(in_file.read(), **kwargs))