Example #1
0
class TestApplicationTester(TestCase):
    def setUp(self):
        self.application = Application()
        self.application.set_auto_exit(False)
        self.application.register('foo')\
            .add_argument('foo')\
            .set_code(lambda c: c.line('foo'))

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

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

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

    def test_get_input(self):
        """
        ApplicationTester.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):
        """
        ApplicationTester.get_output() behaves properly
        """
        self.tester.get_output().get_stream().seek(0)
        self.assertEqual(
            'foo\n',
            self.tester.get_output().get_stream().read().decode('utf-8'),
            msg='.get_output() returns the current output instance.')

    def test_get_display(self):
        """
        ApplicationTester.get_display() behaves properly
        """
        self.assertEqual(
            'foo\n',
            self.tester.get_display(),
            msg='.get_display() returns the display of the last execution.')
Example #2
0
class TestApplicationTester(TestCase):

    def setUp(self):
        self.application = Application()
        self.application.set_auto_exit(False)
        self.application.register('foo')\
            .add_argument('foo')\
            .set_code(lambda input_, output_: output_.writeln('foo'))

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

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

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

    def test_get_input(self):
        """
        ApplicationTester.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):
        """
        ApplicationTester.get_output() behaves properly
        """
        self.tester.get_output().get_stream().seek(0)
        self.assertEqual('foo\n', self.tester.get_output().get_stream().read().decode('utf-8'),
                         msg='.get_output() returns the current output instance.')

    def test_get_display(self):
        """
        ApplicationTester.get_display() behaves properly
        """
        self.assertEqual('foo\n', self.tester.get_display(),
                         msg='.get_display() returns the display of the last execution.')
Example #3
0
    def test_register(self):
        """
        Application.register() registers a new command
        """
        application = Application()
        command = application.register("foo")

        self.assertEqual("foo", command.get_name(), msg=".register() registers a new command")
Example #4
0
    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_)
Example #5
0
    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_)
Example #6
0
    def test_register(self):
        """
        Application.register() registers a new command
        """
        application = Application()
        command = application.register('foo')

        self.assertEqual('foo',
                         command.get_name(),
                         msg='.register() registers a new command')