Debian Codegraph @

pypy/module/test_lib_pypy/no_test_pickle_extra.py

raw symbols SCIP
1 """
2 Disabled for now. This should run at app-level, too.
3 """
4 import pickle
5
6 class Picklable(object):
7 def __init__(self, a=555):
8 self.a = a
9 def __eq__(self, other):
10 return self.a == other.a
11 def __str__(self):
12 return '%s(%r)' % (self.__class__.__name__, self.a)
13 __repr__ = __str__
14
15 class PicklableSpecial2(Picklable):
16 def __reduce__(self):
17 return self.__class__, (self.a,)
18
19 class PicklableSpecial3(Picklable):
20 def __reduce__(self):
21 return self.__class__, (), self.a
22 def __setstate__(self, a):
23 self.a = a
24
25 class PicklableSpecial4(Picklable):
26 def __reduce_ex__(self, proto):
27 return self.__class__, (), self.a
28 def __setstate__(self, a):
29 self.a = a
30
31 def _pickle_some(x):
32 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
33 s = pickle.dumps(x, proto)
34 y = pickle.loads(s)
35 assert x == y
36
37 _pickle_some(Picklable(5))
38 _pickle_some(PicklableSpecial2(66))
39 _pickle_some(PicklableSpecial3(7))
40 _pickle_some(PicklableSpecial4(17))