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


Python Parse.catches_help方法代码示例

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


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

示例1: Test_catches_help

# 需要导入模块: from tambo import Parse [as 别名]
# 或者: from tambo.Parse import catches_help [as 别名]
class Test_catches_help(object):

    def setup(self):
        self.parser = Parse(['--foo'])
        self.parser.writer = StringIO()

    def test_does_not_catch_help_if_catch_help_is_not_defined(self):
        self.parser.arguments = ['--help', '-h', 'help']
        assert self.parser.catches_help(force=False) is None

    def test_does_not_catch_version_if_version_is_not_defined(self):
        self.parser.arguments = ['--version', 'version']
        assert self.parser.catches_version(force=False) is None

    def test_catches_only_help_if_it_sees_it_as_an_argument(self):
        self.parser.arguments = ['foo', 'bar']
        self.parser.catch_help = 'this is the help menu'
        assert self.parser.catches_help() == False

    def test_force_catch_version_does_nothing_if_not_defined(self):
        self.parser.arguments = ['foo', 'bar']
        assert self.parser.catches_version() == None

    def test_force_catch_help_does_nothing_if_not_defined(self):
        self.parser.arguments = ['foo', 'bar']
        assert self.parser.catches_help() == None

    def test_catches_a_single_dash_h(self):
        self.parser.arguments = ['-h']
        assert self.parser.check_help is True
        self.parser.catch_help = 'this is the help menu'

        with raises(SystemExit):
            self.parser.catches_help()
        assert self.parser.writer.getvalue() == 'this is the help menu\n'

    def test_catches_double_dash_h(self):
        self.parser.arguments = ['--h']
        self.parser.catch_help = 'this is the help menu'

        with raises(SystemExit):
            self.parser.catches_help()
        assert self.parser.writer.getvalue() == 'this is the help menu\n'

    def test_catches_double_dash_help(self):
        self.parser.arguments = ['--help']
        self.parser.catch_help = 'this is the help menu'

        with raises(SystemExit):
            self.parser.catches_help()
        assert self.parser.writer.getvalue() == 'this is the help menu\n'
开发者ID:ktdreyer,项目名称:tambo,代码行数:53,代码来源:test_parser.py


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