File: manager.py

package info (click to toggle)
dfvfs 20160918-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 96,408 kB
  • ctags: 2,759
  • sloc: python: 22,682; makefile: 57; vhdl: 25; sh: 16
file content (64 lines) | stat: -rw-r--r-- 1,820 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Tests for the encoding manager."""

import unittest

from dfvfs.encoding import base16_decoder
from dfvfs.encoding import decoder
from dfvfs.encoding import manager
from dfvfs.lib import definitions

from tests import test_lib as shared_test_lib


class TestDecoder(decoder.Decoder):
  """Class that implements a test decoder."""

  ENCODING_METHOD = u'test'

  def Decode(self, unused_encoded_data):
    """Decode the encoded data.

    Args:
      encoded_data: a byte string containing the encoded data.

    Returns:
      A tuple containing a byte string of the decoded data and
      the remaining encoded data.
    """
    return b'', b''


class EncodingManagerTest(shared_test_lib.BaseTestCase):
  """Class to test the encoding manager."""

  def testDecoderRegistration(self):
    """Tests the DeregisterDecoder and DeregisterDecoder functions."""
    # pylint: disable=protected-access
    number_of_decoders = len(manager.EncodingManager._decoders)

    manager.EncodingManager.RegisterDecoder(TestDecoder)
    self.assertEqual(
        len(manager.EncodingManager._decoders),
        number_of_decoders + 1)

    with self.assertRaises(KeyError):
      manager.EncodingManager.RegisterDecoder(TestDecoder)

    manager.EncodingManager.DeregisterDecoder(TestDecoder)
    self.assertEqual(
        len(manager.EncodingManager._decoders), number_of_decoders)

  def testGetDecoder(self):
    """Function to test the GetDecoder function."""
    decoder_object = manager.EncodingManager.GetDecoder(
        definitions.ENCODING_METHOD_BASE16)
    self.assertIsInstance(decoder_object, base16_decoder.Base16Decoder)

    decoder_object = manager.EncodingManager.GetDecoder(u'bogus')
    self.assertIsNone(decoder_object)


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