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)
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)
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)