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