當前位置: 首頁>>代碼示例>>Python>>正文


Python Application.set_catch_exceptions方法代碼示例

本文整理匯總了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"))
開發者ID:onema,項目名稱:cleo,代碼行數:12,代碼來源:test_application.py

示例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"))
開發者ID:onema,項目名稱:cleo,代碼行數:14,代碼來源:test_application.py

示例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())
開發者ID:onema,項目名稱:cleo,代碼行數:14,代碼來源:test_application.py

示例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"))
開發者ID:onema,項目名稱:cleo,代碼行數:18,代碼來源:test_application.py

示例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))
開發者ID:onema,項目名稱:cleo,代碼行數:18,代碼來源:test_application.py

示例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_)
開發者ID:onema,項目名稱:cleo,代碼行數:19,代碼來源:test_application.py

示例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"))
開發者ID:onema,項目名稱:cleo,代碼行數:24,代碼來源:test_application.py

示例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())
開發者ID:onema,項目名稱:cleo,代碼行數:73,代碼來源:test_application.py


注:本文中的cleo.application.Application.set_catch_exceptions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。