Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1094)

Unified Diff: tests/cli/helpers/output_modules.py

Issue 326740043: [plaso] Refactored options to CLI helpers #160 (Closed)
Patch Set: Changes after review and merge Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/cli/helpers/manager.py ('k') | tests/cli/helpers/status_view.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/cli/helpers/output_modules.py
diff --git a/tests/cli/helpers/output_modules.py b/tests/cli/helpers/output_modules.py
new file mode 100644
index 0000000000000000000000000000000000000000..ea6a4edcf517b4405591751b4897b66cc7b982f1
--- /dev/null
+++ b/tests/cli/helpers/output_modules.py
@@ -0,0 +1,90 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+"""Tests for the output modules CLI arguments helper."""
+
+import argparse
+import unittest
+
+from plaso.cli import tools
+from plaso.cli.helpers import output_modules
+from plaso.lib import errors
+
+from tests.cli import test_lib as cli_test_lib
+
+
+class OutputModulesArgumentsHelperTest(cli_test_lib.CLIToolTestCase):
+ """Tests for the output modules CLI arguments helper."""
+
+ # pylint: disable=protected-access
+
+ _EXPECTED_OUTPUT = u'\n'.join([
+ u'usage: cli_helper.py [-o FORMAT] [-w OUTPUT_FILE] [--fields FIELDS]',
+ u' [--additional_fields ADDITIONAL_FIELDS]',
+ u'',
+ u'Test argument parser.',
+ u'',
+ u'optional arguments:',
+ u' --additional_fields ADDITIONAL_FIELDS',
+ (u' Defines extra fields to be included in the '
+ u'output, in'),
+ (u' addition to the default fields, which are '
+ u'datetime,'),
+ (u' timestamp_desc, source, source_long, message, '
+ u'parser,'),
+ u' display_name, tag.',
+ (u' --fields FIELDS Defines which fields should be included in '
+ u'the output.'),
+ u' -o FORMAT, --output_format FORMAT, --output-format FORMAT',
+ (u' The output format. Use "-o list" to see a '
+ u'list of'),
+ u' available output formats.',
+ u' -w OUTPUT_FILE, --write OUTPUT_FILE',
+ u' Output filename.',
+ u''])
+
+ def testAddArguments(self):
+ """Tests the AddArguments function."""
+ argument_parser = argparse.ArgumentParser(
+ prog=u'cli_helper.py', description=u'Test argument parser.',
+ add_help=False,
+ formatter_class=cli_test_lib.SortedArgumentsHelpFormatter)
+
+ output_modules.OutputModulesArgumentsHelper.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.output_format = u'dynamic'
+ options.write = u'output.dynamic'
+
+ test_tool = tools.CLITool()
+
+ output_modules.OutputModulesArgumentsHelper.ParseOptions(
+ options, test_tool)
+
+ self.assertEqual(test_tool._output_format, options.output_format)
+ self.assertEqual(test_tool._output_filename, options.write)
+
+ with self.assertRaises(errors.BadConfigObject):
+ output_modules.OutputModulesArgumentsHelper.ParseOptions(options, None)
+
+ options = cli_test_lib.TestOptions()
+
+ with self.assertRaises(errors.BadConfigOption):
+ output_modules.OutputModulesArgumentsHelper.ParseOptions(
+ options, test_tool)
+
+ options.output_format = u'dynamic'
+
+ with self.assertRaises(errors.BadConfigOption):
+ output_modules.OutputModulesArgumentsHelper.ParseOptions(
+ options, test_tool)
+
+ # TODO: improve test coverage.
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « tests/cli/helpers/manager.py ('k') | tests/cli/helpers/status_view.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b