本文整理匯總了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"'
)
示例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",
)
示例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",
)
示例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))
示例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))
示例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)
示例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")
示例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$")