diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-12 12:08:57 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-12 12:08:57 (GMT) |
commit | 1e09006c3cf85dc6605d015c55ee9debcdccb374 (patch) | |
tree | 66eac129d2f3b5f1d8172f570aabc0935f30db5e | |
parent | 1f7586eeb921d4b1116823b2aea752aaee1329ce (diff) | |
download | cpython-1e09006c3cf85dc6605d015c55ee9debcdccb374.zip cpython-1e09006c3cf85dc6605d015c55ee9debcdccb374.tar.gz cpython-1e09006c3cf85dc6605d015c55ee9debcdccb374.tar.bz2 |
Issue #25455: Backported tests for pickling recursive functools.partial objects.
-rw-r--r-- | 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 index 69176f4..06a9da3 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -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 |