本文整理汇总了Python中cleo.application.Application.set_catch_exceptions方法的典型用法代码示例。如果您正苦于以下问题:Python Application.set_catch_exceptions方法的具体用法?Python Application.set_catch_exceptions怎么用?Python Application.set_catch_exceptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cleo.application.Application
的用法示例。
在下文中一共展示了Application.set_catch_exceptions方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_default_helper_set_returns_default_values
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_catch_exceptions [as 别名]
def test_get_default_helper_set_returns_default_values(self):
application = Application()
application.set_auto_exit(False)
application.set_catch_exceptions(False)
helper_set = application.get_helper_set()
self.assertTrue(helper_set.has("formatter"))
self.assertTrue(helper_set.has("dialog"))
self.assertTrue(helper_set.has("progress"))
示例2: test_adding_single_helper_set_overwrites_default_values
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_catch_exceptions [as 别名]
def test_adding_single_helper_set_overwrites_default_values(self):
application = Application()
application.set_auto_exit(False)
application.set_catch_exceptions(False)
application.set_helper_set(HelperSet({"formatter": FormatterHelper()}))
helper_set = application.get_helper_set()
self.assertTrue(helper_set.has("formatter"))
self.assertFalse(helper_set.has("dialog"))
self.assertFalse(helper_set.has("progress"))
示例3: test_silent_help
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_catch_exceptions [as 别名]
def test_silent_help(self):
"""
Silent help should return nothing
"""
application = Application()
application.set_auto_exit(False)
application.set_catch_exceptions(False)
tester = ApplicationTester(application)
tester.run([("-h", True), ("-q", True)], {"decorated": False})
self.assertEqual("", tester.get_display())
示例4: test_get_default_input_definition_returns_default_values
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_catch_exceptions [as 别名]
def test_get_default_input_definition_returns_default_values(self):
application = Application()
application.set_auto_exit(False)
application.set_catch_exceptions(False)
definition = application.get_definition()
self.assertTrue(definition.has_argument("command"))
self.assertTrue(definition.has_option("help"))
self.assertTrue(definition.has_option("quiet"))
self.assertTrue(definition.has_option("verbose"))
self.assertTrue(definition.has_option("version"))
self.assertTrue(definition.has_option("ansi"))
self.assertTrue(definition.has_option("no-ansi"))
self.assertTrue(definition.has_option("no-interaction"))
示例5: test_set_catch_exceptions
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_catch_exceptions [as 别名]
def test_set_catch_exceptions(self):
application = Application()
application.set_auto_exit(False)
application.get_terminal_width = self.mock().MagicMock(return_value=120)
tester = ApplicationTester(application)
application.set_catch_exceptions(True)
tester.run([("command", "foo")], {"decorated": False})
self.assertEqual(self.open_fixture("application_renderexception1.txt"), tester.get_display())
application.set_catch_exceptions(False)
try:
tester.run([("command", "foo")], {"decorated": False})
self.fail(".set_catch_exceptions() sets the catch exception flag")
except Exception as e:
self.assertEqual('Command "foo" is not defined.', str(e))
示例6: test_adding_already_set_definition_element_data
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_catch_exceptions [as 别名]
def test_adding_already_set_definition_element_data(self):
data = [
[InputArgument("command", InputArgument.REQUIRED)],
[InputOption("quiet", "", InputOption.VALUE_NONE)],
[InputOption("query", "q", InputOption.VALUE_NONE)],
]
for d in data:
application = Application()
application.set_auto_exit(False)
application.set_catch_exceptions(False)
application.register("foo").set_definition(d).set_code(lambda in_, out_: None)
input_ = ListInput([("command", "foo")])
output_ = NullOutput()
self.assertRaises(Exception, application.run, input_, output_)
示例7: test_setting_input_definition_overwrites_default_values
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_catch_exceptions [as 别名]
def test_setting_input_definition_overwrites_default_values(self):
application = Application()
application.set_auto_exit(False)
application.set_catch_exceptions(False)
application.set_definition(
InputDefinition([InputOption("--custom", "-c", InputOption.VALUE_NONE, "Set the custom input definition.")])
)
definition = application.get_definition()
self.assertFalse(definition.has_argument("command"))
self.assertFalse(definition.has_option("help"))
self.assertFalse(definition.has_option("quiet"))
self.assertFalse(definition.has_option("verbose"))
self.assertFalse(definition.has_option("version"))
self.assertFalse(definition.has_option("ansi"))
self.assertFalse(definition.has_option("no-ansi"))
self.assertFalse(definition.has_option("no-interaction"))
self.assertTrue(definition.has_option("custom"))
示例8: test_run
# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_catch_exceptions [as 别名]
def test_run(self):
application = Application()
application.set_auto_exit(False)
application.set_catch_exceptions(False)
command = Foo1Command()
application.add(command)
sys.argv = ["cli.py", "foo:bar1"]
application.run()
self.assertEqual("ArgvInput", command.input.__class__.__name__)
self.assertEqual("ConsoleOutput", command.output.__class__.__name__)
application = Application()
application.set_auto_exit(False)
application.set_catch_exceptions(False)
self.ensure_static_command_help(application)
tester = ApplicationTester(application)
tester.run([], {"decorated": False})
self.assertEqual(self.open_fixture("application_run1.txt"), tester.get_display())
tester.run([("--help", True)], {"decorated": False})
self.assertEqual(self.open_fixture("application_run2.txt"), tester.get_display())
tester.run([("-h", True)], {"decorated": False})
self.assertEqual(self.open_fixture("application_run2.txt"), tester.get_display())
tester.run([("command", "list"), ("--help", True)], {"decorated": False})
self.assertEqual(self.open_fixture("application_run3.txt"), tester.get_display())
tester.run([("command", "list"), ("-h", True)], {"decorated": False})
self.assertEqual(self.open_fixture("application_run3.txt"), tester.get_display())
tester.run([("--ansi", True)])
self.assertTrue(tester.get_output().is_decorated())
tester.run([("--no-ansi", True)])
self.assertFalse(tester.get_output().is_decorated())
tester.run([("--version", True)], {"decorated": False})
self.assertEqual(self.open_fixture("application_run4.txt"), tester.get_display())
tester.run([("-V", True)], {"decorated": False})
self.assertEqual(self.open_fixture("application_run4.txt"), tester.get_display())
tester.run([("command", "list"), ("--quiet", True)])
self.assertEqual("", tester.get_display())
tester.run([("command", "list"), ("-q", True)])
self.assertEqual("", tester.get_display())
tester.run([("command", "list"), ("--verbose", True)])
self.assertEqual(Output.VERBOSITY_VERBOSE, tester.get_output().get_verbosity())
tester.run([("command", "list"), ("-v", True)])
self.assertEqual(Output.VERBOSITY_VERBOSE, tester.get_output().get_verbosity())
application = Application()
application.set_auto_exit(False)
application.set_catch_exceptions(False)
application.add(FooCommand())
tester = ApplicationTester(application)
tester.run([("command", "foo:bar"), ("--no-interaction", True)], {"decorated": False})
self.assertEqual("called\n", tester.get_display())
tester.run([("command", "foo:bar"), ("-n", True)], {"decorated": False})
self.assertEqual("called\n", tester.get_display())