Skip to content

Commit 1dbe82a

Browse files
Refactor tests.
1 parent 3c43a5b commit 1dbe82a

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

Lib/test/pickletester.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,15 @@ def __reduce__(self):
174174
# Shouldn't support the recursion itself
175175
return K, (self.value,)
176176

177-
class L:
178-
def __init__(self):
179-
self.attr = self.__foo
177+
class PrivateMethods:
178+
def __init__(self, value):
179+
self.value = value
180180

181-
def __foo(self):
182-
return 42
181+
def __private_method(self):
182+
return self.value
183183

184+
def get_method(self):
185+
return self.__private_method
184186

185187
class myint(int):
186188
def __init__(self, x):
@@ -3663,13 +3665,6 @@ def test_many_puts_and_gets(self):
36633665
loaded = self.loads(dumped)
36643666
self.assert_is_copy(obj, loaded)
36653667

3666-
def test_mangled_private_methods_roundtrip(self):
3667-
obj = L()
3668-
for proto in protocols:
3669-
with self.subTest(proto=proto):
3670-
loaded = self.loads(self.dumps(obj, proto))
3671-
self.assertEqual(loaded.attr(), 42)
3672-
36733668
def test_attribute_name_interning(self):
36743669
# Test that attribute names of pickled objects are interned when
36753670
# unpickling.
@@ -4087,6 +4082,13 @@ class Nested(str):
40874082
with self.subTest(proto=proto, descr=descr):
40884083
self.assertRaises(TypeError, self.dumps, descr, proto)
40894084

4085+
def test_private_methods(self):
4086+
obj = PrivateMethods(42)
4087+
for proto in protocols:
4088+
with self.subTest(proto=proto):
4089+
unpickled = self.loads(self.dumps(obj.get_method(), proto))
4090+
self.assertEqual(unpickled(), 42)
4091+
40904092
def test_compat_pickle(self):
40914093
tests = [
40924094
(range(1, 7), '__builtin__', 'xrange'),

0 commit comments

Comments
 (0)