classification
Title: Unicode returns in doctest can make subsequent tests fail
Type: behavior Stage:
Components: Extension Modules, Tests Versions: Python 2.7, Python 2.6, Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, lregebro
Priority: normal Keywords: patch

Created on 2010-04-20 15:41 by lregebro, last changed 2010-08-01 08:22 by georg.brandl. This issue is now closed.

Files
File name Uploaded Description Edit
doctest_unicode.patch lregebro, 2010-04-20 15:41
Messages (2)
msg103728 - (view) Author: Lennart Regebro (lregebro) Date: 2010-04-20 15:41
If we return unicode, SpoofOut's buf variable becomes automagically converted to unicode. This means all subsequent output becomes converted to unicode, and if the output contains non-ascii characters that fails.

That means that 

    >>> print u'\xe9'.encode('utf-8')
    é

Will work just fine, but

    >>> print u'abc'
    abc

    >>> print u'\xe9'.encode('utf-8')
    é

Will fail.

    
The reason for this is that when "resetting" the doctest output only a truncate(0) is done, so the buf variable will continue to be unicode. I include tests + a patch that will set self.buf to '' if empty when trunkated. Other options are also possible, like changing the .truncate(0) to a .buf = '' but that's ugly, or adding a reset() method on SpoofOUt.
msg112288 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-08-01 08:22
Thanks, applied in r83392.
History
Date User Action Args
2010-08-01 08:22:32georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg112288

resolution: accepted
2010-04-20 15:41:12lregebrocreate