Ejemplo n.º 1
0
def test_list():
    lis = [lambda x:x, 1]
    bufs = serialize_object(lis)
    canned = pickle.loads(bufs[0])
    nt.assert_is_instance(canned, list)
    l2, r = unserialize_object(bufs)
    nt.assert_equal(l2[0](l2[1]), lis[0](lis[1]))
Ejemplo n.º 2
0
def test_tuple():
    tup = (lambda x:x, 1)
    bufs = serialize_object(tup)
    canned = pickle.loads(bufs[0])
    nt.assert_is_instance(canned, tuple)
    t2, r = unserialize_object(bufs)
    nt.assert_equal(t2[0](t2[1]), tup[0](tup[1]))
Ejemplo n.º 3
0
def test_tuple():
    tup = (lambda x: x, 1)
    bufs = serialize_object(tup)
    canned = pickle.loads(bufs[0])
    nt.assert_is_instance(canned, tuple)
    t2, r = unserialize_object(bufs)
    nt.assert_equal(t2[0](t2[1]), tup[0](tup[1]))
Ejemplo n.º 4
0
def test_list():
    lis = [lambda x: x, 1]
    bufs = serialize_object(lis)
    canned = pickle.loads(bufs[0])
    nt.assert_is_instance(canned, list)
    l2, r = unserialize_object(bufs)
    nt.assert_equal(l2[0](l2[1]), lis[0](lis[1]))
Ejemplo n.º 5
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)
        nt.assert_equal(len(bufs), 2)
        obj2, remainder = unserialize_object(bufs)
        nt.assert_equal(remainder, [])
        nt.assert_equal(obj, obj2)
Ejemplo n.º 6
0
def test_namedtuple():
    p = point(1,2)
    bufs = serialize_object(p)
    canned = pickle.loads(bufs[0])
    nt.assert_is_instance(canned, point)
    p2, r = unserialize_object(bufs, globals())
    nt.assert_equal(p2.x, p.x)
    nt.assert_equal(p2.y, p.y)
Ejemplo n.º 7
0
def test_namedtuple():
    p = point(1, 2)
    bufs = serialize_object(p)
    canned = pickle.loads(bufs[0])
    nt.assert_is_instance(canned, point)
    p2, r = unserialize_object(bufs, globals())
    nt.assert_equal(p2.x, p.x)
    nt.assert_equal(p2.y, p.y)
Ejemplo n.º 8
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)
        nt.assert_equal(len(bufs), 2)
        obj2, remainder = unserialize_object(bufs)
        nt.assert_equal(remainder, [])
        nt.assert_equal(obj, obj2)
Ejemplo n.º 9
0
def test_class():
    @interactive
    class C(object):
        a=5
    bufs = serialize_object(dict(C=C))
    canned = pickle.loads(bufs[0])
    nt.assert_is_instance(canned['C'], CannedClass)
    d, r = unserialize_object(bufs)
    C2 = d['C']
    nt.assert_equal(C2.a, C.a)
Ejemplo n.º 10
0
def test_class_oldstyle():
    @interactive
    class C:
        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)
Ejemplo n.º 11
0
def test_class_oldstyle():
    @interactive
    class C:
        a=5
    
    bufs = serialize_object(dict(C=C))
    canned = pickle.loads(bufs[0])
    yield nt.assert_true(isinstance(canned['C'], CannedClass))
    d, r = unserialize_object(bufs)
    C2 = d['C']
    yield nt.assert_equal(C2.a, C.a)
Ejemplo n.º 12
0
def test_numpy():
    import numpy
    from numpy.testing.utils import assert_array_equal
    for shape in SHAPES:
        for dtype in DTYPES:
            A = new_array(shape, dtype=dtype)
            bufs = serialize_object(A)
            B, r = unserialize_object(bufs)
            nt.assert_equal(r, [])
            nt.assert_equal(A.shape, B.shape)
            nt.assert_equal(A.dtype, B.dtype)
            assert_array_equal(A,B)
Ejemplo n.º 13
0
def test_numpy():
    import numpy
    from numpy.testing.utils import assert_array_equal
    for shape in SHAPES:
        for dtype in DTYPES:
            A = new_array(shape, dtype=dtype)
            bufs = serialize_object(A)
            B, r = unserialize_object(bufs)
            nt.assert_equal(r, [])
            nt.assert_equal(A.shape, B.shape)
            nt.assert_equal(A.dtype, B.dtype)
            assert_array_equal(A, B)
Ejemplo n.º 14
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)
Ejemplo n.º 15
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 = new_array(shape, dtype=dtype)
            bufs = serialize_object((A, 1, 2, b'hello'))
            canned = pickle.loads(bufs[0])
            nt.assert_is_instance(canned[0], CannedArray)
            tup, r = unserialize_object(bufs)
            B = tup[0]
            nt.assert_equal(r, [])
            nt.assert_equal(A.shape, B.shape)
            nt.assert_equal(A.dtype, B.dtype)
            assert_array_equal(A, B)
Ejemplo n.º 16
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)
            nt.assert_equal(r, [])
            nt.assert_equal(A.shape, B.shape)
            nt.assert_equal(A.dtype, B.dtype)
            assert_array_equal(A, B)
Ejemplo n.º 17
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 = new_array(shape, dtype=dtype)
            bufs = serialize_object(dict(a=A, b=1, c=range(20)))
            canned = pickle.loads(bufs[0])
            nt.assert_is_instance(canned['a'], CannedArray)
            d, r = unserialize_object(bufs)
            B = d['a']
            nt.assert_equal(r, [])
            nt.assert_equal(A.shape, B.shape)
            nt.assert_equal(A.dtype, B.dtype)
            assert_array_equal(A, B)
Ejemplo n.º 18
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 = new_array(shape, dtype=dtype)
            bufs = serialize_object(dict(a=A,b=1,c=range(20)))
            canned = pickle.loads(bufs[0])
            nt.assert_is_instance(canned['a'], CannedArray)
            d, r = unserialize_object(bufs)
            B = d['a']
            nt.assert_equal(r, [])
            nt.assert_equal(A.shape, B.shape)
            nt.assert_equal(A.dtype, B.dtype)
            assert_array_equal(A,B)
Ejemplo n.º 19
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 = new_array(shape, dtype=dtype)
            bufs = serialize_object((A,1,2,b'hello'))
            canned = pickle.loads(bufs[0])
            nt.assert_is_instance(canned[0], CannedArray)
            tup, r = unserialize_object(bufs)
            B = tup[0]
            nt.assert_equal(r, [])
            nt.assert_equal(A.shape, B.shape)
            nt.assert_equal(A.dtype, B.dtype)
            assert_array_equal(A,B)
Ejemplo n.º 20
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 = new_array(shape, dtype=dtype)

            bufs = serialize_object(A)
            B, r = unserialize_object(bufs)
            nt.assert_equal(r, [])
            nt.assert_equal(A.shape, B.shape)
            nt.assert_equal(A.dtype, B.dtype)
            assert_array_equal(A, B)
Ejemplo n.º 21
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)
Ejemplo n.º 22
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 = new_array(shape, dtype=dtype)
            
            bufs = serialize_object(A)
            B, r = unserialize_object(bufs)
            nt.assert_equal(r, [])
            nt.assert_equal(A.shape, B.shape)
            nt.assert_equal(A.dtype, B.dtype)
            assert_array_equal(A,B)
Ejemplo n.º 23
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])
    nt.assert_is_instance(canned['D'], CannedClass)
    d, r = unserialize_object(bufs)
    D2 = d['D']
    nt.assert_equal(D2.a, D.a)
    nt.assert_equal(D2.b, D.b)
Ejemplo n.º 24
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=list(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)
Ejemplo n.º 25
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])
    nt.assert_is_instance(canned["D"], CannedClass)
    d, r = unserialize_object(bufs)
    D2 = d["D"]
    nt.assert_equal(D2.a, D.a)
    nt.assert_equal(D2.b, D.b)
Ejemplo n.º 26
0
def roundtrip(obj):
    """roundtrip an object through serialization"""
    bufs = serialize_object(obj)
    obj2, remainder = unserialize_object(bufs)
    nt.assert_equals(remainder, [])
    return obj2
Ejemplo n.º 27
0
def roundtrip(obj):
    """roundtrip an object through serialization"""
    bufs = serialize_object(obj)
    obj2, remainder = unserialize_object(bufs)
    nt.assert_equals(remainder, [])
    return obj2