• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python core.safe_repr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python deprecated.that函数代码示例发布时间:2022-05-27
下一篇:
Python compat.compat_repr函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap