[Zope3-dev] Re: help with doctests

Jim Fulton jim at zope.com
Fri Jul 20 07:57:12 EDT 2007


On Jul 20, 2007, at 5:27 AM, Philipp von Weitershausen wrote:

> Marius Gedminas wrote:
>> doctests have special rules for exceptions that are different from  
>> the
>> rules of normal output matching.
>> If a statement raises an exception, the output part must be of the  
>> form
>>   Traceback (most recent call last):
>>     ...
>>   <exception type>: <exception value>
>> You can use ellipsis in the exception value part, IIRC.
>
> But I wouldn't recommend using them. Sometimes, using ellipses are  
> fine, but generally they obfuscate the doctest when you're reading  
> it. I suggesting using the regex-normalizer [1]. There are many  
> packages out there that use it if you're looking for examples.
>
>
> http://svn.zope.org/zope.testing/trunk/src/zope/testing/ 
> renormalizing.py?rev=66267&view=auto

BTW, a small useful easy project that I don't have time for would be  
to generalize the renormalizer to allow other objects besides regexes.

You now give this a sequences of regex/replacement pairs.

It would be nice to allow callables in addition to regexs.   
Basically, allow items in the sequence to be either:

- a regex+replacement tuple, or

- a callable transformer that reads the text and returns new text.

While regexs and replacements are very powerful, there've been times  
when I wanted the full generality of Python.  I ended up subclassing  
the renormalizer in these cases, but would have preferred not to have  
had to do so.

Jim

--
Jim Fulton			mailto:jim at zope.com		Python Powered!
CTO 				(540) 361-1714			http://www.python.org
Zope Corporation	http://www.zope.com		http://www.zope.org





More information about the Zope3-dev mailing list