本文整理汇总了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))