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


Python Application.set_auto_exit方法代码示例

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


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

示例1: test_render_exception

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

示例2: TestApplicationTester

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

示例3: test_get_default_helper_set_returns_default_values

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_auto_exit [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

示例4: test_run_return_exit_code_one_for_exception_code_zero

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_auto_exit [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

示例5: test_adding_single_helper_set_overwrites_default_values

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_auto_exit [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

示例6: test_silent_help

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_auto_exit [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

示例7: test_get_default_input_definition_returns_default_values

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_auto_exit [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

示例8: test_set_catch_exceptions

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_auto_exit [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

示例9: test_adding_already_set_definition_element_data

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_auto_exit [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

示例10: test_set_run_custom_default_command

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_auto_exit [as 别名]
    def test_set_run_custom_default_command(self):
        """
        Application calls the default command.
        """
        application = Application()
        application.set_auto_exit(False)
        command = FooCommand()
        application.add(command)
        application.set_default_command(command.get_name())

        tester = ApplicationTester(application)
        tester.run([])
        self.assertEqual("interact called\ncalled\n", tester.get_display())

        application = CustomDefaultCommandApplication()
        application.set_auto_exit(False)

        tester = ApplicationTester(application)
        tester.run([])
        self.assertEqual("interact called\ncalled\n", tester.get_display())
开发者ID:onema,项目名称:cleo,代码行数:22,代码来源:test_application.py

示例11: test_setting_input_definition_overwrites_default_values

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_auto_exit [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

示例12: test_run

# 需要导入模块: from cleo.application import Application [as 别名]
# 或者: from cleo.application.Application import set_auto_exit [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_auto_exit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。