示例#1
0
    def test_execute(self):
        """
        ListCommand.execute() behaves properly
        """
        application = Application()

        command = application.get('list')

        command_tester = CommandTester(command)
        command_tester.execute([('command', command.get_name())], {'decorated': False})
        self.assertTrue(re.match('(?s).*help   Displays help for a command.*', command_tester.get_display()) is not None,
                        msg='.execute() returns a list of available commands')

        command_tester.execute([('command', command.get_name()), ('--raw', True)])
        output = """help   Displays help for a command
list   Lists commands"""
        self.assertEqual(output, command_tester.get_display())
示例#2
0
class TestCommandTester(TestCase):
    def setUp(self):
        self.command = Command('foo')
        self.command.add_argument('command')
        self.command.add_argument('foo')
        self.command.set_code(lambda input_, output_: output_.writeln('foo'))

        self.tester = CommandTester(self.command)
        self.tester.execute(
            [('foo', 'bar')], {
                'interactive': False,
                'decorated': False,
                'verbosity': Output.VERBOSITY_VERBOSE
            })

    def tearDown(self):
        self.command = None
        self.tester = None

    def test_execute(self):
        """
        CommandTester.execute() behaves properly
        """
        self.assertFalse(self.tester.get_input().is_interactive(),
                         msg='.execute() takes an interactive option.')
        self.assertFalse(self.tester.get_output().is_decorated(),
                         msg='.execute() takes a decorated option.')
        self.assertEqual(Output.VERBOSITY_VERBOSE,
                         self.tester.get_output().get_verbosity(),
                         msg='.execute() takes an interactive option.')

    def test_get_input(self):
        """
        CommandTester.get_input() behaves properly
        """
        self.assertEqual(
            'bar',
            self.tester.get_input().get_argument('foo'),
            msg='.get_input() returns the current input instance.')

    def test_get_output(self):
        """
        CommandTester.get_output() behaves properly
        """
        self.tester.get_output().get_stream().seek(0)
        self.assertEqual(
            'foo\n',
            self.tester.get_output().get_stream().read().decode(),
            msg='.get_output() returns the current output instance.')

    def test_get_display(self):
        """
        CommandTester.get_display() behaves properly
        """
        self.assertEqual(
            'foo\n',
            self.tester.get_display(),
            msg='.get_display() returns the display of the last execution.')
示例#3
0
    def test_execute(self):
        """
        ListCommand.execute() behaves properly
        """
        application = Application()

        command = application.get('list')

        command_tester = CommandTester(command)
        command_tester.execute([('command', command.get_name())],
                               {'decorated': False})
        self.assertTrue(re.match('(?s).*help   Displays help for a command.*',
                                 command_tester.get_display()) is not None,
                        msg='.execute() returns a list of available commands')

        command_tester.execute([('command', command.get_name()),
                                ('--raw', True)])
        output = """help   Displays help for a command
list   Lists commands"""
        self.assertEqual(output, command_tester.get_display())
示例#4
0
    def test_execute(self):
        """
        ListCommand.execute() behaves properly
        """
        application = Application()

        command = application.get('list')

        command_tester = CommandTester(command)
        command_tester.execute([('command', command.get_name())],
                               {'decorated': False})
        self.assertRegex(command_tester.get_display(),
                         'help\s{2,}Displays help for a command')

        command_tester.execute([('command', command.get_name()),
                                ('--raw', True)])
        output = """help   Displays help for a command
list   Lists commands

"""
        self.assertEqual(output, command_tester.get_display())
示例#5
0
class TestCommandTester(TestCase):

    def setUp(self):
        self.command = Command('foo')
        self.command.add_argument('command')
        self.command.add_argument('foo')
        self.command.set_code(lambda input_, output_: output_.writeln('foo'))

        self.tester = CommandTester(self.command)
        self.tester.execute([('foo', 'bar')],
                            {'interactive': False,
                             'decorated': False,
                             'verbosity': Output.VERBOSITY_VERBOSE})

    def tearDown(self):
        self.command = None
        self.tester = None

    def test_execute(self):
        """
        CommandTester.execute() behaves properly
        """
        self.assertFalse(self.tester.get_input().is_interactive(),
                         msg='.execute() takes an interactive option.')
        self.assertFalse(self.tester.get_output().is_decorated(),
                         msg='.execute() takes a decorated option.')
        self.assertEqual(Output.VERBOSITY_VERBOSE, self.tester.get_output().get_verbosity(),
                         msg='.execute() takes an interactive option.')

    def test_get_input(self):
        """
        CommandTester.get_input() behaves properly
        """
        self.assertEqual('bar', self.tester.get_input().get_argument('foo'),
                         msg='.get_input() returns the current input instance.')

    def test_get_output(self):
        """
        CommandTester.get_output() behaves properly
        """
        self.tester.get_output().get_stream().seek(0)
        self.assertEqual('foo\n', self.tester.get_output().get_stream().read().decode(),
                         msg='.get_output() returns the current output instance.')

    def test_get_display(self):
        """
        CommandTester.get_display() behaves properly
        """
        self.assertEqual('foo\n', self.tester.get_display(),
                         msg='.get_display() returns the display of the last execution.')
示例#6
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))
示例#7
0
class TestCommandTester(TestCase):
    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 tearDown(self):
        self.command = None
        self.tester = None

    def test_execute(self):
        """
        CommandTester.execute() behaves properly
        """
        self.assertFalse(self.tester.get_input().is_interactive(),
                         msg='.execute() takes an interactive option.')
        self.assertFalse(self.tester.get_output().is_decorated(),
                         msg='.execute() takes a decorated option.')
        self.assertEqual(Output.VERBOSITY_VERBOSE,
                         self.tester.get_output().get_verbosity(),
                         msg='.execute() takes an interactive option.')

    def test_get_input(self):
        """
        CommandTester.get_input() behaves properly
        """
        self.assertEqual(
            'bar',
            self.tester.get_input().get_argument('foo'),
            msg='.get_input() returns the current input instance.')

    def test_get_output(self):
        """
        CommandTester.get_output() behaves properly
        """
        self.tester.get_output().get_stream().seek(0)
        self.assertEqual(
            'foo\n',
            self.tester.get_output().get_stream().read().decode(),
            msg='.get_output() returns the current output instance.')

    def test_get_display(self):
        """
        CommandTester.get_display() behaves properly
        """
        self.assertEqual(
            'foo\n',
            self.tester.get_display(),
            msg='.get_display() returns the display of the last execution.')

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