[Python-Dev] doctest, unicode repr, and 2to3

Nick Coghlan ncoghlan at gmail.com
Fri Mar 5 10:29:28 CET 2010


Glyph Lefkowitz wrote:
> 
> On Mar 4, 2010, at 11:30 PM, Barry Warsaw wrote:
> 
>> If you really want to test that it's a unicode, shouldn't you actually
>> test
>> its type?  (I'm not sure what would happen with that under 2to3.)
> 
> Presumably 2to3 will be smart enough to translate 'unicode' to 'str' and
> 'bytes' to... 'bytes'.  Just don't use 'str' in 2.x and you should be
> okay :).

In code (including doctest input lines) 2to3 can make those
translations, but I believe the doctest output lines are a different
story (since they're just arbitrary strings as far as the translator is
concerned).

I would expect 2to3 to be able to translate the following tests
correctly because the expected output stays the same even though the
commands change:
>>> print a6.headline
'Default headline'
>>> type(a6.headline) is type(u'')
True

But I don't see a ready way to support doctests where the expected
*output* changes between versions.

Cheers,
Nick.
-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------


More information about the Python-Dev mailing list