This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients amaury.forgeotdarc, ezio.melotti, gthb, michael.foord, vstinner
Date 2010-05-05.00:32:20
SpamBayes Score 5.12496e-08
Marked as misclassified No
Message-id <1273019544.11.0.438727249101.issue8313@psf.upfronthosting.co.za>
In-reply-to
Content
> 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.
History
Date User Action Args
2010-05-05 00:32:24vstinnersetrecipients: + vstinner, amaury.forgeotdarc, ezio.melotti, michael.foord, gthb
2010-05-05 00:32:24vstinnersetmessageid: <1273019544.11.0.438727249101.issue8313@psf.upfronthosting.co.za>
2010-05-05 00:32:21vstinnerlinkissue8313 messages
2010-05-05 00:32:20vstinnercreate