File: codepage.py

package info (click to toggle)
plaso 20241006-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 673,224 kB
  • sloc: python: 91,831; sh: 557; xml: 97; makefile: 17; sql: 14; vhdl: 11
file content (57 lines) | stat: -rw-r--r-- 1,704 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Tests for the codepage CLI arguments helper."""

import argparse
import unittest

from plaso.cli import tools
from plaso.cli.helpers import codepage
from plaso.lib import errors

from tests.cli import test_lib as cli_test_lib


class CodepagergumentsHelperTest(cli_test_lib.CLIToolTestCase):
  """Tests for the codepage CLI arguments helper."""

  # pylint: disable=no-member,protected-access

  _EXPECTED_OUTPUT = """\
usage: cli_helper.py [--codepage CODEPAGE]

Test argument parser.

{0:s}:
  --codepage CODEPAGE  The preferred codepage, which is used for decoding
                       single-byte or multi-byte character extracted strings.
""".format(cli_test_lib.ARGPARSE_OPTIONS)

  def testAddArguments(self):
    """Tests the AddArguments function."""
    argument_parser = argparse.ArgumentParser(
        prog='cli_helper.py', description='Test argument parser.',
        add_help=False,
        formatter_class=cli_test_lib.SortedArgumentsHelpFormatter)

    codepage.CodepageArgumentsHelper.AddArguments(argument_parser)

    output = self._RunArgparseFormatHelp(argument_parser)
    self.assertEqual(output, self._EXPECTED_OUTPUT)

  def testParseOptions(self):
    """Tests the ParseOptions function."""
    options = cli_test_lib.TestOptions()
    options.preferred_codepage = 'cp1252'

    test_tool = tools.CLITool()
    codepage.CodepageArgumentsHelper.ParseOptions(options, test_tool)

    self.assertEqual(test_tool._preferred_codepage, options.preferred_codepage)

    with self.assertRaises(errors.BadConfigObject):
      codepage.CodepageArgumentsHelper.ParseOptions(options, None)


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