Show More
@@ -12,6 +12,7 b'' | |||
|
12 | 12 | #------------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | 14 | import pickle |
|
15 | from collections import namedtuple | |
|
15 | 16 | |
|
16 | 17 | import nose.tools as nt |
|
17 | 18 | |
@@ -186,12 +187,42 b' def test_class_oldstyle():' | |||
|
186 | 187 | |
|
187 | 188 | bufs = serialize_object(dict(C=C)) |
|
188 | 189 | canned = pickle.loads(bufs[0]) |
|
189 | yield nt.assert_true(canned['C'], CannedClass) | |
|
190 | yield nt.assert_true(isinstance(canned['C'], CannedClass)) | |
|
190 | 191 | d, r = unserialize_object(bufs) |
|
191 | 192 | C2 = d['C'] |
|
192 | 193 | yield nt.assert_equal(C2.a, C.a) |
|
193 | 194 | |
|
194 | 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 | 226 | def test_class_inheritance(): |
|
196 | 227 | @interactive |
|
197 | 228 | class C(object): |
General Comments 0
You need to be logged in to leave comments.
Login now