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


Python strutils.BasicStringComparator方法代碼示例

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


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

示例1: test_basic_string_comparator_fails_different_comparators

# 需要導入模塊: from charmhelpers.core import strutils [as 別名]
# 或者: from charmhelpers.core.strutils import BasicStringComparator [as 別名]
def test_basic_string_comparator_fails_different_comparators(self):

        class MyComparator1(strutils.BasicStringComparator):

            _list = ('the truth is out there'.split(' '))

        class MyComparator2(strutils.BasicStringComparator):

            _list = ('no one in space can hear you scream'.split(' '))

        x = MyComparator1('is')
        y = MyComparator2('you')
        try:
            x > y
            raise Exception("Comparing different comparators should fail")
        except Exception as e:
            self.assertTrue(isinstance(e, AssertionError)) 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:19,代碼來源:test_strutils.py

示例2: test_basic_string_comparator_class_fails_instantiation

# 需要導入模塊: from charmhelpers.core import strutils [as 別名]
# 或者: from charmhelpers.core.strutils import BasicStringComparator [as 別名]
def test_basic_string_comparator_class_fails_instantiation(self):
        try:
            strutils.BasicStringComparator('hello')
            raise Exception("instantiating BasicStringComparator should fail")
        except Exception as e:
            assert (str(e) == "Must define the _list in the class definition!") 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:8,代碼來源:test_strutils.py

示例3: test_basic_string_comparator_class

# 需要導入模塊: from charmhelpers.core import strutils [as 別名]
# 或者: from charmhelpers.core.strutils import BasicStringComparator [as 別名]
def test_basic_string_comparator_class(self):

        class MyComparator(strutils.BasicStringComparator):

            _list = ('zomg', 'bartlet', 'over', 'and')

        x = MyComparator('zomg')
        self.assertEquals(x.index, 0)
        y = MyComparator('over')
        self.assertEquals(y.index, 2)
        self.assertTrue(x == 'zomg')
        self.assertTrue(x != 'bartlet')
        self.assertTrue(x == x)
        self.assertTrue(x != y)
        self.assertTrue(x < y)
        self.assertTrue(y > x)
        self.assertTrue(x < 'bartlet')
        self.assertTrue(y > 'bartlet')
        self.assertTrue(x >= 'zomg')
        self.assertTrue(x <= 'zomg')
        self.assertTrue(x >= x)
        self.assertTrue(x <= x)
        self.assertTrue(y >= 'zomg')
        self.assertTrue(y <= 'over')
        self.assertTrue(y >= x)
        self.assertTrue(x <= y)
        # ensure that something not in the list dies
        try:
            MyComparator('nope')
            raise Exception("MyComparator('nope') should have failed")
        except Exception as e:
            self.assertTrue(isinstance(e, KeyError)) 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:34,代碼來源:test_strutils.py


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