]> granicus.if.org Git - python/commitdiff
Issue #25455: Backported tests for pickling recursive functools.partial objects.
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 12 Jun 2016 12:08:57 +0000 (15:08 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 12 Jun 2016 12:08:57 +0000 (15:08 +0300)
Lib/test/test_functools.py

index 69176f434ea070758d3042ef31ff8418fb5e810e..06a9da3f41a65d4b7d33bac4933dcc27ca9cae7d 100644 (file)
@@ -236,6 +236,25 @@ class TestPartial(unittest.TestCase):
         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 @@ class TestPythonPartial(TestPartial):
     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