##// END OF EJS Templates
test serializing lists / tuples / namedtuples
MinRK -
Show More
@@ -12,6 +12,7 b''
12 #-------------------------------------------------------------------------------
12 #-------------------------------------------------------------------------------
13
13
14 import pickle
14 import pickle
15 from collections import namedtuple
15
16
16 import nose.tools as nt
17 import nose.tools as nt
17
18
@@ -186,12 +187,42 b' def test_class_oldstyle():'
186
187
187 bufs = serialize_object(dict(C=C))
188 bufs = serialize_object(dict(C=C))
188 canned = pickle.loads(bufs[0])
189 canned = pickle.loads(bufs[0])
189 yield nt.assert_true(canned['C'], CannedClass)
190 yield nt.assert_true(isinstance(canned['C'], CannedClass))
190 d, r = unserialize_object(bufs)
191 d, r = unserialize_object(bufs)
191 C2 = d['C']
192 C2 = d['C']
192 yield nt.assert_equal(C2.a, C.a)
193 yield nt.assert_equal(C2.a, C.a)
193
194
194 @dec.parametric
195 @dec.parametric
196 def test_tuple():
197 tup = (lambda x:x, 1)
198 bufs = serialize_object(tup)
199 canned = pickle.loads(bufs[0])
200 yield nt.assert_true(isinstance(canned, tuple))
201 t2, r = unserialize_object(bufs)
202 yield nt.assert_equal(t2[0](t2[1]), tup[0](tup[1]))
203
204 point = namedtuple('point', 'x y')
205
206 @dec.parametric
207 def test_namedtuple():
208 p = point(1,2)
209 bufs = serialize_object(p)
210 canned = pickle.loads(bufs[0])
211 yield nt.assert_true(isinstance(canned, point))
212 p2, r = unserialize_object(bufs, globals())
213 yield nt.assert_equal(p2.x, p.x)
214 yield nt.assert_equal(p2.y, p.y)
215
216 @dec.parametric
217 def test_list():
218 lis = [lambda x:x, 1]
219 bufs = serialize_object(lis)
220 canned = pickle.loads(bufs[0])
221 yield nt.assert_true(isinstance(canned, list))
222 l2, r = unserialize_object(bufs)
223 yield nt.assert_equal(l2[0](l2[1]), lis[0](lis[1]))
224
225 @dec.parametric
195 def test_class_inheritance():
226 def test_class_inheritance():
196 @interactive
227 @interactive
197 class C(object):
228 class C(object):
General Comments 0
You need to be logged in to leave comments. Login now