当前位置: 首页>>代码示例>>Python>>正文


Python Application.has方法代码示例

本文整理汇总了Python中cleo.application.Application.has方法的典型用法代码示例。如果您正苦于以下问题:Python Application.has方法的具体用法?Python Application.has怎么用?Python Application.has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cleo.application.Application的用法示例。


在下文中一共展示了Application.has方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_combined_decorators

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import has [as 别名]
    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,代码行数:32,代码来源:test_application.py

示例2: test_has_get

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import has [as 别名]
    def test_has_get(self):
        """
        Application.has() and Application.get() should determine and get commands
        """
        application = Application()

        self.assertTrue(application.has("list"), msg=".has() returns true if a command is registered")
        self.assertFalse(application.has("afoobar"), msg=".has() returns false if a command is not registered")

        foo = FooCommand()
        application.add(foo)

        self.assertTrue(application.has("afoobar"), msg=".has() returns true if an alias is registered")
        self.assertEqual(foo, application.get("foo:bar"), msg=".get() returns a command by name")
        self.assertEqual(foo, application.get("afoobar"), msg=".get() returns a command by alias")

        application = Application()
        application.add(foo)
        # Simulate help
        application._want_helps = True
        self.assertTrue(
            isinstance(application.get("foo:bar"), HelpCommand),
            msg=".get() returns the help command if --help is provided as the input",
        )
开发者ID:onema,项目名称:cleo,代码行数:26,代码来源:test_application.py

示例3: test_command_decorator

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import has [as 别名]
    def test_command_decorator(self):
        """
        @Application.command decorator should register a command
        """
        application = Application()

        @application.command("decorated_foo", description="Foo")
        def decorated_foo_code(i, o):
            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")
        self.assertTrue("decorated_foo_code" in command.get_aliases())
开发者ID:onema,项目名称:cleo,代码行数:18,代码来源:test_application.py

示例4: test_argument_decorator

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import has [as 别名]
    def test_argument_decorator(self):
        """
        @Application.argument decorator should register a command with a specific argument
        """
        application = Application()

        @application.argument("foo", description="Foo", required=True, is_list=True)
        def decorated_foo_code(i, o):
            """Foo Description"""
            o.writeln("called")

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

        command = application.get("decorated_foo_code")
        self.assertEqual(command._code, decorated_foo_code)
        self.assertEqual(command.get_description(), "Foo Description")

        argument = command.get_definition().get_argument("foo")
        self.assertEqual("Foo", argument.get_description())
        self.assertTrue(argument.is_required())
        self.assertTrue(argument.is_list())
开发者ID:onema,项目名称:cleo,代码行数:23,代码来源:test_application.py

示例5: test_option_decorator

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import has [as 别名]
    def test_option_decorator(self):
        """
        @Application.option decorator should register a command with a specific option
        """
        application = Application()

        @application.option("foo", "f", description="Foo", value_required=True, is_list=True)
        def decorated_foo_code(i, o):
            """Foo Description"""
            o.writeln("called")

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

        command = application.get("decorated_foo_code")
        self.assertEqual(command._code, decorated_foo_code)
        self.assertEqual(command.get_description(), "Foo Description")

        option = command.get_definition().get_option("foo")
        self.assertEqual("f", option.get_shortcut())
        self.assertEqual("Foo", option.get_description())
        self.assertTrue(option.is_value_required())
        self.assertTrue(option.is_list())
开发者ID:onema,项目名称:cleo,代码行数:24,代码来源:test_application.py


注:本文中的cleo.application.Application.has方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。