diff options
author | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-07-10 13:52:22 (GMT) |
---|---|---|
committer | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-07-10 13:52:22 (GMT) |
commit | c653ce313f6781d27852a3f3552a0295c1a1fa6a (patch) | |
tree | 5786116363ab341638faf74c5c3fc0f6a59f6947 /Lib/unittest/case.py | |
parent | 0425a8ea729617a74ab343909687d98216d25524 (diff) | |
download | cpython-c653ce313f6781d27852a3f3552a0295c1a1fa6a.zip cpython-c653ce313f6781d27852a3f3552a0295c1a1fa6a.tar.gz cpython-c653ce313f6781d27852a3f3552a0295c1a1fa6a.tar.bz2 |
Fix error message for comparing single line strings in unittest.TestCase.assertEqual.
Issue 9174.
Diffstat (limited to 'Lib/unittest/case.py')
-rw-r--r-- | Lib/unittest/case.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 3bc2b3d..03346a1 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -940,9 +940,14 @@ class TestCase(object): 'Second argument is not a string')) if first != second: - standardMsg = '%s != %s' % (safe_repr(first, True), safe_repr(second, True)) - diff = '\n' + ''.join(difflib.ndiff(first.splitlines(True), - second.splitlines(True))) + firstlines = first.splitlines(True) + secondlines = second.splitlines(True) + if len(firstlines) == 1 and first.strip('\r\n') == first: + firstlines = [first + '\n'] + secondlines = [second + '\n'] + standardMsg = '%s != %s' % (safe_repr(first, True), + safe_repr(second, True)) + diff = '\n' + ''.join(difflib.ndiff(firstlines, secondlines)) standardMsg = self._truncateMessage(standardMsg, diff) self.fail(self._formatMessage(msg, standardMsg)) |