当前位置: 首页>>代码示例>>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;未经允许,请勿转载。