[Python-checkins] cpython (2.7): Issue #25455: Backported tests for pickling recursive functools.partial objects.

serhiy.storchaka python-checkins at python.org
Sun Jun 12 08:09:24 EDT 2016


https://hg.python.org/cpython/rev/7859742826b2
changeset:   101942:7859742826b2
branch:      2.7
parent:      101931:c071da010053
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sun Jun 12 15:08:57 2016 +0300
summary:
  Issue #25455: Backported tests for pickling recursive functools.partial objects.

files:
  Lib/test/test_functools.py |  20 ++++++++++++++++++++
  1 files changed, 20 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -236,6 +236,25 @@
         self.assertEqual(r, ((1, 2), {}))
         self.assertIs(type(r[0]), tuple)
 
+    def test_recursive_pickle(self):
+        f = self.thetype(capture)
+        f.__setstate__((f, (), {}, {}))
+        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+            with self.assertRaises(RuntimeError):
+                pickle.dumps(f, proto)
+
+        f = self.thetype(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)
+
+        f = self.thetype(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)
+
     # Issue 6083: Reference counting bug
     def test_setstate_refcount(self):
         class BadSequence:
@@ -270,6 +289,7 @@
     test_setstate_errors = None
     test_setstate_subclasses = None
     test_setstate_refcount = None
+    test_recursive_pickle = None
 
     # the python version isn't deepcopyable
     test_deepcopy = None

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list