Kaydet (Commit) 047f14c3 authored tarafından Kushal Das's avatar Kushal Das

Closes #21256: Printout of keyword args in deterministic order in mock calls.

Printout of keyword args should be in deterministic order in
a mock function call. This will help to write better doctests.
üst 85e4235c
...@@ -1894,7 +1894,7 @@ def _format_call_signature(name, args, kwargs): ...@@ -1894,7 +1894,7 @@ def _format_call_signature(name, args, kwargs):
formatted_args = '' formatted_args = ''
args_string = ', '.join([repr(arg) for arg in args]) args_string = ', '.join([repr(arg) for arg in args])
kwargs_string = ', '.join([ kwargs_string = ', '.join([
'%s=%r' % (key, value) for key, value in kwargs.items() '%s=%r' % (key, value) for key, value in sorted(kwargs.items())
]) ])
if args_string: if args_string:
formatted_args = args_string formatted_args = args_string
......
...@@ -1206,6 +1206,12 @@ class MockTest(unittest.TestCase): ...@@ -1206,6 +1206,12 @@ class MockTest(unittest.TestCase):
with self.assertRaises(AssertionError): with self.assertRaises(AssertionError):
m.hello.assert_not_called() m.hello.assert_not_called()
#Issue21256 printout of keyword args should be in deterministic order
def test_sorted_call_signature(self):
m = Mock()
m.hello(name='hello', daddy='hero')
text = "call(daddy='hero', name='hello')"
self.assertEquals(repr(m.hello.call_args), text)
def test_mock_add_spec(self): def test_mock_add_spec(self):
class _One(object): class _One(object):
......
...@@ -92,6 +92,9 @@ Core and Builtins ...@@ -92,6 +92,9 @@ Core and Builtins
Library Library
------- -------
- Issue #21256: Printout of keyword args should be in deterministic order in
a mock function call. This will help to write better doctests.
- Issue #21677: Fixed chaining nonnormalized exceptions in io close() methods. - Issue #21677: Fixed chaining nonnormalized exceptions in io close() methods.
- Issue #11709: Fix the pydoc.help function to not fail when sys.stdin is not a - Issue #11709: Fix the pydoc.help function to not fail when sys.stdin is not a
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment