本文整理匯總了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))
示例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!")
示例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))