msg135608 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2011-05-09 16:36 |
>>> tc.assertEqual("x\n" * 40 + "\n", "x\n" * 40 + "\r\n") Traceback (most recent call last): File "", line 1, in File "/home/antoine/cpython/default/Lib/unittest/case.py", line 662, in assertEqual assertion_func(first, second, msg=msg) File "/home/antoine/cpython/default/Lib/unittest/case.py", line 1041, in assertMultiLineEqual self.fail(self._formatMessage(msg, standardMsg)) File "/home/antoine/cpython/default/Lib/unittest/case.py", line 531, in fail raise self.failureException(msg) AssertionError: 'x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx [truncated]... != 'x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx [truncated]... x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x - + It isn't obvious when looking at this printout that the last newline differed. |
|
|
msg135657 - (view) |
Author: Michael Foord (michael.foord) *  |
Date: 2011-05-09 21:40 |
Yup, I agree that's pretty sucky. Any suggestions for a fix? |
|
|
msg135953 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2011-05-14 05:22 |
A possible fix is to condense the output by omitting stuff in the center rather than as the end: "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx...x\nx\nx\nx\nx\nx\nx\nx\nx\nx\n" "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx...x\nx\nx\nx\nx\nx\nx\nx\nx\nx\r\n" would be clear. |
|
|
msg136007 - (view) |
Author: Gregory P. Smith (gregory.p.smith) *  |
Date: 2011-05-15 04:39 |
We should ensure that the first differing character in the string is always included in what is displayed as a diff. if we're going to shorten a string we should elide something that matches. |
|
|
msg136079 - (view) |
Author: Michael Foord (michael.foord) *  |
Date: 2011-05-16 11:52 |
Yep, ensuring the truncated repr includes at least the *first* difference sounds like the right approach. |
|
|
msg139190 - (view) |
Author: mouad (mouad) * |
Date: 2011-06-26 15:25 |
I took on consideration the two suggestion that was in the issue and create this patch that basically show only until the last character that differ and truncate the rest. I just included one test case, other test case if they should be included (and if my solution got accepted :)), should be more *complex* and check using Regex the correctness of the assertion message, but here is the output that we can see when applying the patch: >>> tc.assertEqual("x\n" * 40 + "\n", "x\n" * 40 + "\r\n") 'x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n...nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n\n [truncated]... != 'x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n...\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n\r [truncated]... x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x - + >>> tc.assertEqual('aaaa', 'abbb') AssertionError: 'aa [truncated]... != 'ab [truncated]... - aaaa + abbb >>> tc.assertEqual('aaaa', 'bbbb') AssertionError: 'a [truncated]... != 'b [truncated]... - aaaa + bbbb >>> tc.assertEqual("x\n" * 80 + "\n", "x\n" * 80 + "\r") AssertionError: 'x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n...nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n\n [truncated]... != 'x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n...nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n\r [truncated]... |
|
|
msg408160 - (view) |
Author: Irit Katriel (iritkatriel) *  |
Date: 2021-12-09 21:45 |
Reproduced on 3.11. |
|
|