[SciPy-dev] tests for scipy.integrate
Arnd Baecker
arnd.baecker at web.de
Wed Nov 16 14:02:25 CST 2005
On Wed, 16 Nov 2005, Nils Wagner wrote:
[...]
> I am not familiar with writing tests. However I have attached a small
> example,
Hi Nils,
I also have no experience in writing unittests, but it
seems pretty straightforward.
For example looking at scipy/Lib/linalg/tests/test_basic.py
suggests that one has to
a) create a subdirectory called `tests`
b) add a test file `test_<something>.py`, e.g. `test_simple.py`
which contains
#################################################
import scipy.base as Numeric
from scipy.base import arange, add, array, dot, zeros, identity
import sys
from scipy.test.testing import *
set_package_path()
# adapt the following ones accordingly:
from linalg import solve,inv,det,lstsq, toeplitz, hankel, tri, triu, tril
from linalg import pinv, pinv2, solve_banded
restore_path()
import unittest
class test_routine1(ScipyTestCase):
""" Collection of tests for routine1"""
def check_trivial(self):
"""do some test giving a scalar"""
result=
known_result=
assert_almost_equal(result,known_result)
def check_simple(self):
"""do some test giving an array"""
result=
known_result=
assert_array_almost_equal(result,known_result)
class test_routine2(ScipyTestCase):
""" Collection of tests for routine2"""
def check_trivial(self):
"""do some test giving a scalar"""
result=
known_result=
assert_almost_equal(result,known_result)
def check_simple(self):
"""do some test giving an array"""
result=
known_result=
assert_array_almost_equal(result,known_result)
def check_extensive(self,level=10):
"""do some more heavy test giving an array"""
result=
known_result=
assert_array_almost_equal(result,known_result)
if __name__ == "__main__":
ScipyTest().run()
####################
Note that the above is untested - good luck ;-)
For other assert_xxx see scipy.test.testing.
Best, Arnd
More information about the Scipy-dev
mailing list