André wrote:

> Now, I want to be able to test the code using the doctest module.
> 
> I can't use exec as doctest.testmod() will be testing my entire
> application, not simply the code in the input window!

> While this works, I find it "messy", as it creates some intermediate
> files.  I was wondering if there was a better way to do things all in
> memory, in an OS independent way.

Here's a manual setup you might be able to adapt:

import doctest
from cStringIO import StringIO

sample = """
>>> print "hello"
hello
>>> "hello"
'hello'
"""

globs = {}
out = StringIO()
parser = doctest.DocTestParser()
test = parser.get_doctest(sample, globs, "<noname>", "<nofile>", 0)
runner = doctest.DocTestRunner(verbose=True)
runner.run(test, out=out.write)
print out.getvalue()
 
Peter
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to