[Zope3-dev] Re: doctest prb again

Marius Gedminas mgedmin at b4net.lt
Fri Jul 20 12:11:12 EDT 2007


On Fri, Jul 20, 2007 at 11:30:08AM +0200, Philipp von Weitershausen wrote:
> Adam Groszer wrote:
> >Great, that works ;-)
> >Thought that there is some more genreic-sane way.
> 
> There is. NORMALIZE_WHITESPACE actually only helps when whatever you're 
> outputting actually prints whitespace. Doing this::
> 
>   >>> '   '
>   '   '
> 
> won't invoke the whitespace normalizer.

I'm pretty certain you're mistaken here:

    >>> import doctest
    >>> def test1():
    ...     """
    ...         >>> '   ' # doctest: +NORMALIZE_WHITESPACE
    ...         ' '
    ...     """
    ... 
    >>> doctest.testmod()
    (0, 1)

The test passes.  What wouldn't work, though, is if you tried to match
whitespace that is not expressed as whitespace in your test, e.g. tabs:

    >>> def test2():
    ...     r"""
    ...         >>> '\t\t ' # doctest: +NORMALIZE_WHITESPACE
    ...         '\t'
    ...     """
    ... 
    >>> doctest.testmod()
    **********************************************************************
    File "/home/mg/.python", line 25, in __main__.test2
    Failed example:
        '\t\t' # doctest: +NORMALIZE_WHITESPACE
    Expected:
        '\t'
    Got:
        '\t\t'
    **********************************************************************
    1 items had failures:
       1 of   1 in __main__.test2
    ***Test Failed*** 1 failures.
    *** DocTestRunner.merge: '__main__.test1' in both testers; summing outcomes.
    *** DocTestRunner.merge: '__main__' in both testers; summing outcomes.
    (1, 2)

Marius Gedminas
-- 
America and England are two countries separated by a common language.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope3-dev/attachments/20070720/a2e5dde9/attachment.bin


More information about the Zope3-dev mailing list