STINNER Victor <victor.stin...@haypocalc.com> added the comment: > The downside of using backslashreplace (or repr, for that matter) is > that it does not preserve lengths, so the diff markers can get > misaligned. I find that an acceptable tradeoff, but 'replace' is > another option that preserves lengths, at least more often.
'replace' loose important informations: if the test is about the unicode string content, we will be unable to see the error data. Result of the first example with my patch (backslashreplace): ====================================================================== FAIL: test_fffd (__main__.Foo) ---------------------------------------------------------------------- Traceback (most recent call last): File "x.py", line 3, in test_fffd def test_fffd(self): self.assertEqual(u'\ufffd', u'\ufffd\ufffd') AssertionError: - \ufffd+ \ufffd\ufffd Result of the first example with 'replace' error handler: ====================================================================== FAIL: test_fffd (__main__.Foo) ---------------------------------------------------------------------- Traceback (most recent call last): File "x.py", line 3, in test_fffd def test_fffd(self): self.assertEqual(u'\ufffd', u'\ufffd\ufffd') AssertionError: - ?+ ?? (but this example is irrevelant because U+FFFD is the unicode replacement character :-D) If nobody complains about my patch, I will commit it to Python trunk (only). You can still reimplement fail() method to encode the message using a more revelant encoding and/or error handler. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue8313> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com