def test_roundtrip_backref():
    """References to the same object are preserved."""
    foo = 'foo'
    obj = [foo, foo]
    buf = pencode(obj)
    assert isinstance(buf, bytes)
    a, b = pdecode(buf)
    assert a is b
Beispiel #2
0
def test_roundtrip_backref():
    """References to the same object are preserved."""
    foo = 'foo'
    obj = [foo, foo]
    buf = pencode(obj)
    assert isinstance(buf, bytes)
    a, b = pdecode(buf)
    assert a is b
def assert_roundtrip(obj):
    """Assert that we can successfully round-trip the given object."""
    buf = pencode(obj)
    assert isinstance(buf, bytes)
    obj2 = pdecode(buf)

    try:
        assert obj == obj2
    except RuntimeError as e:
        if 'maximum recursion depth exceeded' not in e.args[0]:
            raise
        # If we hit a RecursionError, we correctly decoded a recursive
        # structure, so test passes :)
    except RecursionError:
        pass

    assert type(obj) == type(obj2)
    return obj2
Beispiel #4
0
def assert_roundtrip(obj):
    """Assert that we can successfully round-trip the given object."""
    buf = pencode(obj)
    assert isinstance(buf, bytes)
    obj2 = pdecode(buf)

    try:
        assert obj == obj2
    except RuntimeError as e:
        if 'maximum recursion depth exceeded' not in e.args[0]:
            raise
        # If we hit a RecursionError, we correctly decoded a recursive
        # structure, so test passes :)
    except RecursionError:
        pass

    assert type(obj) == type(obj2)
    return obj2
Beispiel #5
0
        {
            'e': 101,
            'i': 105,
            'o': 111,
            'q': 113,
            'p': 112,
            'r': 114,
            'u': 117,
            't': 116,
            'w': 119,
            'y': 121,
            'x': i
        },
    ] for i in range(1000)]


runner = perf.Runner()

if __name__ == '__main__':
    v = setup()
    assert pdecode(pencode(v)) == v
    #pencode(v)
    runner.timeit(
        name='pencode',
        stmt='pencode(v)',
        globals={
            'v': v,
            'pencode': pencode
        },
    )
def test_roundtrip_float_nan():
    """We can round-trip nan."""
    import math
    res = pdecode(pencode(float('nan')))
    assert math.isnan(res)
def test_unserialisable():
    """An exception is raised if a type is not serialisable."""
    with pytest.raises(ValueError):
        pencode(object())
Beispiel #8
0
def test_roundtrip_float_nan():
    """We can round-trip nan."""
    import math
    res = pdecode(pencode(float('nan')))
    assert math.isnan(res)
Beispiel #9
0
def test_unserialisable():
    """An exception is raised if a type is not serialisable."""
    with pytest.raises(ValueError):
        pencode(object())