diff -r f947fe289db8 Lib/test/test_functools.py --- a/Lib/test/test_functools.py Thu Nov 21 22:33:21 2013 +0100 +++ b/Lib/test/test_functools.py Fri Nov 22 00:22:45 2013 +0100 @@ -155,12 +155,21 @@ class TestPartialC(TestPartial, unittest 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()) + kwargs_repr = ', '.join("%s=%r" % (k, v) for k, v in sorted(kwargs.items())) if self.partial is c_functools.partial: name = 'functools.partial' else: name = self.partial.__name__ + def check_kw_repr(f, prefix, kwargs_repr): + text = repr(f) + self.assertTrue(text.startswith(prefix), text) + self.assertTrue(text.endswith(')'), text) + kwargs = text[len(prefix):-1] + # sort keywords to not depend on the hash randomization + kwargs = ', '.join(sorted(kwargs.split(', '))) + self.assertEqual(kwargs, kwargs_repr) + f = self.partial(capture) self.assertEqual('{}({!r})'.format(name, capture), repr(f)) @@ -170,12 +179,10 @@ class TestPartialC(TestPartial, unittest repr(f)) f = self.partial(capture, **kwargs) - self.assertEqual('{}({!r}, {})'.format(name, capture, kwargs_repr), - repr(f)) + check_kw_repr(f, '{}({!r}, '.format(name, capture), kwargs_repr) f = self.partial(capture, *args, **kwargs) - self.assertEqual('{}({!r}, {}, {})'.format(name, capture, args_repr, kwargs_repr), - repr(f)) + check_kw_repr(f, '{}({!r}, {}, '.format(name, capture, args_repr), kwargs_repr) def test_pickle(self): f = self.partial(signature, 'asdf', bar=True)