本文整理汇总了Python中cleo.application.Application.add方法的典型用法代码示例。如果您正苦于以下问题:Python Application.add方法的具体用法?Python Application.add怎么用?Python Application.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cleo.application.Application
的用法示例。
在下文中一共展示了Application.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_render_exception
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import add [as 别名]
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())
示例2: test_find
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import add [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_with_missing_namespace
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import add [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))
示例4: test_find_command_with_ambiguous_namespace_but_unique_name
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import add [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))
示例5: test_find_unique_name_but_namespace_name
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import add [as 别名]
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")
示例6: find_alternative_commands_with_an_alias
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import add [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_single
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import add [as 别名]
def test_find_alternative_exception_message_single(self):
"""
Application.find() raises an exception when an alternative has been found
"""
data = ["foo3:baR", "foO3:bar"]
application = Application()
application.add(Foo3Command())
for d in data:
self.assertRaisesRegexp(Exception, "Did you mean this", application.find, d)
示例8: test_get_namespaces
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import add [as 别名]
def test_get_namespaces(self):
"""
Application.get_namespaces() should return registered namespaces
"""
application = Application()
application.add(FooCommand())
application.add(Foo1Command())
self.assertEqual(
["foo"], application.get_namespaces(), msg=".get_namespaces() returns an array of unique used namespaces"
)
示例9: test_as_text
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import add [as 别名]
def test_as_text(self):
"""
Application.as_text() returns a text representation of the application.
"""
application = Application()
application.add(FooCommand())
self.ensure_static_command_help(application)
self.assertEqual(self.open_fixture("application_astext1.txt"), application.as_text())
self.assertEqual(self.open_fixture("application_astext2.txt"), application.as_text("foo"))
示例10: test_all
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import add [as 别名]
def test_all(self):
"""
Application.get_all() returns all comands of the application
"""
application = Application()
commands = application.all()
self.assertEqual(
"HelpCommand", commands["help"].__class__.__name__, msg=".all() returns the registered commands"
)
application.add(FooCommand())
self.assertEqual(1, len(application.all("foo")), msg=".all() take a namespace as first argument")
示例11: test_find_command_equal_namesapce
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import add [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",
)
示例12: test_find_with_ambiguous_abbreviations
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import add [as 别名]
def test_find_with_ambiguous_abbreviations(self):
"""
Application.find() should raise an error when there is ambiguosity
"""
data = [
["f", 'Command "f" is not defined\.'],
["a", 'Command "a" is ambiguous \(afoobar, afoobar1 and 1 more\)\.'],
["foo:b", 'Command "foo:b" is ambiguous \(foo1:bar, foo:bar and 1 more\)\.'],
]
application = Application()
application.add(FooCommand())
application.add(Foo1Command())
application.add(Foo2Command())
for d in data:
self.assertRaisesRegexp(Exception, d[1], application.find, d[0])
示例13: test_add_with_dictionary
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import add [as 别名]
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())
示例14: test_add
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import add [as 别名]
def test_add(self):
"""
Application.add() and .addCommands() register commands
"""
application = Application()
foo = FooCommand()
application.add(foo)
self.assertEqual(foo, application.all()["foo:bar"], msg=".add() registers a command")
application = Application()
foo, foo1 = FooCommand(), Foo1Command()
application.add_commands([foo, foo1])
commands = application.all()
self.assertEqual(
[foo, foo1], [commands["foo:bar"], commands["foo:bar1"]], msg=".add_commands() registers a list of commands"
)
示例15: test_find_namespace
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import add [as 别名]
def test_find_namespace(self):
"""
Application.find_namespace() should return a namespace
"""
application = Application()
application.add(FooCommand())
self.assertEqual(
"foo", application.find_namespace("foo"), msg=".find_namespace() returns the given namespace if it exists"
)
self.assertEqual(
"foo", application.find_namespace("f"), msg=".find_namespace() finds a namespace given an abbreviation"
)
application.add(Foo2Command())
self.assertEqual(
"foo", application.find_namespace("foo"), msg=".find_namespace() returns the given namespace if it exists"
)