File: bzip2_decompressor.py

package info (click to toggle)
dfvfs 20201219-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 284,900 kB
  • sloc: python: 30,025; vhdl: 1,921; sh: 465; makefile: 16
file content (42 lines) | stat: -rw-r--r-- 1,272 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests for the bzip2 decompressor object."""

from __future__ import unicode_literals

import unittest

from dfvfs.compression import bzip2_decompressor
from dfvfs.lib import errors

from tests.compression import test_lib


class BZIP2DecompressorTestCase(test_lib.DecompressorTestCase):
  """Tests for the bzip2 decompressor object."""

  def testDecompress(self):
    """Tests the Decompress method."""
    decompressor = bzip2_decompressor.BZIP2Decompressor()

    compressed_data = (
        b'BZh91AY&SYa\x0e\xf5A\x00\x00\x02\x13\x80@\x01\x04\x00"`\x0c\x00 '
        b'\x00!\xa3M\x19\x082b\x18Q#\xa5\xc1"\xf1w$S\x85\t\x06\x10\xefT\x10')

    uncompressed_data, _ = decompressor.Decompress(compressed_data)
    expected_uncompressed_data = b'This is a test.'
    self.assertEqual(uncompressed_data, expected_uncompressed_data)

    # Test to trigger bz2 raising EOFError.
    with self.assertRaises(errors.BackEndError):
      decompressor.Decompress(b'This is a test.')

    # Test to trigger bz2 raising IOError.
    decompressor = bzip2_decompressor.BZIP2Decompressor()

    with self.assertRaises(errors.BackEndError):
      decompressor.Decompress(b'This is a test.')


if __name__ == '__main__':
  unittest.main()