Mercurial > cpython-lru_cache-weakref
diff Lib/test/test_functools.py @ 52637:ffa81bd2ec72
Merged revisions 70931 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70931 | jack.diederich | 2009-03-31 19:46:48 -0400 (Tue, 31 Mar 2009) | 1 line
#5228: add pickle support to functools.partial
........
| author | Jack Diederich <jackdied@gmail.com> |
|---|---|
| date | Wed, 01 Apr 2009 04:27:09 +0000 |
| parents | 9c930a32cebb |
| children | 0bb232078b8c |
line wrap: on
line diff
--- a/Lib/test/test_functools.py Wed Apr 01 03:42:00 2009 +0000 +++ b/Lib/test/test_functools.py Wed Apr 01 04:27:09 2009 +0000 @@ -2,6 +2,7 @@ import unittest from test import support from weakref import proxy +import pickle @staticmethod def PythonPartial(func, *args, **keywords): @@ -19,6 +20,9 @@ """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): @@ -141,6 +145,12 @@ 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 @@ -148,11 +158,13 @@ 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,
