當前位置: 首頁>>代碼示例>>Python>>正文


Python application.Application類代碼示例

本文整理匯總了Python中cleo.application.Application的典型用法代碼示例。如果您正苦於以下問題:Python Application類的具體用法?Python Application怎麽用?Python Application使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Application類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_merge_application_definition

    def test_merge_application_definition(self):
        """
        Command.merge_application_definition() merges command and application.
        """
        application1 = Application()
        application1.get_definition().add_arguments([InputArgument('foo')])
        application1.get_definition().add_options([InputOption('bar')])
        command = TestCommand()
        command.set_application(application1)
        command.set_definition(
            InputDefinition([
                InputArgument('bar'),
                InputOption('foo')
            ])
        )

        command.merge_application_definition()
        self.assertTrue(command.get_definition().has_argument('foo'))
        self.assertTrue(command.get_definition().has_option('foo'))
        self.assertTrue(command.get_definition().has_argument('bar'))
        self.assertTrue(command.get_definition().has_option('bar'))

        # It should not merge the definitions twice
        command.merge_application_definition()
        self.assertEqual(3, command.get_definition().get_argument_count())
開發者ID:onema,項目名稱:cleo,代碼行數:25,代碼來源:test_command.py

示例2: test_render_exception

    def test_render_exception(self):
        """
        Application.render_exception() displays formatted exception.
        """
        application = Application()
        application.set_auto_exit(False)

        application.get_terminal_width = self.mock().MagicMock(return_value=120)
        tester = ApplicationTester(application)

        tester.run([("command", "foo")], {"decorated": False})
        self.assertEqual(self.open_fixture("application_renderexception1.txt"), tester.get_display())

        tester.run([("command", "foo")], {"decorated": False, "verbosity": Output.VERBOSITY_VERBOSE})
        self.assertRegex(tester.get_display(), "Exception trace")

        tester.run([("command", "list"), ("--foo", True)], {"decorated": False})
        self.assertEqual(self.open_fixture("application_renderexception2.txt"), tester.get_display())

        application.add(Foo3Command())
        tester = ApplicationTester(application)
        tester.run([("command", "foo3:bar")], {"decorated": False})
        self.assertEqual(self.open_fixture("application_renderexception3.txt"), tester.get_display())
        tester = ApplicationTester(application)
        tester.run([("command", "foo3:bar")], {"decorated": True})
        self.assertEqual(self.open_fixture("application_renderexception3decorated.txt"), tester.get_display())

        application = Application()
        application.set_auto_exit(False)

        application.get_terminal_width = self.mock().MagicMock(return_value=31)
        tester = ApplicationTester(application)

        tester.run([("command", "foo")], {"decorated": False})
        self.assertEqual(self.open_fixture("application_renderexception4.txt"), tester.get_display())
開發者ID:onema,項目名稱:cleo,代碼行數:35,代碼來源:test_application.py

示例3: test_get_long_version

    def test_get_long_version(self):
        """
        Application.get_long_version() returns the long version of the application
        """
        application = Application("foo", "bar")

        self.assertEqual("<info>foo</info> version <comment>bar</comment>", application.get_long_version())
開發者ID:onema,項目名稱:cleo,代碼行數:7,代碼來源:test_application.py

示例4: test_combined_decorators

    def test_combined_decorators(self):
        """
        Combining decorators should register a command with arguments and options
        """
        application = Application()

        @application.command("decorated_foo", description="Foo command")
        @application.argument("foo", description="Foo argument", required=True, is_list=True)
        @application.option("bar", "b", description="Bar option", value_required=True, is_list=True)
        def decorated_foo_code(i, o):
            """Foo Description"""
            o.writeln("called")

        self.assertTrue(application.has("decorated_foo"))

        command = application.get("decorated_foo")
        self.assertEqual(command._code, decorated_foo_code)
        self.assertEqual(command.get_description(), "Foo command")
        self.assertTrue("decorated_foo_code" in command.get_aliases())

        argument = command.get_definition().get_argument("foo")
        self.assertEqual("Foo argument", argument.get_description())
        self.assertTrue(argument.is_required())
        self.assertTrue(argument.is_list())

        option = command.get_definition().get_option("bar")
        self.assertEqual("b", option.get_shortcut())
        self.assertEqual("Bar option", option.get_description())
        self.assertTrue(option.is_value_required())
        self.assertTrue(option.is_list())
開發者ID:onema,項目名稱:cleo,代碼行數:30,代碼來源:test_application.py

示例5: test_help

    def test_help(self):
        """
        Application.get_help() returns the help message of the application
        """
        application = Application()

        self.assertEqual(self.open_fixture("application_gethelp.txt"), application.get_help())
開發者ID:onema,項目名稱:cleo,代碼行數:7,代碼來源:test_application.py

示例6: test_register

    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")
開發者ID:onema,項目名稱:cleo,代碼行數:8,代碼來源:test_application.py

示例7: test_set_get_name

    def test_set_get_name(self):
        """
        Application name accessors behave properly
        """
        application = Application()
        application.set_name("foo")

        self.assertEqual("foo", application.get_name(), msg=".set_name() sets the name of the application")
開發者ID:onema,項目名稱:cleo,代碼行數:8,代碼來源:test_application.py

示例8: test_find_command_with_missing_namespace

    def test_find_command_with_missing_namespace(self):
        """
        Application.find() returns a command with missing namespace
        """
        application = Application()
        application.add(Foo4Command())

        self.assertTrue(isinstance(application.find("f::t"), Foo4Command))
開發者ID:onema,項目名稱:cleo,代碼行數:8,代碼來源:test_application.py

示例9: test_execute_for_application_command

 def test_execute_for_application_command(self):
     application = Application()
     tester = CommandTester(application.get('help'))
     tester.execute([('command_name', 'list')])
     self.assertRegex(
         tester.get_display(),
         'list \[--raw\] \[namespace\]'
     )
開發者ID:hason,項目名稱:cleo,代碼行數:8,代碼來源:test_help_command.py

示例10: test_set_get_version

    def test_set_get_version(self):
        """
        Application version accessors behave properly
        """
        application = Application()
        application.set_version("bar")

        self.assertEqual("bar", application.get_version(), msg=".set_version() sets the version of the application")
開發者ID:onema,項目名稱:cleo,代碼行數:8,代碼來源:test_application.py

示例11: TestApplicationTester

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.')
開發者ID:hason,項目名稱:cleo,代碼行數:58,代碼來源:test_application_tester.py

示例12: test_add_with_dictionary

    def test_add_with_dictionary(self):
        """
        Application.add() accepts a dictionary as argument.
        """
        application = Application()

        foo = application.add(foo_commmand)
        self.assertTrue(isinstance(foo, Command))
        self.assertEqual("foo:bar1", foo.get_name())
開發者ID:onema,項目名稱:cleo,代碼行數:9,代碼來源:test_application.py

示例13: find_alternative_commands_with_an_alias

    def find_alternative_commands_with_an_alias(self):
        foo_command = FooCommand()
        foo_command.set_aliases(["foo2"])

        application = Application()
        application.add(foo_command)

        result = application.find("foo")

        self.assertEqual(foo_command, result)
開發者ID:onema,項目名稱:cleo,代碼行數:10,代碼來源:test_application.py

示例14: test_find_unique_name_but_namespace_name

    def test_find_unique_name_but_namespace_name(self):
        """
        Application.find() should raise an error when command is missing
        """
        application = Application()
        application.add(FooCommand())
        application.add(Foo1Command())
        application.add(Foo2Command())

        self.assertRaisesRegexp(Exception, 'Command "foo1" is not defined', application.find, "foo1")
開發者ID:onema,項目名稱:cleo,代碼行數:10,代碼來源:test_application.py

示例15: test_run_return_exit_code_one_for_exception_code_zero

    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)
開發者ID:onema,項目名稱:cleo,代碼行數:10,代碼來源:test_application.py


注:本文中的cleo.application.Application類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。