[Numpy-discussion] Doctest items

Fernando Perez fperez.net@gmail....
Tue Jul 1 17:50:27 CDT 2008


On Tue, Jul 1, 2008 at 1:41 PM, Pauli Virtanen <pav@iki.fi> wrote:

> But it's a custom tweak to doctest, so it might break at some point in
> the future, and I don't love the monkeypatching here...

Welcome to the joys of extending doctest/unittest.  They hardcoded so
much stuff in there that the only way to reuse that code is by
copy/paste/monkeypatch.  It's absolutely atrocious.

>> We could always just make the plotting section one of those "it's just
>> an example not a doctest" things and remove the ">>>" (since it doesn't
>> appear to provide any useful test coverage or anything).
>
> If possible, I'd like other possibilities be considered first before
> jumping this route. I think it would be nice to retain the ability to run
> also the matplotlib examples as (optional) doctests, to make sure also
> they execute correctly. Also, using two different markups in the
> documentation to work around a shortcoming of doctest is IMHO not very
> elegant.

How about a much simpler approach?  Just pre-populate the globals dict
where doctest executes with an object called 'plt' that basically does

def noop(*a,**k): pass

class dummy():
  def __getattr__(self,k): return noop

plt = dummy()

This would ensure that all calls to plt.anything() silently succeed in
the doctests.  Granted, we're not testing matplotlib, but it has the
benefit of simplicity and of letting us keep consistent formatting,
and examples that *users* can still paste into their sessions where
plt refers to the real matplotlib.

Just an idea...

f


More information about the Numpy-discussion mailing list