Posts

Showing posts with the label ipython

ipython and doc tests. Cutting and pasting doctests into your shell.

Doc tests are a kind of literate programming for python. Where you type tests like you're typing stuff into an interpreter. In fact, it's easy to just type stuff into the interpreter and once you've finished playing around, copy the results from your terminal into a test file. This is a great, fairly low effort way of writing tests. However, what if you have written them in your source code file, and not in the interpreter? Ok, so you've written some doc tests and you want to paste doc tests into your interpreter ? With the normal python interpreter you can't paste doc tests in(I don't think). However the advanced ipython interpreter can. It has a special mode from writing doc tests. The command is called '%doctest_mode'. The %doctest_mode command allows you to paste in doc tests, into the interpreter... and have them run. The normal python shell fails at this, as the '>>>' is not valid python syntax. The ipython ignores the ...