doctest bug?

Edward K. Ream edreamleo at charter.net
Mon Jul 19 12:24:00 EDT 2004


Hi,

I am trying to run the following docstring using docutils.DocTestSuite:

"""
>>> s = "a\n \t\n\t\t \t\nb"
etc...
"""

However, docutils complains about "inconsistent leading whitespace".  Well,
that's not the problem.

I inserted traces in various places in Lib/Python23/doctest.py.  This is
what I found:

1.  Tester._get_doctest returns  __doc__, and in this case repr(__doc__) is:

'        >>> s = "a\n \t\n\t\t \t\nb"\n        etc...'

So you can see the problem: all newlines (all the '\n' characters) are equal
here, whether or not they are inside strings!

Note:  this came from a an actual dump: I hope it has survived the cut/paste
relatively intact.

2. Naturally, doctest._extract_examples(s) complains because it thinks the
lines in s are improperly indented.

Indeed, doctest._extract_examples contains the following code:

lines = s.split("\n")
i, n = 0, len(lines)
while i < n:
....line = lines[i]
....<< do something with line i >>

Printing "EKR:", repr(line) in this code yields:

EKR: '        >>> s = "a'
EKR: ' \t'
EKR: '\t\t \t'
EKR: 'b"'

This should make it perfectly clear what is happening and why
doctest._extract_examples complains about indentation.

Is this a bug?  If so, is there a workaround?  If this isn't a bug, why not?

I don't see anything in the doctest docs about this kind of problem.  Am I
doing something obviously wrong?

Thanks,

Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edreamleo at charter.net
Leo: Literate Editor with Outlines
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------





More information about the Python-list mailing list