Skip to content

Commit 6317677

Browse files
Add tests for other types of methods.
1 parent 1dbe82a commit 6317677

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Lib/test/pickletester.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,26 @@ def __private_method(self):
184184
def get_method(self):
185185
return self.__private_method
186186

187+
@classmethod
188+
def get_unbound_method(cls):
189+
return cls.__private_method
190+
191+
@classmethod
192+
def __private_classmethod(cls):
193+
return 43
194+
195+
@classmethod
196+
def get_classmethod(cls):
197+
return cls.__private_classmethod
198+
199+
@staticmethod
200+
def __private_staticmethod():
201+
return 44
202+
203+
@classmethod
204+
def get_staticmethod(cls):
205+
return cls.__private_staticmethod
206+
187207
class myint(int):
188208
def __init__(self, x):
189209
self.str = str(x)
@@ -4088,6 +4108,12 @@ def test_private_methods(self):
40884108
with self.subTest(proto=proto):
40894109
unpickled = self.loads(self.dumps(obj.get_method(), proto))
40904110
self.assertEqual(unpickled(), 42)
4111+
unpickled = self.loads(self.dumps(obj.get_unbound_method(), proto))
4112+
self.assertEqual(unpickled(obj), 42)
4113+
unpickled = self.loads(self.dumps(obj.get_classmethod(), proto))
4114+
self.assertEqual(unpickled(), 43)
4115+
unpickled = self.loads(self.dumps(obj.get_staticmethod(), proto))
4116+
self.assertEqual(unpickled(), 44)
40914117

40924118
def test_compat_pickle(self):
40934119
tests = [

0 commit comments

Comments
 (0)