Skip to content

Commit c00dbc2

Browse files
Fix test_pickle. Enable more tests in test_xpickle.
1 parent d482988 commit c00dbc2

File tree

3 files changed

+133
-114
lines changed

3 files changed

+133
-114
lines changed

Lib/test/picklecommon.py

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
# Classes used for pickle testing.
2+
# They are moved to separate file, so they can be loaded
3+
# in other Python version for test_xpickle.
4+
15
class C:
26
def __eq__(self, other):
37
return self.__dict__ == other.__dict__
48

9+
# For test_load_classic_instance
510
class D(C):
611
def __init__(self, arg):
712
pass
@@ -31,10 +36,12 @@ def __reduce__(self):
3136
# Shouldn't support the recursion itself
3237
return K, (self.value,)
3338

39+
# For test_misc
3440
class myint(int):
3541
def __init__(self, x):
3642
self.str = str(x)
3743

44+
# For test_misc and test_getinitargs
3845
class initarg(C):
3946

4047
def __init__(self, a, b):
@@ -44,6 +51,7 @@ def __init__(self, a, b):
4451
def __getinitargs__(self):
4552
return self.a, self.b
4653

54+
# For test_metaclass
4755
class metaclass(type):
4856
pass
4957

@@ -140,14 +148,17 @@ def __setstate__(self, state):
140148
def __reduce__(self):
141149
return type(self), (), self.state
142150

151+
# For test_reduce_ex_None
143152
class REX_None:
144153
""" Setting __reduce_ex__ to None should fail """
145154
__reduce_ex__ = None
146155

156+
# For test_reduce_None
147157
class R_None:
148158
""" Setting __reduce__ to None should fail """
149159
__reduce__ = None
150160

161+
# For test_pickle_setstate_None
151162
class C_None_setstate:
152163
""" Setting __setstate__ to None should fail """
153164
def __getstate__(self):
@@ -158,6 +169,8 @@ def __getstate__(self):
158169

159170
# Test classes for newobj
160171

172+
# For test_newobj_generic and test_newobj_proxies
173+
161174
class MyInt(int):
162175
sample = 1
163176

@@ -193,6 +206,7 @@ class MyFrozenSet(frozenset):
193206
MyStr, MyUnicode,
194207
MyTuple, MyList, MyDict, MySet, MyFrozenSet]
195208

209+
# For test_newobj_overridden_new
196210
class MyIntWithNew(int):
197211
def __new__(cls, value):
198212
raise AssertionError
@@ -201,6 +215,7 @@ class MyIntWithNew2(MyIntWithNew):
201215
__new__ = int.__new__
202216

203217

218+
# For test_newobj_list_slots
204219
class SlotList(MyList):
205220
__slots__ = ["foo"]
206221

@@ -221,16 +236,6 @@ class ComplexNewObjEx(SimpleNewObj):
221236
def __getnewargs_ex__(self):
222237
return ('%X' % self,), {'base': 16}
223238

224-
class BadGetattr:
225-
def __getattr__(self, key):
226-
self.foo
227-
228-
class NoNew:
229-
def __getattribute__(self, name):
230-
if name == '__new__':
231-
raise AttributeError
232-
return super().__getattribute__(name)
233-
234239

235240
class ZeroCopyBytes(bytes):
236241
readonly = True
@@ -371,3 +376,42 @@ def _reconstruct(cls, obj, kwargs):
371376
# XXX This only works if format == 'B'
372377
items = list(m.tobytes())
373378
return cls(items, **kwargs)
379+
380+
381+
# For test_nested_names
382+
class Nested:
383+
class A:
384+
class B:
385+
class C:
386+
pass
387+
388+
# For test_py_methods
389+
class PyMethodsTest:
390+
@staticmethod
391+
def cheese():
392+
return "cheese"
393+
@classmethod
394+
def wine(cls):
395+
assert cls is PyMethodsTest
396+
return "wine"
397+
def biscuits(self):
398+
assert isinstance(self, PyMethodsTest)
399+
return "biscuits"
400+
class Nested:
401+
"Nested class"
402+
@staticmethod
403+
def ketchup():
404+
return "ketchup"
405+
@classmethod
406+
def maple(cls):
407+
assert cls is PyMethodsTest.Nested
408+
return "maple"
409+
def pie(self):
410+
assert isinstance(self, PyMethodsTest.Nested)
411+
return "pie"
412+
413+
# For test_c_methods
414+
class Subclass(tuple):
415+
class Nested(str):
416+
pass
417+

0 commit comments

Comments
 (0)