##// END OF EJS Templates
Doc tweaks and updates
Doc tweaks and updates

File last commit:

r3661:ee9089a7
r3663:11592a75
Show More
test_newserialized.py
86 lines | 2.9 KiB | text/x-python | PythonLexer
/ IPython / zmq / parallel / tests / test_newserialized.py
MinRK
some initial tests for newparallel
r3637 """test serialization with newserialized"""
MinRK
prep newparallel for rebase...
r3539
from unittest import TestCase
MinRK
some initial tests for newparallel
r3637 from IPython.testing.parametric import parametric
from IPython.utils import newserialized as ns
from IPython.utils.pickleutil import can, uncan, CannedObject, CannedFunction
from IPython.zmq.parallel.tests.clienttest import skip_without
class CanningTestCase(TestCase):
def test_canning(self):
d = dict(a=5,b=6)
cd = can(d)
MinRK
pyzmq-2.1.3 related testing adjustments
r3661 self.assertTrue(isinstance(cd, dict))
MinRK
some initial tests for newparallel
r3637
def test_canned_function(self):
f = lambda : 7
cf = can(f)
MinRK
pyzmq-2.1.3 related testing adjustments
r3661 self.assertTrue(isinstance(cf, CannedFunction))
MinRK
some initial tests for newparallel
r3637
@parametric
def test_can_roundtrip(cls):
objs = [
dict(),
set(),
list(),
['a',1,['a',1],u'e'],
]
return map(cls.run_roundtrip, objs)
@classmethod
MinRK
pyzmq-2.1.3 related testing adjustments
r3661 def run_roundtrip(self, obj):
MinRK
some initial tests for newparallel
r3637 o = uncan(can(obj))
MinRK
pyzmq-2.1.3 related testing adjustments
r3661 assert o == obj, "failed assertion: %r == %r"%(o,obj)
MinRK
some initial tests for newparallel
r3637
def test_serialized_interfaces(self):
us = {'a':10, 'b':range(10)}
s = ns.serialize(us)
uus = ns.unserialize(s)
MinRK
pyzmq-2.1.3 related testing adjustments
r3661 self.assertTrue(isinstance(s, ns.SerializeIt))
self.assertEquals(uus, us)
MinRK
some initial tests for newparallel
r3637
def test_pickle_serialized(self):
obj = {'a':1.45345, 'b':'asdfsdf', 'c':10000L}
original = ns.UnSerialized(obj)
originalSer = ns.SerializeIt(original)
firstData = originalSer.getData()
firstTD = originalSer.getTypeDescriptor()
firstMD = originalSer.getMetadata()
MinRK
pyzmq-2.1.3 related testing adjustments
r3661 self.assertEquals(firstTD, 'pickle')
self.assertEquals(firstMD, {})
MinRK
some initial tests for newparallel
r3637 unSerialized = ns.UnSerializeIt(originalSer)
secondObj = unSerialized.getObject()
for k, v in secondObj.iteritems():
MinRK
pyzmq-2.1.3 related testing adjustments
r3661 self.assertEquals(obj[k], v)
MinRK
some initial tests for newparallel
r3637 secondSer = ns.SerializeIt(ns.UnSerialized(secondObj))
MinRK
pyzmq-2.1.3 related testing adjustments
r3661 self.assertEquals(firstData, secondSer.getData())
self.assertEquals(firstTD, secondSer.getTypeDescriptor() )
self.assertEquals(firstMD, secondSer.getMetadata())
MinRK
some initial tests for newparallel
r3637
@skip_without('numpy')
def test_ndarray_serialized(self):
import numpy
a = numpy.linspace(0.0, 1.0, 1000)
unSer1 = ns.UnSerialized(a)
ser1 = ns.SerializeIt(unSer1)
td = ser1.getTypeDescriptor()
MinRK
pyzmq-2.1.3 related testing adjustments
r3661 self.assertEquals(td, 'ndarray')
MinRK
some initial tests for newparallel
r3637 md = ser1.getMetadata()
MinRK
pyzmq-2.1.3 related testing adjustments
r3661 self.assertEquals(md['shape'], a.shape)
self.assertEquals(md['dtype'], a.dtype.str)
MinRK
some initial tests for newparallel
r3637 buff = ser1.getData()
MinRK
pyzmq-2.1.3 related testing adjustments
r3661 self.assertEquals(buff, numpy.getbuffer(a))
MinRK
some initial tests for newparallel
r3637 s = ns.Serialized(buff, td, md)
final = ns.unserialize(s)
MinRK
pyzmq-2.1.3 related testing adjustments
r3661 self.assertEquals(numpy.getbuffer(a), numpy.getbuffer(final))
self.assertTrue((a==final).all())
self.assertEquals(a.dtype.str, final.dtype.str)
self.assertEquals(a.shape, final.shape)
MinRK
some initial tests for newparallel
r3637 # test non-copying:
a[2] = 1e9
MinRK
pyzmq-2.1.3 related testing adjustments
r3661 self.assertTrue((a==final).all())
MinRK
some initial tests for newparallel
r3637