diff options
author | Jack Diederich <jackdied@gmail.com> | 2009-03-31 23:46:48 +0000 |
---|---|---|
committer | Jack Diederich <jackdied@gmail.com> | 2009-03-31 23:46:48 +0000 |
commit | d60c29ed8b12fda1d129e21b80a5d9ce4125a21a (patch) | |
tree | f7524afac78222e37db8e426289946fc4756cdb9 /Lib/test/test_functools.py | |
parent | 840ac926c572caa7656449aa1e815660e69f7713 (diff) | |
download | cpython-git-d60c29ed8b12fda1d129e21b80a5d9ce4125a21a.tar.gz |
#5228: add pickle support to functools.partial
Diffstat (limited to 'Lib/test/test_functools.py')
-rw-r--r-- | Lib/test/test_functools.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 30d419da21..cd645d34bf 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -2,6 +2,7 @@ import functools import unittest from test import test_support from weakref import proxy +import pickle @staticmethod def PythonPartial(func, *args, **keywords): @@ -19,6 +20,10 @@ def capture(*args, **kw): """capture all positional and keyword arguments""" return args, kw +def signature(part): + """ return the signature of a partial object """ + return (part.func, part.args, part.keywords, part.__dict__) + class TestPartial(unittest.TestCase): thetype = functools.partial @@ -140,6 +145,12 @@ class TestPartial(unittest.TestCase): join = self.thetype(''.join) self.assertEqual(join(data), '0123456789') + def test_pickle(self): + f = self.thetype(signature, 'asdf', bar=True) + f.add_something_to__dict__ = True + f_copy = pickle.loads(pickle.dumps(f)) + self.assertEqual(signature(f), signature(f_copy)) + class PartialSubclass(functools.partial): pass @@ -147,11 +158,13 @@ class TestPartialSubclass(TestPartial): thetype = PartialSubclass - class TestPythonPartial(TestPartial): thetype = PythonPartial + # the python version isn't picklable + def test_pickle(self): pass + class TestUpdateWrapper(unittest.TestCase): def check_wrapper(self, wrapper, wrapped, |