OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 # -*- coding: utf-8 -*- |
| 3 """Tests for the data location CLI arguments helper.""" |
| 4 |
| 5 import argparse |
| 6 import unittest |
| 7 |
| 8 from plaso.cli import tools |
| 9 from plaso.cli.helpers import data_location |
| 10 from plaso.lib import errors |
| 11 |
| 12 from tests.cli import test_lib as cli_test_lib |
| 13 |
| 14 |
| 15 class DataLocationArgumentsHelperTest(cli_test_lib.CLIToolTestCase): |
| 16 """Tests for the data location CLI arguments helper.""" |
| 17 |
| 18 # pylint: disable=protected-access |
| 19 |
| 20 _EXPECTED_OUTPUT = u'\n'.join([ |
| 21 u'usage: cli_helper.py [--data PATH]', |
| 22 u'', |
| 23 u'Test argument parser.', |
| 24 u'', |
| 25 u'optional arguments:', |
| 26 u' --data PATH the location of the data files.', |
| 27 u'']) |
| 28 |
| 29 def testAddArguments(self): |
| 30 """Tests the AddArguments function.""" |
| 31 argument_parser = argparse.ArgumentParser( |
| 32 prog=u'cli_helper.py', description=u'Test argument parser.', |
| 33 add_help=False, |
| 34 formatter_class=cli_test_lib.SortedArgumentsHelpFormatter) |
| 35 |
| 36 data_location.DataLocationArgumentsHelper.AddArguments(argument_parser) |
| 37 |
| 38 output = self._RunArgparseFormatHelp(argument_parser) |
| 39 self.assertEqual(output, self._EXPECTED_OUTPUT) |
| 40 |
| 41 def testParseOptions(self): |
| 42 """Tests the ParseOptions function.""" |
| 43 options = cli_test_lib.TestOptions() |
| 44 options.data_location = self._GetTestFilePath([u'testdir']) |
| 45 |
| 46 test_tool = tools.CLITool() |
| 47 data_location.DataLocationArgumentsHelper.ParseOptions(options, test_tool) |
| 48 |
| 49 self.assertEqual(test_tool._data_location, options.data_location) |
| 50 |
| 51 with self.assertRaises(errors.BadConfigObject): |
| 52 data_location.DataLocationArgumentsHelper.ParseOptions(options, None) |
| 53 |
| 54 # TODO: improve test coverage. |
| 55 |
| 56 |
| 57 if __name__ == '__main__': |
| 58 unittest.main() |
OLD | NEW |