def test_run_returns_integer_exit_code(self): command = SomeCommand() exit_code = command.run(ListInput([]), NullOutput()) self.assertEqual(0, exit_code) command = SomeCommand() command.execute = self.mock().MagicMock(return_value=2.3) exit_code = command.run(ListInput([]), NullOutput()) self.assertEqual(2, exit_code)
def test_execute_method_needs_to_be_overwridden(self): command = Command('foo') self.assertRaises( NotImplementedError, command.run, ListInput([]), NullOutput() )
def test_run_return_exit_code_one_for_exception_code_zero(self): exception = OSError(0, '') application = Application() application.set_auto_exit(False) application.do_run = self.mock().MagicMock(side_effect=exception) exit_code = application.run(ListInput([]), NullOutput()) self.assertEqual(1, exit_code)
def test_adding_already_set_definition_element_data(self): data = [[InputArgument('command', InputArgument.REQUIRED)], [InputOption('quiet', '', InputOption.VALUE_NONE)], [InputOption('query', 'q', InputOption.VALUE_NONE)]] for d in data: application = Application() application.set_auto_exit(False) application.set_catch_exceptions(False) application.register('foo')\ .set_definition(d)\ .set_code(lambda in_, out_: None) input_ = ListInput([('command', 'foo')]) output_ = NullOutput() self.assertRaises(Exception, application.run, input_, output_)
def __init__(self): super().__init__(ListInput([]), NullOutput())
def test_init(self): output = NullOutput() self.assertFalse(output.is_decorated())
def test_verbosity(self): output = NullOutput() self.assertEqual(Output.VERBOSITY_QUIET, output.get_verbosity()) output.set_verbosity(Output.VERBOSITY_VERBOSE) self.assertEqual(Output.VERBOSITY_QUIET, output.get_verbosity())