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


Python Parse.catches_version方法代碼示例

本文整理匯總了Python中tambo.Parse.catches_version方法的典型用法代碼示例。如果您正苦於以下問題:Python Parse.catches_version方法的具體用法?Python Parse.catches_version怎麽用?Python Parse.catches_version使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tambo.Parse的用法示例。


在下文中一共展示了Parse.catches_version方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Test_catches_help

# 需要導入模塊: from tambo import Parse [as 別名]
# 或者: from tambo.Parse import catches_version [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

示例2: Test_catches_version

# 需要導入模塊: from tambo import Parse [as 別名]
# 或者: from tambo.Parse import catches_version [as 別名]
class Test_catches_version(object):

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

    def test_catches_only_version_if_it_sees_it_as_an_argument(self):
        self.parser.arguments = ['foo', 'bar']
        self.parser.catch_version = "version 3"
        assert self.parser.catches_version() == False

    def test_catches_double_dash_version(self):
        self.parser.arguments = ['foo', '--version']
        self.parser.catch_version = "version 3"
        with raises(SystemExit):
            self.parser.catches_version()
        assert self.parser.writer.getvalue() == 'version 3\n'

    def test_catches_version_if_it_sees_it_as_an_argument(self):
        self.parser.arguments = ['foo', 'version']
        self.parser.catch_version = "version 3"
        with raises(SystemExit):
            self.parser.catches_version()
        assert self.parser.writer.getvalue() == 'version 3\n'
開發者ID:ktdreyer,項目名稱:tambo,代碼行數:26,代碼來源:test_parser.py


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