当前位置: 首页>>代码示例>>Python>>正文


Python core.safe_repr函数代码示例

本文整理汇总了Python中sure.core.safe_repr函数的典型用法代码示例。如果您正苦于以下问题:Python safe_repr函数的具体用法?Python safe_repr怎么用?Python safe_repr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了safe_repr函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: callable

    def callable(self):
        if self.negative:
            assert not callable(self.obj), (
                'expected `{0}` to not be callable but it is'.format(safe_repr(self.obj)))
        else:
            assert callable(self.obj), (
                'expected {0} to be callable'.format(safe_repr(self.obj)))

        return True
开发者ID:spulec,项目名称:sure,代码行数:9,代码来源:__init__.py

示例2: test_unicode

def test_unicode():
    "dicts with unicode should work properly"
    class Y(object):
        def __init__(self, x):
            self.x = x

        def __repr__(self):
            if PY3:
                # PY3K should return the regular (unicode) string
                return self.x
            else:
                return self.x.encode('utf-8')

        def __eq__(self, other):
            return self.x == other.x

    y1 = {
        'a': 2,
        'b': Y('Gabriel Falcão'),
        'c': 'Foo',
    }
    name = 'Gabriel Falcão' if PY3 else 'Gabriel Falc\xe3o'

    expect(safe_repr(y1)).should.equal(compat_repr(
        "{'a': 2, 'b': %s, 'c': 'Foo'}" % name
    ))
开发者ID:abg,项目名称:sure,代码行数:26,代码来源:test_safe_repr.py

示例3: __getattr__

 def __getattr__(self, attr):
     try:
         return super(VariablesBag, self).__getattribute__(attr)
     except AttributeError:
         if attr not in dir(VariablesBag):
             raise AssertionError(not_here_error % (
                 attr,
                 safe_repr(self.__varnames__),
             ))
开发者ID:adamchainz,项目名称:sure,代码行数:9,代码来源:__init__.py

示例4: empty

    def empty(self):
        representation = safe_repr(self.obj)
        length = len(self.obj)
        if self.negative:
            assert length > 0, "expected `{0}` to not be empty".format(representation)
        else:
            assert length == 0, "expected `{0}` to be empty but it has {1} items".format(representation, length)

        return True
开发者ID:CyrilRoelandteNovance,项目名称:sure,代码行数:9,代码来源:__init__.py

示例5: wrapper

    def wrapper(self, *args, **kw):
        value = func(self, *args, **kw)
        msg = "{0}({1}) failed".format(
            func.__name__,
            ", ".join(map(safe_repr, args)),
            ", ".join(["{0}={1}".format(k, safe_repr(kw[k])) for k in kw]),
        )

        assert value, unicode(msg)
        return value
开发者ID:spulec,项目名称:sure,代码行数:10,代码来源:__init__.py

示例6: equal

    def equal(self, what, epsilon=None):
        try:
            comparison = DeepComparison(self.obj, what, epsilon).compare()
            error = False
        except AssertionError as e:
            error = e
            comparison = None

        if isinstance(comparison, DeepExplanation):
            error = comparison.get_assertion(self.obj, what)

        if self.negative:
            if error:
                return True

            msg = '%s should differ from %s, but is the same thing'
            raise AssertionError(msg % (safe_repr(self.obj), safe_repr(what)))

        else:
            if not error:
                return True
            raise error
开发者ID:adamchainz,项目名称:sure,代码行数:22,代码来源:__init__.py

示例7: wrapper

    def wrapper(self, *args, **kw):
        try:
            value = func(self, *args, **kw)
        except AssertionError as e:
            raise AssertionError(e)

        msg = "{0}({1}) failed".format(
            func.__name__,
            ", ".join(map(safe_repr, args)),
            ", ".join(["{0}={1}".format(k, safe_repr(kw[k])) for k in kw]),
        )
        if PY2:
            msg = text_type(msg)

        assert value, msg
        return value
开发者ID:gabrielfalcao,项目名称:sure,代码行数:16,代码来源:__init__.py

示例8: test_nested_dict

def test_nested_dict():
    "dicts nested inside values should also get sorted"
    X = {'my::all_users': [{'age': 33, 'name': 'John', 'foo': 'bar'}]}
    expect(safe_repr(X)).should.equal(compat_repr(
        '''{'my::all_users': [{'age': 33, 'foo': 'bar', 'name': 'John'}]}'''
    ))
开发者ID:abg,项目名称:sure,代码行数:6,代码来源:test_safe_repr.py

示例9: test_basic_dict

def test_basic_dict():
    "safe_repr should return a sorted repr"
    X = {'b': 'd', 'a': 'c'}
    expect(safe_repr(X)).should.equal(compat_repr(
        "{'a': 'c', 'b': 'd'}"
    ))
开发者ID:abg,项目名称:sure,代码行数:6,代码来源:test_safe_repr.py

示例10: test_basic_list

def test_basic_list():
    "safe_repr should display a simple list"
    X = ['one', 'yeah']
    expect(safe_repr(X)).should.equal(compat_repr(
        "['one', 'yeah']"
    ))
开发者ID:abg,项目名称:sure,代码行数:6,代码来源:test_safe_repr.py


注:本文中的sure.core.safe_repr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。