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


Python Application.find方法代码示例

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


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

示例1: test_find_alternative_namespace

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import find [as 别名]
    def test_find_alternative_namespace(self):
        application = Application()

        application.add(FooCommand())
        application.add(Foo1Command())
        application.add(Foo2Command())
        application.add(Foo3Command())

        try:
            application.find("Unknown-namespace:Unknown-command")
            self.fail(".find() raises an Exception if namespace does not exist")
        except Exception as e:
            self.assertRegex(str(e), 'There are no commands defined in the "Unknown-namespace" namespace.')

        try:
            application.find("foo2:command")
            self.fail(".find() raises an tException if namespace does not exist")
        except Exception as e:
            self.assertRegex(str(e), 'There are no commands defined in the "foo2" namespace.')
            self.assertRegex(
                str(e), "foo", msg='.find() raises an tException if namespace does not exist, with alternative "foo"'
            )
            self.assertRegex(
                str(e), "foo1", msg='.find() raises an tException if namespace does not exist, with alternative "foo1"'
            )
            self.assertRegex(
                str(e), "foo3", msg='.find() raises an Exception if namespace does not exist, with alternative "foo2"'
            )
开发者ID:onema,项目名称:cleo,代码行数:30,代码来源:test_application.py

示例2: test_find

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import find [as 别名]
    def test_find(self):
        """
        Application.find() should return a command
        """
        application = Application()
        application.add(FooCommand())

        self.assertTrue(
            isinstance(application.find("foo:bar"), FooCommand), msg=".find() returns a command if its name exists"
        )
        self.assertTrue(
            isinstance(application.find("h"), HelpCommand), msg=".find() returns a command if its name exists"
        )
        self.assertTrue(
            isinstance(application.find("f:bar"), FooCommand),
            msg=".find() returns a command if the abbreviation for the namespace exists",
        )
        self.assertTrue(
            isinstance(application.find("f:b"), FooCommand),
            msg=".find() returns a command if the abbreviation for the namespace and the command name exist",
        )
        self.assertTrue(
            isinstance(application.find("a"), FooCommand),
            msg=".find() returns a command if the abbreviation exists for an alias",
        )
开发者ID:onema,项目名称:cleo,代码行数:27,代码来源:test_application.py

示例3: test_find_command_equal_namesapce

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import find [as 别名]
    def test_find_command_equal_namesapce(self):
        """
        Application.find() returns a command if it has a namespace with the same name
        """
        application = Application()
        application.add(Foo3Command())
        application.add(Foo4Command())

        self.assertTrue(
            isinstance(application.find("foo3:bar"), Foo3Command),
            msg=".find() returns the good command even if a namespace has same name",
        )
        self.assertTrue(
            isinstance(application.find("foo3:bar:toh"), Foo4Command),
            msg=".find() returns a command even if its namespace equals another command name",
        )
开发者ID:onema,项目名称:cleo,代码行数:18,代码来源:test_application.py

示例4: test_find_command_with_missing_namespace

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

示例5: test_find_command_with_ambiguous_namespace_but_unique_name

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import find [as 别名]
    def test_find_command_with_ambiguous_namespace_but_unique_name(self):
        """
        Application.find() returns a command with ambiguous namespace
        """
        application = Application()
        application.add(FooCommand())
        application.add(FoobarCommand())

        self.assertTrue(isinstance(application.find("f:f"), FoobarCommand))
开发者ID:onema,项目名称:cleo,代码行数:11,代码来源:test_application.py

示例6: find_alternative_commands_with_an_alias

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

示例7: test_find_alternative_exception_message_multiple

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import find [as 别名]
    def test_find_alternative_exception_message_multiple(self):
        """
        Application.find() raises an exception when alternatives have been found
        """
        application = Application()
        application.add(FooCommand())
        application.add(Foo1Command())
        application.add(Foo2Command())

        try:
            application.find("foo:baR")
            self.fail(".find() raises an Exception if command does not exist, with alternatives")
        except Exception as e:
            self.assertRegexpMatches(str(e), "Did you mean one of these")
            self.assertRegexpMatches(str(e), "foo1:bar")
            self.assertRegexpMatches(str(e), "foo:bar")

        try:
            application.find("foo2:baR")
            self.fail(".find() raises an Exception if command does not exist, with alternatives")
        except Exception as e:
            self.assertRegexpMatches(str(e), "Did you mean one of these")
            self.assertRegexpMatches(str(e), "foo1")

        application.add(Foo3Command())
        application.add(Foo4Command())

        try:
            application.find("foo3:")
            self.fail(".find() raises an Exception if command does not exist, with alternatives")
        except Exception as e:
            self.assertRegexpMatches(str(e), "foo3:bar")
            self.assertRegexpMatches(str(e), "foo3:bar:toh")
开发者ID:onema,项目名称:cleo,代码行数:35,代码来源:test_application.py

示例8: test_find_alternative_commands

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import find [as 别名]
    def test_find_alternative_commands(self):
        application = Application()
        application.add(FooCommand())
        application.add(Foo1Command())
        application.add(Foo2Command())

        command_name = "Unknown command"
        try:
            application.find(command_name)
            self.fail(".find() raises an Exception if command does not exist")
        except Exception as e:
            self.assertEqual('Command "%s" is not defined.' % command_name, str(e))

        command_name = "bar1"
        try:
            application.find(command_name)
            self.fail(".find() raises an Exception if command does not exist")
        except Exception as e:
            self.assertRegexpMatches(str(e), 'Command "%s" is not defined.' % command_name)
            self.assertRegexpMatches(str(e), "afoobar1")
            self.assertRegexpMatches(str(e), "foo:bar1")
            self.assertNotRegex(str(e), "foo:bar$")
开发者ID:onema,项目名称:cleo,代码行数:24,代码来源:test_application.py


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