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

Python six.compat_repr函数代码示例

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

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



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

示例1: test_have_property_with_value

def test_have_property_with_value():
    (u"this(instance).should.have.property(property_name).being or "
     ".with_value should allow chain up")

    class Person(object):
        name = "John Doe"

        def __repr__(self):
            return r"Person()"

    jay = Person()

    assert this(jay).should.have.property("name").being.equal("John Doe")
    assert this(jay).should.have.property("name").not_being.equal("Foo")

    def opposite():
        assert this(jay).should.have.property("name").not_being.equal(
            "John Doe")

    def opposite_not():
        assert this(jay).should.have.property("name").being.equal(
            "Foo")

    expect(opposite).when.called.to.throw(AssertionError)
    expect(opposite).when.called.to.throw(compat_repr(
        "'John Doe' should differ to 'John Doe', but is the same thing"))

    expect(opposite_not).when.called.to.throw(AssertionError)
    expect(opposite_not).when.called.to.throw(compat_repr(
        "X is 'John Doe' whereas Y is 'Foo'"))
开发者ID:amukiza,项目名称:sure,代码行数:30,代码来源:test_assertion_builder.py


示例2: test_equal_with_repr_of_complex_types_and_repr

def test_equal_with_repr_of_complex_types_and_repr():
    (u"test usage of repr() inside expect(complex1).to.equal(complex2)")

    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(u'Gabriel Falcão'),
        'c': 'Foo',
    }

    expect(y1).to.equal({
        'a': 2,
        'b': Y(u'Gabriel Falcão'),
        'c': 'Foo',
    })

    expect(y1).to_not.equal({
        'a': 2,
        'b': Y(u'Gabriel Falçao'),
        'c': 'Foo',
    })

    def opposite():
        expect(y1).to.equal({
            'a': 2,
            'b': Y(u'Gabriel Falçao'),
            'c': 'Foo',
        })

    def opposite_not():
        expect(y1).to_not.equal({
            'a': 2,
            'b': Y(u'Gabriel Falcão'),
            'c': 'Foo',
        })

    expect(opposite).when.called.to.throw(AssertionError)
    expect(opposite).when.called.to.throw(compat_repr("X['b'] != Y['b']"))

    expect(opposite_not).when.called.to.throw(AssertionError)
    expect(opposite_not).when.called.to.throw(compat_repr(
        u"{'a': 2, 'b': Gabriel Falcão, 'c': 'Foo'} should differ to {'a': 2, 'b': Gabriel Falcão, 'c': 'Foo'}, but is the same thing"))
开发者ID:amukiza,项目名称:sure,代码行数:55,代码来源:test_assertion_builder.py


示例3: test_have_property

def test_have_property():
    (u"this(instance).should.have.property(property_name)")

    class Person(object):
        name = "John Doe"

        def __repr__(self):
            return r"Person()"

    jay = Person()

    assert this(jay).should.have.property("name")
    assert this(jay).should_not.have.property("age")

    def opposite():
        assert this(jay).should_not.have.property("name")

    def opposite_not():
        assert this(jay).should.have.property("age")

    expect(opposite).when.called.to.throw(AssertionError)
    expect(opposite).when.called.to.throw(compat_repr(
        "Person() should not have the property `name`, but it is 'John Doe'"))

    expect(opposite_not).when.called.to.throw(AssertionError)
    expect(opposite_not).when.called.to.throw(
        "Person() should have the property `age` but does not")
开发者ID:amukiza,项目名称:sure,代码行数:27,代码来源:test_assertion_builder.py


示例4: test_deep_equals_dict_level2_fail

def test_deep_equals_dict_level2_fail():
    "that() deep_equals(dict) failing on level 2"

    something = {
        'one': 'yeah',
        'another': {
            'two': '##',
        },
    }

    def assertions():
        assert that(something).deep_equals({
            'one': 'yeah',
            'another': {
                'two': '$$',
            },
        })
    assert that(assertions).raises(
        AssertionError, compat_repr(
        "given\n" \
        "X = {'another': {'two': '##'}, 'one': 'yeah'}\n" \
        "    and\n" \
        "Y = {'another': {'two': '$$'}, 'one': 'yeah'}\n" \
        "X['another']['two'] is '##' whereas Y['another']['two'] is '$$'",
    ))
开发者ID:CyrilRoelandteNovance,项目名称:sure,代码行数:25,代码来源:test_old_api.py


示例5: 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(u'Gabriel Falcão'),
        'c': u'Foo',
    }
    name = u'Gabriel Falcão' if PY3 else u'Gabriel Falc\xe3o'

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


示例6: test_look_like

def test_look_like():
    (u"this('   aa  \n  ').should.look_like('aa')")

    assert this('   \n  aa \n  ').should.look_like('AA')
    assert this('   \n  bb \n  ').should_not.look_like('aa')

    def opposite():
        assert this('\n aa \n').should.look_like('bb')

    def opposite_not():
        assert this('\n aa \n').should_not.look_like('aa')

    expect(opposite).when.called.to.throw(AssertionError)
    expect(opposite).when.called.to.throw(compat_repr(r"'\n aa \n' does not look like 'bb'"))

    expect(opposite_not).when.called.to.throw(AssertionError)
    expect(opposite_not).when.called.to.throw(compat_repr(r"'\n aa \n' should not look like 'aa' but does"))
开发者ID:amukiza,项目名称:sure,代码行数:17,代码来源:test_assertion_builder.py


示例7: test_that_equals_fails

def test_that_equals_fails():
    "that() equals(string) when it's supposed to fail"

    something = "else"

    def fail():
        assert that("something").equals(something)

    assert that(fail).raises(
        AssertionError,
        compat_repr("given\n" "X = 'something'\n" "    and\n" "Y = 'else'\n" "X is 'something' whereas Y is 'else'"),
    )
开发者ID:vmalloc,项目名称:sure,代码行数:12,代码来源:test_old_api.py


示例8: test_have_key

def test_have_key():
    (u"this(dictionary).should.have.key(key_name)")

    jay = {'name': "John Doe"}

    assert this(jay).should.have.key("name")
    assert this(jay).should_not.have.key("age")

    def opposite():
        assert this(jay).should_not.have.key("name")

    def opposite_not():
        assert this(jay).should.have.key("age")

    expect(opposite).when.called.to.throw(AssertionError)
    expect(opposite).when.called.to.throw(compat_repr(
        "{'name': 'John Doe'} should not have the key `name`, "
        "but it is 'John Doe'"))

    expect(opposite_not).when.called.to.throw(AssertionError)
    expect(opposite_not).when.called.to.throw(compat_repr(
        "{'name': 'John Doe'} should have the key `age` but does not"))
开发者ID:amukiza,项目名称:sure,代码行数:22,代码来源:test_assertion_builder.py


示例9: test_deep_equals_failing_complex_vs_basic

def test_deep_equals_failing_complex_vs_basic():
    "that(X) deep_equals(Y) fails with complex vc basic type"

    def assertions():
        assert that({'two': 'yeah'}).deep_equals('two yeah')

    assert that(assertions).raises(
        AssertionError, compat_repr(
        "given\n" \
        "X = {'two': 'yeah'}\n" \
        "    and\n" \
        "Y = 'two yeah'\n"
        "X is a dict and Y is a %s instead" % text_type_name,
    ))
开发者ID:CyrilRoelandteNovance,项目名称:sure,代码行数:14,代码来源:test_old_api.py


示例10: test_have_key_with_value

def test_have_key_with_value():
    (u"this(dictionary).should.have.key(key_name).being or "
     ".with_value should allow chain up")

    jay = dict(name="John Doe")

    assert this(jay).should.have.key("name").being.equal("John Doe")
    assert this(jay).should.have.key("name").not_being.equal("Foo")

    def opposite():
        assert this(jay).should.have.key("name").not_being.equal(
            "John Doe")

    def opposite_not():
        assert this(jay).should.have.key("name").being.equal(
            "Foo")

    expect(opposite).when.called.to.throw(AssertionError)
    expect(opposite).when.called.to.throw(compat_repr(
        "'John Doe' should differ to 'John Doe', but is the same thing"))

    expect(opposite_not).when.called.to.throw(AssertionError)
    expect(opposite_not).when.called.to.throw(compat_repr(
        "X is 'John Doe' whereas Y is 'Foo'"))
开发者ID:amukiza,项目名称:sure,代码行数:24,代码来源:test_assertion_builder.py


示例11: test_deep_equals_list_level2_fail_by_length_y_gt_x

def test_deep_equals_list_level2_fail_by_length_y_gt_x():
    "that(list) deep_equals(list) failing by length (len(Y) > len(X))"

    something = [u'one', u'yeah']

    def assertions():
        assert that(something).deep_equals(['one', 'yeah', 'damn'])

    assert that(assertions).raises(
        AssertionError, compat_repr(
        "given\n" \
        "X = ['one', 'yeah']\n" \
        "    and\n" \
        "Y = ['one', 'yeah', 'damn']\n" \
        "Y has 3 items whereas X has only 2",
    ))
开发者ID:CyrilRoelandteNovance,项目名称:sure,代码行数:16,代码来源:test_old_api.py


示例12: test_deep_equals_list_level2_fail_by_length_x_gt_y

def test_deep_equals_list_level2_fail_by_length_x_gt_y():
    "that(list) deep_equals(list) failing by length (len(X) > len(Y))"

    something = {'iterable': ['one', 'yeah', 'awesome!']}

    def assertions():
        assert that(something).deep_equals({'iterable': ['one', 'yeah']})

    assert that(assertions).raises(
        AssertionError, compat_repr(
        "given\n" \
        "X = {'iterable': ['one', 'yeah', 'awesome!']}\n" \
        "    and\n" \
        "Y = {'iterable': ['one', 'yeah']}\n" \
        "X has 3 items whereas Y has only 2",
    ))
开发者ID:CyrilRoelandteNovance,项目名称:sure,代码行数:16,代码来源:test_old_api.py


示例13: test_deep_equals_tuple_level1_fail_by_length_y_gt_x

def test_deep_equals_tuple_level1_fail_by_length_y_gt_x():
    "that(tuple) deep_equals(tuple) failing by length (len(Y) > len(X))"

    something = ('one', 'yeah')

    def assertions():
        assert that(something).deep_equals(('one', 'yeah', 'damn'))

    assert that(assertions).raises(
        AssertionError, compat_repr(
        "given\n" \
        "X = ('one', 'yeah')\n" \
        "    and\n" \
        "Y = ('one', 'yeah', 'damn')\n" \
        "Y has 3 items whereas X has only 2",
    ))
开发者ID:CyrilRoelandteNovance,项目名称:sure,代码行数:16,代码来源:test_old_api.py


示例14: test_deep_equals_tuple_level1_fail_by_value

def test_deep_equals_tuple_level1_fail_by_value():
    "that(tuple) deep_equals(tuple) failing on level 1"

    something = ('one', 'yeahs')

    def assertions():
        assert that(something).deep_equals(('one', 'yeah'))

    assert that(assertions).raises(
        AssertionError, compat_repr(
        "given\n" \
        "X = ('one', 'yeahs')\n" \
        "    and\n" \
        "Y = ('one', 'yeah')\n" \
        "X[1] is 'yeahs' whereas Y[1] is 'yeah'",
    ))
开发者ID:CyrilRoelandteNovance,项目名称:sure,代码行数:16,代码来源:test_old_api.py


示例15: test_deep_equals_failing_basic_vs_complex

def test_deep_equals_failing_basic_vs_complex():
    "that(X) deep_equals(Y) fails with basic vc complex type"

    def assertions():
        assert that("two yeah").deep_equals({"two": "yeah"})

    assert that(assertions).raises(
        AssertionError,
        compat_repr(
            "given\n"
            "X = 'two yeah'\n"
            "    and\n"
            "Y = {'two': 'yeah'}\n"
            "X is a %s and Y is a dict instead" % text_type_name
        ),
    )
开发者ID:vmalloc,项目名称:sure,代码行数:16,代码来源:test_old_api.py


示例16: test_deep_equals_list_level1_fail_by_value

def test_deep_equals_list_level1_fail_by_value():
    "that(list) deep_equals(list) failing on level 1"

    something = ['one', 'yeahs']

    def assertions():
        assert that(something).deep_equals(['one', 'yeah'])

    assert that(assertions).raises(
        AssertionError, compat_repr(
        "given\n" \
        "X = ['one', 'yeahs']\n" \
        "    and\n" \
        "Y = ['one', 'yeah']\n" \
        "X[1] is 'yeahs' whereas Y[1] is 'yeah'",
    ))
开发者ID:CyrilRoelandteNovance,项目名称:sure,代码行数:16,代码来源:test_old_api.py


示例17: test_deep_equals_tuple_level1_fail_by_length_x_gt_y

def test_deep_equals_tuple_level1_fail_by_length_x_gt_y():
    "that(tuple) deep_equals(tuple) failing by length (len(X) > len(Y))"

    something = ("one", "yeah", "awesome!")

    def assertions():
        assert that(something).deep_equals(("one", "yeah"))

    assert that(assertions).raises(
        AssertionError,
        compat_repr(
            "given\n"
            "X = ('one', 'yeah', 'awesome!')\n"
            "    and\n"
            "Y = ('one', 'yeah')\n"
            "X has 3 items whereas Y has only 2"
        ),
    )
开发者ID:vmalloc,项目名称:sure,代码行数:18,代码来源:test_old_api.py


示例18: test_deep_equals_dict_level1_fail

def test_deep_equals_dict_level1_fail():
    "that() deep_equals(dict) failing on level 1"

    something = {"one": "yeah"}

    def assertions():
        assert that(something).deep_equals({"one": "oops"})

    assert that(assertions).raises(
        AssertionError,
        compat_repr(
            "given\n"
            "X = {'one': 'yeah'}\n"
            "    and\n"
            "Y = {'one': 'oops'}\n"
            "X['one'] is 'yeah' whereas Y['one'] is 'oops'"
        ),
    )
开发者ID:vmalloc,项目名称:sure,代码行数:18,代码来源:test_old_api.py


示例19: test_deep_equals_list_level1_fail_by_length_x_gt_y

def test_deep_equals_list_level1_fail_by_length_x_gt_y():
    "that(list) deep_equals(list) failing by length (len(X) > len(Y))"

    something = ["one", "yeah", "awesome!"]

    def assertions():
        assert that(something).deep_equals(["one", "yeah"])

    assert that(assertions).raises(
        AssertionError,
        compat_repr(
            "given\n"
            "X = ['one', 'yeah', 'awesome!']\n"
            "    and\n"
            "Y = ['one', 'yeah']\n"
            "X has 3 items whereas Y has only 2"
        ),
    )
开发者ID:vmalloc,项目名称:sure,代码行数:18,代码来源:test_old_api.py


示例20: test_deep_equals_dict_level1_fails_missing_key_on_y

def test_deep_equals_dict_level1_fails_missing_key_on_y():
    "that(X) deep_equals(Y) fails when Y is missing a key that X has"

    something = {"one": "yeah"}

    def assertions():
        assert that(something).deep_equals({"two": "yeah"})

    assert that(assertions).raises(
        AssertionError,
        compat_repr(
            "given\n"
            "X = {'one': 'yeah'}\n"
            "    and\n"
            "Y = {'two': 'yeah'}\n"
            "X has the key 'one' whereas Y does not"
        ),
    )
开发者ID:vmalloc,项目名称:sure,代码行数:18,代码来源:test_old_api.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python query.select函数代码示例发布时间:2022-05-27
下一篇:
Python old.AssertionHelper类代码示例发布时间: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