[SciPy-dev] Using doctest
David M. Cooke
cookedm at physics.mcmaster.ca
Sun Oct 30 17:37:59 EST 2005
On Oct 30, 2005, at 11:14, Travis Oliphant wrote:
>> 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?
>>
>>
>>
>
> newcore should be installable, but there can be a few functions that
> require other scipy packages. This is the appropriate way to
> handle it,
> I think.
>
> The test for deconvolve should be moved over to scipy.signal or
> else an
> appropriate try block used.
It's not the test for deconvolve (didn't add one). It's the test for
polynomial division. I'll have a look at not using deconvolve for
division.
I've changed deconvolve so it just does import scipy.signal, and
doesn't try to catch the ImportError. This is less confusing in terms
of error messages, at least.
--
|>|\/|<
/------------------------------------------------------------------\
|David M. Cooke http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca
More information about the SciPy-Dev
mailing list