def test_execute_method_needs_to_be_overwridden(self): command = Command('foo') self.assertRaises( NotImplementedError, command.run, ListInput([]), NullOutput() )
def test_init(self): """ Command.__init__() behaves properly """ self.assertRaises(Exception, Command) command = Command('foo:bar') self.assertEqual( 'foo:bar', command.get_name(), msg='__init__() takes the command name as its first argument' )
def setUp(self): self.command = Command('foo') self.command.add_argument('command') self.command.add_argument('foo') self.command.set_code(lambda c: c.line('foo')) self.tester = CommandTester(self.command) self.tester.execute( [('foo', 'bar')], { 'interactive': False, 'decorated': False, 'verbosity': Output.VERBOSITY_VERBOSE })
def test_command_with_inputs(self): questions = [ 'What\'s your name?', 'How are you?', 'Where do you come from?', ] def code(c): c.ask(questions[0]) c.ask(questions[1]) c.ask(questions[2]) command = Command('foo') command.set_code(code) tester = CommandTester(command) tester.set_inputs(['Bobby', 'Fine', 'France']) tester.execute([]) self.assertEqual(0, tester.status_code) self.assertEqual('\n' + ' \n\n\n'.join(questions) + ' \n', tester.get_display(True))
def test_set_application(): application = Application() command = Command() command.set_application(application) assert application == command.application
def command(name: str) -> Command: command_ = Command() command_.name = name return command_