本文整理汇总了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())
示例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())
示例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())
示例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())
示例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())
示例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")
示例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")
示例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))
示例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\]'
)
示例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")
示例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.')
示例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())
示例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)
示例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")
示例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)