File: bzip2_decompressor.py

package info (click to toggle)
dfvfs 20240505-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 475,508 kB
  • sloc: python: 36,533; vhdl: 1,922; sh: 448; xml: 52; makefile: 16
file content (40 lines) | stat: -rw-r--r-- 1,231 bytes parent folder | download
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests for the bzip2 decompressor object."""

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()