diff options
author | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-12-01 20:05:49 +0000 |
---|---|---|
committer | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-12-01 20:05:49 +0000 |
commit | 41e422a4ffd2c9ce778b1d03180b4aa758dc6fc9 (patch) | |
tree | b24f8dd2394482f6d8dc491d1afb908b792b3354 /Lib/test/test_functools.py | |
parent | 419e3de3734edfec1aa04a3123e53199193a0bed (diff) | |
download | cpython-git-41e422a4ffd2c9ce778b1d03180b4aa758dc6fc9.tar.gz |
Issue #4113: Added custom __repr__ method to functools.partial.
Diffstat (limited to 'Lib/test/test_functools.py')
-rw-r--r-- | Lib/test/test_functools.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index e5921a758f..f41a144a14 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -146,6 +146,32 @@ class TestPartial(unittest.TestCase): join = self.thetype(''.join) self.assertEqual(join(data), '0123456789') + def test_repr(self): + args = (object(), object()) + args_repr = ', '.join(repr(a) for a in args) + kwargs = {'a': object(), 'b': object()} + kwargs_repr = ', '.join("%s=%r" % (k, v) for k, v in kwargs.items()) + if self.thetype is functools.partial: + name = 'functools.partial' + else: + name = self.thetype.__name__ + + f = self.thetype(capture) + self.assertEqual('{}({!r})'.format(name, capture), + repr(f)) + + f = self.thetype(capture, *args) + self.assertEqual('{}({!r}, {})'.format(name, capture, args_repr), + repr(f)) + + f = self.thetype(capture, **kwargs) + self.assertEqual('{}({!r}, {})'.format(name, capture, kwargs_repr), + repr(f)) + + f = self.thetype(capture, *args, **kwargs) + self.assertEqual('{}({!r}, {}, {})'.format(name, capture, args_repr, kwargs_repr), + repr(f)) + def test_pickle(self): f = self.thetype(signature, 'asdf', bar=True) f.add_something_to__dict__ = True @@ -163,6 +189,9 @@ class TestPythonPartial(TestPartial): thetype = PythonPartial + # the python version hasn't a nice repr + def test_repr(self): pass + # the python version isn't picklable def test_pickle(self): pass |