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


Python Application.run方法代码示例

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


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

示例1: test_run_return_exit_code_one_for_exception_code_zero

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import run [as 别名]
    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)
开发者ID:onema,项目名称:cleo,代码行数:12,代码来源:test_application.py

示例2: test_run

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import run [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())
开发者ID:onema,项目名称:cleo,代码行数:73,代码来源:test_application.py


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