Leo and Doctests

I have a Leo file with the node @file minimal.txt which consists of:

>>> import sys
>>> print 1+1
2
>>> print 1+1
1

If I do:

import doctest
doctest.testfile(u'minimal.txt')

I get the expected result

If, however, I do:

import doctest
doctest.testfile(u'minimal.leo')

the tests don't run, because minimal.leo looks like:

...
<tnodes>
<t tx="ktenney.20060330105933">&gt;&gt;&gt; import sys
&gt;&gt;&gt; print 1+1
2
&gt;&gt;&gt; print 1+1
1

</t>

the >>> prompt is escaped, and import sys shares a line with the <t ...> tag

I edited minimal.leo to look like:

<tnodes>
    <t tx="ktenney.20060330105933">
>>> import sys
>>> print 1+1
2
>>> print 1+1
1

</t>

and it still opens, plus it is a valid doctest document

of course when saved, >>> is once again &gt;&gt;&gt;

The potential benefits of Leo files being valid for doctesting is enormous. There is a lot of momentum behind the idiom of putting edge case doctests in method docstrings, and creating .txt files which document usage, mixing doctests and prose.

One of Leo's strengths is aggregating files. It would be very attractive to many developers if they could manage their code, doc and tests from a Leo file.

The less Leo-specific Leo is the better. If '>>>' wasn't escaped, the Leo file would provide the same expected testing capability that the .txt and .py files currently do.

Use a simple wrapper to fix? --btheado, Sat, 01 Apr 2006 06:53:02 -0800 reply

How easy would it be to add a wrapper around doctest.testfile that translates '&gt;&gt;&gt' into >>> and then passes the result to doctest.testfile?

.leo files must be xml files --edreamleo, Sun, 02 Apr 2006 16:14:14 -0700 reply

As I said in the SF forum, it is invalid not to escape '>' in .leo files: that would not make the .leo file a valid xml file. Brian Theado's solution is the only way.