Exemplo n.º 1
0
def test_class():
    @interactive
    class C(object):
        a=5
    bufs = serialize_object(dict(C=C))
    canned = pickle.loads(bufs[0])
    yield nt.assert_true(canned['C'], CannedClass)
    d, r = unserialize_object(bufs)
    C2 = d['C']
    yield nt.assert_equal(C2.a, C.a)
Exemplo n.º 2
0
def test_roundtrip_buffered():
    for obj in [
        dict(a=b"x"*1025),
        b"hello"*500,
        [b"hello"*501, 1,2,3]
    ]:
        bufs = serialize_object(obj)
        yield nt.assert_equals(len(bufs), 2)
        obj2, remainder = unserialize_object(bufs)
        yield nt.assert_equals(remainder, [])
        yield nt.assert_equals(obj, obj2)
Exemplo n.º 3
0
def test_numpy():
    import numpy
    from numpy.testing.utils import assert_array_equal
    for shape in SHAPES:
        for dtype in DTYPES:
            A = numpy.empty(shape, dtype=dtype)
            _scrub_nan(A)
            bufs = serialize_object(A)
            B, r = unserialize_object(bufs)
            yield nt.assert_equals(r, [])
            yield nt.assert_equals(A.shape, B.shape)
            yield nt.assert_equals(A.dtype, B.dtype)
            yield assert_array_equal(A,B)
Exemplo n.º 4
0
def test_numpy_in_dict():
    import numpy
    from numpy.testing.utils import assert_array_equal
    for shape in SHAPES:
        for dtype in DTYPES:
            A = numpy.empty(shape, dtype=dtype)
            _scrub_nan(A)
            bufs = serialize_object(dict(a=A,b=1,c=range(20)))
            canned = pickle.loads(bufs[0])
            yield nt.assert_true(canned['a'], CannedArray)
            d, r = unserialize_object(bufs)
            B = d['a']
            yield nt.assert_equals(r, [])
            yield nt.assert_equals(A.shape, B.shape)
            yield nt.assert_equals(A.dtype, B.dtype)
            yield assert_array_equal(A,B)
Exemplo n.º 5
0
def test_numpy_in_seq():
    import numpy
    from numpy.testing.utils import assert_array_equal
    for shape in SHAPES:
        for dtype in DTYPES:
            A = numpy.empty(shape, dtype=dtype)
            _scrub_nan(A)
            bufs = serialize_object((A,1,2,b'hello'))
            canned = pickle.loads(bufs[0])
            yield nt.assert_true(canned[0], CannedArray)
            tup, r = unserialize_object(bufs)
            B = tup[0]
            yield nt.assert_equals(r, [])
            yield nt.assert_equals(A.shape, B.shape)
            yield nt.assert_equals(A.dtype, B.dtype)
            yield assert_array_equal(A,B)
Exemplo n.º 6
0
def test_class_inheritance():
    @interactive
    class C(object):
        a=5

    @interactive
    class D(C):
        b=10
    
    bufs = serialize_object(dict(D=D))
    canned = pickle.loads(bufs[0])
    yield nt.assert_true(canned['D'], CannedClass)
    d, r = unserialize_object(bufs)
    D2 = d['D']
    yield nt.assert_equal(D2.a, D.a)
    yield nt.assert_equal(D2.b, D.b)
Exemplo n.º 7
0
def test_recarray():
    import numpy
    from numpy.testing.utils import assert_array_equal
    for shape in SHAPES:
        for dtype in [
            [('f', float), ('s', '|S10')],
            [('n', int), ('s', '|S1'), ('u', 'uint32')],
        ]:
            A = numpy.empty(shape, dtype=dtype)
            _scrub_nan(A)
            
            bufs = serialize_object(A)
            B, r = unserialize_object(bufs)
            yield nt.assert_equals(r, [])
            yield nt.assert_equals(A.shape, B.shape)
            yield nt.assert_equals(A.dtype, B.dtype)
            yield assert_array_equal(A,B)
Exemplo n.º 8
0
def roundtrip(obj):
    """roundtrip an object through serialization"""
    bufs = serialize_object(obj)
    obj2, remainder = unserialize_object(bufs)
    nt.assert_equals(remainder, [])
    return obj2