Exemple #1
0
 def register_parser(self, subparsers):
     parser = subparsers.add_parser(
         "dev", help="development commands")
     subdev = parser.add_subparsers()
     ScriptCommand(self.provider, self.config).register_parser(subdev)
     SpecialCommand(self.provider).register_parser(subdev)
     AnalyzeCommand(self.provider).register_parser(subdev)
     ParseCommand().register_parser(subdev)
     CrashCommand().register_parser(subdev)
     LogTestCommand().register_parser(subdev)
Exemple #2
0
 def test_invoked(self, patched_ParseInvocation):
     # Make a fake ParserPlugIn
     mock_parser = mock.Mock(spec=ParserPlugIn)
     # Give it a plugin_name and summary
     mock_parser.plugin_name = "foo"
     mock_parser.summary = "summary of foo"
     # With temporary override to use the fake parser
     with all_parsers.fake_plugins([mock_parser]):
         # Set the name of the expected parser to 'foo'
         self.ns.parser_name = 'foo'
         # And invoke the ParseCommand
         retval = ParseCommand().invoked(self.ns)
     # Ensure that ParseInvocation was called with the fake parser
     patched_ParseInvocation.assert_called_once_with(mock_parser)
     # Ensure that ParsesCommand.invoked() returned whatever
     # was returned by ParseInvocation.run()
     self.assertEqual(
         retval,
         patched_ParseInvocation(self.ns.parser_name).run.return_value)
Exemple #3
0
 def test_register_parser(self):
     # Create an argument parser
     parser = argparse.ArgumentParser(prog='test')
     # Add subparsers to it
     subparsers = parser.add_subparsers()
     # Register the ParseCommand into subparsers
     ParseCommand().register_parser(subparsers)
     # With IO capture helper
     with TestIO() as io:
         # Print the help message
         parser.print_help()
     # Ensure that a short help message was included
     self.assertIn("parse stdin with the specified parser", io.stdout)
     # With another IO capture helper
     with TestIO() as io:
         # With a trap for SystemExit exception
         with self.assertRaises(SystemExit):
             # Run the 'parse --help' command
             parser.parse_args(['parse', '--help'])
     # Ensure that a detailed help message was printed
     self.assertEqual(io.stdout, cleandoc(self._help) + '\n')
Exemple #4
0
 def test_invoked_question_mark(self):
     # Make a fake ParserPlugIn
     mock_parser = mock.Mock(spec=ParserPlugIn)
     # Give it a plugin_name, name and summary
     mock_parser.plugin_name = "foo"
     mock_parser.name = "foo"
     mock_parser.summary = "summary of foo"
     # With temporary override to use the fake parser
     with all_parsers.fake_plugins([mock_parser]):
         # Set the name of the expected parser to '?'
         self.ns.parser_name = '?'
         # With IO capture helper
         with TestIO() as io:
             # And invoke the ParseCommand
             retval = ParseCommand().invoked(self.ns)
     # Ensure that a list of parsers was printed
     self.assertEqual(
         io.stdout,
         cleandoc("""
             The following parsers are available:
               foo: summary of foo
             """) + '\n')
     # Ensure that the return code was 0
     self.assertEqual(retval, 0)
Exemple #5
0
 def test_init(self):
     ParseCommand()