Re: doctests compatibility for python 2 & python 3

2014-01-20 Thread Robin Becker
On 17/01/2014 21:10, Terry Reedy wrote: On 1/17/2014 7:14 AM, Robin Becker wrote: .. I never got how you are using doctests. There were certainly not meant for heavy-duty unit testing, but for testing combined with explanation. Section 26.2.3.7. (in 3.3) Warnings warns that they are fr

Re: doctests compatibility for python 2 & python 3

2014-01-18 Thread Albert-Jan Roskam
On Fri, 1/17/14, Terry Reedy wrote: Subject: Re: doctests compatibility for python 2 & python 3 To: python-list@python.org Date: Friday, January 17, 2014, 10:10 PM On 1/17/2014 7:14 AM, Robin Becker wrote: > I tried this approach wit

Re: doctests compatibility for python 2 & python 3

2014-01-17 Thread Terry Reedy
On 1/17/2014 7:14 AM, Robin Becker wrote: I tried this approach with a few more complicated outcomes and they fail in python2 or 3 depending on how I try to render the result in the doctest. I never got how you are using doctests. There were certainly not meant for heavy-duty unit testing, bu

Re: doctests compatibility for python 2 & python 3

2014-01-17 Thread Robin Becker
On 17/01/2014 15:27, Steven D'Aprano wrote: .. # -*- coding: utf-8 -*- def func(a): """ >>> print(func(u'aaa\u020b')) aaaȋ """ return a There seems to be some mojibake in your post, which confuses issues. You refer to \u020b, which is LATIN SMALL LETTER

Re: doctests compatibility for python 2 & python 3

2014-01-17 Thread Steven D'Aprano
On Fri, 17 Jan 2014 12:12:35 +, Robin Becker wrote: > On 17/01/2014 11:41, Steven D'Aprano wrote: >> def func(a): >> """ >> >>> print(func(u'aaa')) >> aaa >> """ >> return a > > I think this approach seems to work if I turn the docstring into unicode > > def func(a):

Re: doctests compatibility for python 2 & python 3

2014-01-17 Thread Robin Becker
On 17/01/2014 11:30, Chris Angelico wrote: On Fri, Jan 17, 2014 at 10:24 PM, Chris Angelico wrote: Do your test strings contain any non-ASCII characters? If not, you might be able to do this: def func(a): """ >>> str(func(u'aaa')) 'aaa' """ return a Actually, probabl

Re: doctests compatibility for python 2 & python 3

2014-01-17 Thread Robin Becker
On 17/01/2014 11:41, Steven D'Aprano wrote: def func(a): """ >>> print(func(u'aaa')) aaa """ return a I think this approach seems to work if I turn the docstring into unicode def func(a): u""" >>> print(func(u'aaa\u020b')) aaa\u020b """

Re: doctests compatibility for python 2 & python 3

2014-01-17 Thread Steven D'Aprano
On Fri, 17 Jan 2014 11:16:17 +, Robin Becker wrote: > I have some problems making some doctests for python2 code compatible > with python3. The problem is that as part of our approach we are > converting the code to use unicode internally. So we allow eihter byte > strings or unicode in inputs

Re: doctests compatibility for python 2 & python 3

2014-01-17 Thread Chris Angelico
On Fri, Jan 17, 2014 at 10:24 PM, Chris Angelico wrote: > Do your test strings contain any non-ASCII characters? If not, you > might be able to do this: > > def func(a): > """ > >>> str(func(u'aaa')) > 'aaa' > """ > return a Actually, probably better than that: def func(a):

Re: doctests compatibility for python 2 & python 3

2014-01-17 Thread Chris Angelico
On Fri, Jan 17, 2014 at 10:16 PM, Robin Becker wrote: > Aside from changing the tests so they look like > """ > >>> func(u'aaa')==u'aaa' > True > """ Do your test strings contain any non-ASCII characters? If not, you might be able to do this: def func(a): """ >>> str(func