summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_functools.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-06-12 12:53:09 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-06-12 12:53:09 (GMT)
commit8918b89e61a8417f36848d332fa7af5776c7d688 (patch)
tree4ea41e11e0596c29d03a494a6f9052ec603d3b45 /Lib/test/test_functools.py
parent0f355c0022946412ee6b7ba37ffbeb6aa8bc02a2 (diff)
parent46fe29de318c628309c2f12bec3a32f7e15ba844 (diff)
downloadcpython-8918b89e61a8417f36848d332fa7af5776c7d688.zip
cpython-8918b89e61a8417f36848d332fa7af5776c7d688.tar.gz
cpython-8918b89e61a8417f36848d332fa7af5776c7d688.tar.bz2
Issue #25455: Clean up reference loops created in tests for recursive
functools.partial objects.
Diffstat (limited to 'Lib/test/test_functools.py')
-rw-r--r--Lib/test/test_functools.py48
1 files changed, 36 insertions, 12 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index 03e7e5b..e2ab654 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -225,15 +225,24 @@ class TestPartialC(TestPartial, unittest.TestCase):
f = self.partial(capture)
f.__setstate__((f, (), {}, {}))
- self.assertEqual(repr(f), '%s(%s(...))' % (name, name))
+ try:
+ self.assertEqual(repr(f), '%s(%s(...))' % (name, name))
+ finally:
+ f.__setstate__((capture, (), {}, {}))
f = self.partial(capture)
f.__setstate__((capture, (f,), {}, {}))
- self.assertEqual(repr(f), '%s(%r, %s(...))' % (name, capture, name))
+ try:
+ self.assertEqual(repr(f), '%s(%r, %s(...))' % (name, capture, name))
+ finally:
+ f.__setstate__((capture, (), {}, {}))
f = self.partial(capture)
f.__setstate__((capture, (), {'a': f}, {}))
- self.assertEqual(repr(f), '%s(%r, a=%s(...))' % (name, capture, name))
+ try:
+ self.assertEqual(repr(f), '%s(%r, a=%s(...))' % (name, capture, name))
+ finally:
+ f.__setstate__((capture, (), {}, {}))
def test_pickle(self):
f = self.partial(signature, ['asdf'], bar=[True])
@@ -318,21 +327,36 @@ class TestPartialC(TestPartial, unittest.TestCase):
def test_recursive_pickle(self):
f = self.partial(capture)
f.__setstate__((f, (), {}, {}))
- for proto in range(pickle.HIGHEST_PROTOCOL + 1):
- with self.assertRaises(RecursionError):
- pickle.dumps(f, proto)
+ try:
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ with self.assertRaises(RecursionError):
+ pickle.dumps(f, proto)
+ finally:
+ f.__setstate__((capture, (), {}, {}))
f = self.partial(capture)
f.__setstate__((capture, (f,), {}, {}))
- for proto in range(pickle.HIGHEST_PROTOCOL + 1):
- f_copy = pickle.loads(pickle.dumps(f, proto))
- self.assertIs(f_copy.args[0], f_copy)
+ try:
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ f_copy = pickle.loads(pickle.dumps(f, proto))
+ try:
+ self.assertIs(f_copy.args[0], f_copy)
+ finally:
+ f_copy.__setstate__((capture, (), {}, {}))
+ finally:
+ f.__setstate__((capture, (), {}, {}))
f = self.partial(capture)
f.__setstate__((capture, (), {'a': f}, {}))
- for proto in range(pickle.HIGHEST_PROTOCOL + 1):
- f_copy = pickle.loads(pickle.dumps(f, proto))
- self.assertIs(f_copy.keywords['a'], f_copy)
+ try:
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ f_copy = pickle.loads(pickle.dumps(f, proto))
+ try:
+ self.assertIs(f_copy.keywords['a'], f_copy)
+ finally:
+ f_copy.__setstate__((capture, (), {}, {}))
+ finally:
+ f.__setstate__((capture, (), {}, {}))
# Issue 6083: Reference counting bug
def test_setstate_refcount(self):