[IPython-User] Doctest checker in IPython notebook

Brian Granger ellisonbg@gmail....
Thu Oct 11 22:18:48 CDT 2012

Just thinking out loud...

It might be nice to have a button that will cause a single cell to be
doctested.  That button could grab the Python code of the cell and
then wrap that code in the needed calls to doctest it and produce the
HTML output.

code_string -> doctest_to_html(code_string) would get sent to kernel

The output of that cell would then be send back and you could see the
doctest results for that cell.  I think the main part of this would be
to write the doctest_to_html function that doctests the code string in
the ipython namespace.  I don't know anything about the doctest
internals, but this should not be difficult.

This mode has the advantage that you can doctest any code without
additional calls like test(foo).  But it also mixes the doctest
results with the actual notebook code.  There are other ways we could
do the UI once we have the doctest_to_html function.



On Thu, Oct 11, 2012 at 12:40 PM, Catherine Devlin
<catherine.devlin@gmail.com> wrote:
> On Thu, Oct 11, 2012 at 12:40 PM, Brian Granger <ellisonbg@gmail.com> wrote:
>> Catherine,
>> Hi, this looks really great!  We would love to work with you to make
>> this an actual IPython library or extension.  If you are interested in
>> working with us, let's use this thread to discuss where you see this
>> heading and the best way to incorporate it into the project.  Of
>> course, feel free to continue to work on this on your own as well.
> Wow, thanks!  Sure!  I mean, I didn't really contribute much beyond
> the concept - the implementation is really primitive (ripping apart
> doctest's printed output and parsing its strings).  If it were going
> to become a real part of IPython, it should probably be a little more
> sophisticated - maybe creating a custom "out" function to pass to
> ``DocTestRunner.run`` so it wouldn't be so fragile, and so it could
> accept some arguments/flags.  Or something like that.  This is my
> first time looking inside doctest.py and I'm just trying to sound
> smart.  :)
> I'd also be interested in ideas about how it can look more
> seamless/transparent to use - can the notebook somehow be set up to
> automatically try to run it against all class and function definitions
> found in any of its cells?  Then again, maybe it shouldn't be too
> transparent - maybe it's good to let students see a little of testing
> in action and that testing is awesome but not magic (though it could
> be %magic).
> --
> - Catherine
> http://catherinedevlin.blogspot.com

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

More information about the IPython-User mailing list