Skip to content

Commit 50d936a

Browse files
[3.11] gh-111019: Align expected and actual titles in test output (GH-111020) (#111025)
gh-111019: Align expected and actual titles in test output (GH-111020) Align expected and actual titles in output from assert_has_calls/assert_called_with for greater readability (cherry picked from commit 77dbd95) Co-authored-by: James <[email protected]>
1 parent 72131d0 commit 50d936a

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Lib/unittest/mock.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ def _format_mock_call_signature(self, args, kwargs):
822822

823823

824824
def _format_mock_failure_message(self, args, kwargs, action='call'):
825-
message = 'expected %s not found.\nExpected: %s\nActual: %s'
825+
message = 'expected %s not found.\nExpected: %s\n Actual: %s'
826826
expected_string = self._format_mock_call_signature(args, kwargs)
827827
call_args = self.call_args
828828
actual_string = self._format_mock_call_signature(*call_args)
@@ -925,7 +925,7 @@ def assert_called_with(self, /, *args, **kwargs):
925925
if self.call_args is None:
926926
expected = self._format_mock_call_signature(args, kwargs)
927927
actual = 'not called.'
928-
error_message = ('expected call not found.\nExpected: %s\nActual: %s'
928+
error_message = ('expected call not found.\nExpected: %s\n Actual: %s'
929929
% (expected, actual))
930930
raise AssertionError(error_message)
931931

@@ -976,7 +976,7 @@ def assert_has_calls(self, calls, any_order=False):
976976
raise AssertionError(
977977
f'{problem}\n'
978978
f'Expected: {_CallList(calls)}'
979-
f'{self._calls_repr(prefix="Actual").rstrip(".")}'
979+
f'{self._calls_repr(prefix=" Actual").rstrip(".")}'
980980
) from cause
981981
return
982982

Lib/unittest/test/testmock/testmock.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ def test_assert_called_with_failure_message(self):
10391039

10401040
actual = 'not called.'
10411041
expected = "mock(1, '2', 3, bar='foo')"
1042-
message = 'expected call not found.\nExpected: %s\nActual: %s'
1042+
message = 'expected call not found.\nExpected: %s\n Actual: %s'
10431043
self.assertRaisesWithMsg(
10441044
AssertionError, message % (expected, actual),
10451045
mock.assert_called_with, 1, '2', 3, bar='foo'
@@ -1054,7 +1054,7 @@ def test_assert_called_with_failure_message(self):
10541054
for meth in asserters:
10551055
actual = "foo(1, '2', 3, foo='foo')"
10561056
expected = "foo(1, '2', 3, bar='foo')"
1057-
message = 'expected call not found.\nExpected: %s\nActual: %s'
1057+
message = 'expected call not found.\nExpected: %s\n Actual: %s'
10581058
self.assertRaisesWithMsg(
10591059
AssertionError, message % (expected, actual),
10601060
meth, 1, '2', 3, bar='foo'
@@ -1064,7 +1064,7 @@ def test_assert_called_with_failure_message(self):
10641064
for meth in asserters:
10651065
actual = "foo(1, '2', 3, foo='foo')"
10661066
expected = "foo(bar='foo')"
1067-
message = 'expected call not found.\nExpected: %s\nActual: %s'
1067+
message = 'expected call not found.\nExpected: %s\n Actual: %s'
10681068
self.assertRaisesWithMsg(
10691069
AssertionError, message % (expected, actual),
10701070
meth, bar='foo'
@@ -1074,7 +1074,7 @@ def test_assert_called_with_failure_message(self):
10741074
for meth in asserters:
10751075
actual = "foo(1, '2', 3, foo='foo')"
10761076
expected = "foo(1, 2, 3)"
1077-
message = 'expected call not found.\nExpected: %s\nActual: %s'
1077+
message = 'expected call not found.\nExpected: %s\n Actual: %s'
10781078
self.assertRaisesWithMsg(
10791079
AssertionError, message % (expected, actual),
10801080
meth, 1, 2, 3
@@ -1084,7 +1084,7 @@ def test_assert_called_with_failure_message(self):
10841084
for meth in asserters:
10851085
actual = "foo(1, '2', 3, foo='foo')"
10861086
expected = "foo()"
1087-
message = 'expected call not found.\nExpected: %s\nActual: %s'
1087+
message = 'expected call not found.\nExpected: %s\n Actual: %s'
10881088
self.assertRaisesWithMsg(
10891089
AssertionError, message % (expected, actual), meth
10901090
)
@@ -1533,7 +1533,7 @@ def f(x=None): pass
15331533
'^{}$'.format(
15341534
re.escape('Calls not found.\n'
15351535
'Expected: [call()]\n'
1536-
'Actual: [call(1)]'))) as cm:
1536+
' Actual: [call(1)]'))) as cm:
15371537
mock.assert_has_calls([call()])
15381538
self.assertIsNone(cm.exception.__cause__)
15391539

@@ -1545,7 +1545,7 @@ def f(x=None): pass
15451545
'Error processing expected calls.\n'
15461546
"Errors: [None, TypeError('too many positional arguments')]\n"
15471547
"Expected: [call(), call(1, 2)]\n"
1548-
'Actual: [call(1)]'))) as cm:
1548+
' Actual: [call(1)]'))) as cm:
15491549
mock.assert_has_calls([call(), call(1, 2)])
15501550
self.assertIsInstance(cm.exception.__cause__, TypeError)
15511551

0 commit comments

Comments
 (0)