[SciPy-Dev] examples for scipy

Jonathan Guyer guyer@nist....
Thu Jan 5 08:19:48 CST 2012

On Jan 5, 2012, at 12:14 AM, <josef.pktd@gmail.com> <josef.pktd@gmail.com> wrote:

> A caveat is that for example in statsmodels we haven't found a way to
> automatically test the examples and make sure they are always up to
> date, but that might be less of a problem for scipy.

In FiPy, we write all of our examples as doctests and they are integrated into our automatic test suite (see http://matforge.org/fipy/browser/trunk/examples). Basically we write any given example.py as a long docstring with prose, math and doctests and then end them with what amounts to (a little messier than this due to trying to still support Python 2.4):

if __name__ == '__main__':
    exec(doctest.testsource(sys.modules.get(__name__), ""))

so that they can be run directly.

As tests, we build up our test suite with a bunch of DocTestSuites (mostly in http://matforge.org/fipy/browser/trunk/fipy/tests/doctestPlus.py). Our overall mechanism is complicated by the fact that if some optional package is not installed, we got early and pervasive failures in our test suite simply because some example tried to import that package, when all we wanted was a runtime failure on the actual example that had that dependency. (I don't honestly remember the specifics, as I wrote that stuff years ago and, of course, didn't document any of it).

Anyway, you're welcome to swipe any of what we have if you find it useful.

More information about the SciPy-Dev mailing list