Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
aaronp
2017/07/14 00:31:42
Note to self: reviewed.
Joachim Metz
2017/07/27 05:43:54
Done.
| |
2 # -*- coding: utf-8 -*- | |
3 """Tests for the analysis plugins CLI arguments helper.""" | |
4 | |
5 import argparse | |
6 import unittest | |
7 | |
8 from plaso.cli import tools | |
9 from plaso.cli.helpers import analysis_plugins | |
10 from plaso.lib import errors | |
11 | |
12 from tests.cli import test_lib as cli_test_lib | |
13 | |
14 | |
15 class AnalysisPluginsArgumentsHelperTest(cli_test_lib.CLIToolTestCase): | |
16 """Tests for the analysis plugins CLI arguments helper.""" | |
17 | |
18 # pylint: disable=protected-access | |
19 | |
20 _EXPECTED_OUTPUT = u'\n'.join([ | |
21 u'usage: cli_helper.py [--analysis PLUGIN_LIST]', | |
22 u'', | |
23 u'Test argument parser.', | |
24 u'', | |
25 u'optional arguments:', | |
26 u' --analysis PLUGIN_LIST', | |
27 (u' A comma separated list of analysis plugin ' | |
28 u'names to be'), | |
29 (u' loaded or "--analysis list" to see a list ' | |
30 u'of available'), | |
31 u' plugins.', | |
32 u'']) | |
33 | |
34 def testAddArguments(self): | |
35 """Tests the AddArguments function.""" | |
36 argument_parser = argparse.ArgumentParser( | |
37 prog=u'cli_helper.py', description=u'Test argument parser.', | |
38 add_help=False, | |
39 formatter_class=cli_test_lib.SortedArgumentsHelpFormatter) | |
40 | |
41 analysis_plugins.AnalysisPluginsArgumentsHelper.AddArguments( | |
42 argument_parser) | |
43 | |
44 output = self._RunArgparseFormatHelp(argument_parser) | |
45 self.assertEqual(output, self._EXPECTED_OUTPUT) | |
46 | |
47 def testParseOptions(self): | |
48 """Tests the ParseOptions function.""" | |
49 options = cli_test_lib.TestOptions() | |
50 options.analysis_plugins = u'tagging' | |
51 | |
52 test_tool = tools.CLITool() | |
53 analysis_plugins.AnalysisPluginsArgumentsHelper.ParseOptions( | |
54 options, test_tool) | |
55 | |
56 self.assertEqual(test_tool._analysis_plugins, [u'tagging']) | |
57 | |
58 with self.assertRaises(errors.BadConfigObject): | |
59 analysis_plugins.AnalysisPluginsArgumentsHelper.ParseOptions( | |
60 options, None) | |
61 | |
62 options.analysis_plugins = u'bogus' | |
63 | |
64 with self.assertRaises(errors.BadConfigOption): | |
65 analysis_plugins.AnalysisPluginsArgumentsHelper.ParseOptions( | |
66 options, test_tool) | |
67 | |
68 # TODO: improve test coverage. | |
aaronp
2017/07/14 00:31:42
Maybe add testing '--analysis list' specifically t
Joachim Metz
2017/07/27 05:43:54
Done.
| |
69 | |
70 | |
71 if __name__ == '__main__': | |
72 unittest.main() | |
OLD | NEW |