Example #1
0
 def test_execute_method_needs_to_be_overwridden(self):
     command = Command('foo')
     self.assertRaises(
         NotImplementedError,
         command.run,
         ListInput([]),
         NullOutput()
     )
Example #2
0
    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'
        )
Example #3
0
    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
            })
Example #4
0
    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))
Example #5
0
def test_set_application():
    application = Application()
    command = Command()
    command.set_application(application)

    assert application == command.application
Example #6
0
def command(name: str) -> Command:
    command_ = Command()
    command_.name = name

    return command_