[SciPy-dev] Using doctest

Arnd Baecker arnd.baecker at web.de
Sun Oct 30 02:05:17 CST 2005



On Sat, 29 Oct 2005, David M. Cooke wrote:

> I've added some tests for scipy.base.polynomial and
> scipy.base.ufunclike, but I used doctests instead of writing out
> something with unittest. They're run by using a test_suite(level)
> function in the appropriate test module.
>
> They were much easier to write than using the unittest API: copy-and-
> paste from my terminal window, mostly :-)
>
> I'm not familiar with the internals of scipy.test.testing, so I don't
> know if there's something I'm missing when setting them up. It does
> require Python 2.3 or higher to make a unittest test suite from the
> doctest, though.


One problem is that the doctests screw up when
ipython is used, e.g.:

ipython
import scipy
scipy.__core_version__
scipy.__core_config__.show()
scipy.test(10)

Giving many of this type.

*****************************************************************
Failure in example: p
from line #5 of scipy.base.polynomial.test_polynomial
Expected: poly1d([ 1.,  2.,  3.])
Got:
*****************************************************************
Failure in example: q
from line #11 of scipy.base.polynomial.test_polynomial
Expected: poly1d([ 3.,  2.,  1.])
Got:


Note that I use IPython 0.6.13 and I vaguely
remember that something like this
was discussed on the IPython mailing list some time ago.

Another point:
Running the tests of newcore from "normal" python gives:

[...]

======================================================================
ERROR: doctest of scipy.base.polynomial.test_polynomial
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.3/unittest.py", line 423, in runTest
    self.__testFunc()
  File "/usr/lib/python2.3/doctest.py", line 1359, in runit
    _utest(tester, name, doc, filename, lineno)
  File "/usr/lib/python2.3/doctest.py", line 1309, in _utest
    raise DocTestTestFailure('Failed doctest test for %s\n'
DocTestTestFailure: Failed doctest test for
scipy.base.polynomial.test_polynomial
  File
"/tmp/SCIPY3/INST/lib/python2.3/site-packages/scipy/base/tests/test_polynomial.py",
line 1 (or above), in test_polynomial

*****************************************************************
Failure in example: p / q
from line #28 of scipy.base.polynomial.test_polynomial
Exception raised:
Traceback (most recent call last):
  File "/usr/lib/python2.3/doctest.py", line 442, in _run_examples_inner
    compileflags, 1) in globs
  File "<string>", line 1, in ?
  File
"/tmp/SCIPY3/INST//lib/python2.3/site-packages/scipy/base/polynomial.py",
line 489, in __div__
    return map(poly1d, polydiv(self.coeffs, other.coeffs))
  File
"/tmp/SCIPY3/INST//lib/python2.3/site-packages/scipy/base/polynomial.py",
line 313, in polydiv
    q, r = deconvolve(a1, a2)
  File
"/tmp/SCIPY3/INST//lib/python2.3/site-packages/scipy/base/polynomial.py",
line 305, in deconvolve
    quot = scipy.signal.lfilter(num, den, input)
UnboundLocalError: local variable 'scipy' referenced before assignment


The reason is the use of scipy.signal in polynomial.py,

def deconvolve(signal, divisor):
    """Deconvolves divisor out of signal.  Requires scipy.signal library
    """
    try:
        import scipy.signal
    except ImportError:
        print "You need scipy.signal to use this function."
    [...]

This routine does not work if only newcore is installed.
If I understood things correctly, newcore should
be independent from newscipy, or?

Best, Arnd




More information about the Scipy-dev mailing list