Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64352

Re: doctests compatibility for python 2 & python 3

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'warnings': 0.04; 'indicating': 0.07; 'reject': 0.07; 'string': 0.09; 'ascii': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:skip:c 10': 0.09; 'testing,': 0.09; 'python': 0.11; 'def': 0.12; 'changes': 0.15; "%s'": 0.16; 'doctests': 0.16; 'outcomes': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'meant': 0.20; 'import': 0.22; '(in': 0.22; 'tests': 0.22; 'header:User- Agent:1': 0.23; 'certainly': 0.24; 'char': 0.24; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'testing': 0.29; 'am,': 0.29; 'skip:( 20': 0.30; 'code': 0.31; 'equality': 0.31; 'option.': 0.31; 'search.': 0.31; 'file': 0.32; 'but': 0.35; 'there': 0.35; 'unit': 0.37; 'expected': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'future': 0.60; 'skip:a 30': 0.61; 'course': 0.61; 'our': 0.64; 'different': 0.65; 'subject: & ': 0.68; 'received:109': 0.72; 'discovered': 0.83; "'true'": 0.84; 'observed': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Robin Becker <robin@reportlab.com>
Subject Re: doctests compatibility for python 2 & python 3
Date Mon, 20 Jan 2014 10:07:35 +0000
References <52D91101.7000202@chamonix.reportlab.co.uk> <CAPTjJmqhr9V42ncZHKKGnE=N8KuUmV2t6M3eNYfZzkPNTYQF9A@mail.gmail.com> <CAPTjJmo6XqfZL5xYB-2pyhv+fsmB-faPrLK3y8-dcqRQFEyC9A@mail.gmail.com> <52D91EBB.2060606@chamonix.reportlab.co.uk> <lbc68l$atj$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 109.174.168.73
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
In-Reply-To <lbc68l$atj$1@ger.gmane.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5743.1390212469.18130.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1390212469 news.xs4all.nl 2955 [2001:888:2000:d::a6]:37387
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64352

Show key headers only | View raw


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 fragile to even single char
> changes and suggests == as a workaround, as 'True' and 'False' will not change.
> So I would not reject that option.
>
I have used some 'robust' True/False equality tests and also tests which return 
None or a string indicating the expected and observed outcomes eg

>
> def equalStrings(a,b,enc='utf8'):
> 	return a==b if type(a)==type(b) else asUnicode(a,enc)==asUnicode(b,enc)
>
> def eqCheck(r,x):
> 	if r!=x:
> 		print('Strings unequal\nexp: %s\ngot: %s' % (ascii(x),ascii(r)))

of course I needed to import ascii from the future and the asUnicode function 
has to be different for python 3 and 2.

Some of our code used doctests which are discovered by a file search.
-- 
Robin Becker

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: doctests compatibility for python 2 & python 3 Robin Becker <robin@reportlab.com> - 2014-01-20 10:07 +0000

csiph-web