[Scipy-svn] r3822 - in trunk/scipy: . cluster cluster/tests fftpack fftpack/tests integrate integrate/tests interpolate interpolate/tests io io/matlab/tests lib lib/blas lib/blas/tests lib/lapack lib/lapack/tests linalg linalg/tests linsolve linsolve/umfpack linsolve/umfpack/tests maxentropy maxentropy/tests misc misc/tests ndimage ndimage/segment/tests ndimage/tests odr odr/tests optimize optimize/tests sandbox/arpack/tests sandbox/buildgrid sandbox/cdavid sandbox/constants sandbox/delaunay/tests sandbox/dhuard sandbox/dhuard/tests sandbox/fdfpack/tests sandbox/lobpcg sandbox/lobpcg/tests sandbox/maskedarray sandbox/maskedarray/alternative_versions sandbox/montecarlo/tests sandbox/multigrid sandbox/multigrid/tests sandbox/numexpr sandbox/numexpr/tests sandbox/pyloess sandbox/pyloess/tests sandbox/rbf sandbox/rbf/tests sandbox/spline sandbox/spline/tests sandbox/timeseries sandbox/timeseries/lib sandbox/timeseries/lib/tests sandbox/timeseries/tests signal signal/tests sparse sparse/tests special special/tests stats stats/models stats/models/tests stats/tests testing weave weave/tests
scipy-svn@scip...
scipy-svn@scip...
Sat Jan 12 04:08:45 CST 2008
Author: matthew.brett@gmail.com
Date: 2008-01-12 04:06:39 -0600 (Sat, 12 Jan 2008)
New Revision: 3822
Added:
trunk/scipy/sandbox/dhuard/tests/
trunk/scipy/sandbox/dhuard/tests/test_histogram.py
trunk/scipy/sandbox/dhuard/tests/test_stats.py
Removed:
trunk/scipy/sandbox/dhuard/test_histogram.py
trunk/scipy/sandbox/dhuard/test_stats.py
trunk/scipy/tests/
Modified:
trunk/scipy/__init__.py
trunk/scipy/cluster/__init__.py
trunk/scipy/cluster/tests/test_vq.py
trunk/scipy/fftpack/__init__.py
trunk/scipy/fftpack/tests/test_basic.py
trunk/scipy/fftpack/tests/test_helper.py
trunk/scipy/fftpack/tests/test_pseudo_diffs.py
trunk/scipy/integrate/__init__.py
trunk/scipy/integrate/tests/test_integrate.py
trunk/scipy/integrate/tests/test_quadpack.py
trunk/scipy/integrate/tests/test_quadrature.py
trunk/scipy/interpolate/__init__.py
trunk/scipy/interpolate/tests/test_fitpack.py
trunk/scipy/interpolate/tests/test_interpolate.py
trunk/scipy/io/__init__.py
trunk/scipy/io/matlab/tests/test_mio.py
trunk/scipy/lib/__init__.py
trunk/scipy/lib/blas/__init__.py
trunk/scipy/lib/blas/tests/test_blas.py
trunk/scipy/lib/blas/tests/test_fblas.py
trunk/scipy/lib/lapack/__init__.py
trunk/scipy/lib/lapack/tests/esv_tests.py
trunk/scipy/lib/lapack/tests/gesv_tests.py
trunk/scipy/lib/lapack/tests/test_lapack.py
trunk/scipy/linalg/__init__.py
trunk/scipy/linalg/tests/test_atlas_version.py
trunk/scipy/linalg/tests/test_basic.py
trunk/scipy/linalg/tests/test_blas.py
trunk/scipy/linalg/tests/test_decomp.py
trunk/scipy/linalg/tests/test_fblas.py
trunk/scipy/linalg/tests/test_iterative.py
trunk/scipy/linalg/tests/test_lapack.py
trunk/scipy/linalg/tests/test_matfuncs.py
trunk/scipy/linsolve/__init__.py
trunk/scipy/linsolve/umfpack/__init__.py
trunk/scipy/linsolve/umfpack/tests/test_umfpack.py
trunk/scipy/maxentropy/__init__.py
trunk/scipy/maxentropy/tests/test_maxentropy.py
trunk/scipy/misc/__init__.py
trunk/scipy/misc/ppimport.py
trunk/scipy/misc/tests/test_pilutil.py
trunk/scipy/ndimage/__init__.py
trunk/scipy/ndimage/segment/tests/test_segment.py
trunk/scipy/ndimage/tests/test_ndimage.py
trunk/scipy/odr/__init__.py
trunk/scipy/odr/tests/test_odr.py
trunk/scipy/optimize/__init__.py
trunk/scipy/optimize/tests/test_cobyla.py
trunk/scipy/optimize/tests/test_nonlin.py
trunk/scipy/optimize/tests/test_optimize.py
trunk/scipy/optimize/tests/test_slsqp.py
trunk/scipy/optimize/tests/test_zeros.py
trunk/scipy/sandbox/arpack/tests/test_arpack.py
trunk/scipy/sandbox/arpack/tests/test_speigs.py
trunk/scipy/sandbox/buildgrid/test_build_grid.py
trunk/scipy/sandbox/cdavid/__init__.py
trunk/scipy/sandbox/cdavid/segmentaxis.py
trunk/scipy/sandbox/constants/constants.py
trunk/scipy/sandbox/delaunay/tests/test_triangulate.py
trunk/scipy/sandbox/fdfpack/tests/test_fdf.py
trunk/scipy/sandbox/lobpcg/__init__.py
trunk/scipy/sandbox/lobpcg/tests/large_scale.py
trunk/scipy/sandbox/lobpcg/tests/test_lobpcg.py
trunk/scipy/sandbox/maskedarray/alternative_versions/test_mrecarray.py
trunk/scipy/sandbox/maskedarray/testutils.py
trunk/scipy/sandbox/montecarlo/tests/test_dictsampler.py
trunk/scipy/sandbox/montecarlo/tests/test_intsampler.py
trunk/scipy/sandbox/multigrid/__init__.py
trunk/scipy/sandbox/multigrid/simple_test.py
trunk/scipy/sandbox/multigrid/tests/test_adaptive.py
trunk/scipy/sandbox/multigrid/tests/test_relaxation.py
trunk/scipy/sandbox/multigrid/tests/test_sa.py
trunk/scipy/sandbox/multigrid/tests/test_utils.py
trunk/scipy/sandbox/numexpr/__init__.py
trunk/scipy/sandbox/numexpr/compiler.py
trunk/scipy/sandbox/numexpr/expressions.py
trunk/scipy/sandbox/numexpr/tests/test_numexpr.py
trunk/scipy/sandbox/pyloess/mpyloess.py
trunk/scipy/sandbox/pyloess/tests/test_mpyloess.py
trunk/scipy/sandbox/pyloess/tests/test_pyloess.py
trunk/scipy/sandbox/rbf/__init__.py
trunk/scipy/sandbox/rbf/tests/test_rbf.py
trunk/scipy/sandbox/spline/__init__.py
trunk/scipy/sandbox/spline/tests/test_fitpack.py
trunk/scipy/sandbox/spline/tests/test_spline.py
trunk/scipy/sandbox/timeseries/dates.py
trunk/scipy/sandbox/timeseries/extras.py
trunk/scipy/sandbox/timeseries/lib/filters.py
trunk/scipy/sandbox/timeseries/lib/interpolate.py
trunk/scipy/sandbox/timeseries/lib/moving_funcs.py
trunk/scipy/sandbox/timeseries/lib/tests/test_interpolate.py
trunk/scipy/sandbox/timeseries/lib/tests/test_moving_funcs.py
trunk/scipy/sandbox/timeseries/report.py
trunk/scipy/sandbox/timeseries/tests/test_dates.py
trunk/scipy/sandbox/timeseries/tests/test_extras.py
trunk/scipy/sandbox/timeseries/tests/test_timeseries.py
trunk/scipy/sandbox/timeseries/tests/test_trecords.py
trunk/scipy/sandbox/timeseries/trecords.py
trunk/scipy/sandbox/timeseries/tseries.py
trunk/scipy/setup.py
trunk/scipy/signal/__init__.py
trunk/scipy/signal/tests/test_signaltools.py
trunk/scipy/signal/tests/test_wavelets.py
trunk/scipy/sparse/__init__.py
trunk/scipy/sparse/tests/test_base.py
trunk/scipy/sparse/tests/test_construct.py
trunk/scipy/sparse/tests/test_sparse.py
trunk/scipy/sparse/tests/test_spfuncs.py
trunk/scipy/sparse/tests/test_sputils.py
trunk/scipy/special/__init__.py
trunk/scipy/special/tests/test_basic.py
trunk/scipy/special/tests/test_spfun_stats.py
trunk/scipy/stats/__init__.py
trunk/scipy/stats/models/__init__.py
trunk/scipy/stats/models/tests/test_bspline.py
trunk/scipy/stats/models/tests/test_formula.py
trunk/scipy/stats/models/tests/test_glm.py
trunk/scipy/stats/models/tests/test_regression.py
trunk/scipy/stats/models/tests/test_rlm.py
trunk/scipy/stats/models/tests/test_scale.py
trunk/scipy/stats/models/tests/test_utils.py
trunk/scipy/stats/morestats.py
trunk/scipy/stats/tests/test_distributions.py
trunk/scipy/stats/tests/test_morestats.py
trunk/scipy/stats/tests/test_stats.py
trunk/scipy/testing/nosetester.py
trunk/scipy/weave/__init__.py
trunk/scipy/weave/c_spec.py
trunk/scipy/weave/size_check.py
trunk/scipy/weave/tests/test_ast_tools.py
trunk/scipy/weave/tests/test_blitz_tools.py
trunk/scipy/weave/tests/test_build_tools.py
trunk/scipy/weave/tests/test_c_spec.py
trunk/scipy/weave/tests/test_catalog.py
trunk/scipy/weave/tests/test_ext_tools.py
trunk/scipy/weave/tests/test_inline_tools.py
trunk/scipy/weave/tests/test_numpy_scalar_spec.py
trunk/scipy/weave/tests/test_scxx.py
trunk/scipy/weave/tests/test_scxx_dict.py
trunk/scipy/weave/tests/test_scxx_object.py
trunk/scipy/weave/tests/test_scxx_sequence.py
trunk/scipy/weave/tests/test_size_check.py
trunk/scipy/weave/tests/test_slice_handler.py
trunk/scipy/weave/tests/test_standard_array_spec.py
trunk/scipy/weave/tests/test_wx_spec.py
trunk/scipy/weave/tests/weave_test_utils.py
Log:
Full changeset to implement nose testing
Modified: trunk/scipy/__init__.py
===================================================================
--- trunk/scipy/__init__.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/__init__.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -62,14 +62,9 @@
"""
__doc__ += pkgload.get_pkgdocs()
+from testing.pkgtester import Tester
+test = Tester().test
-def test(level=1, verbosity=1):
- """ Run Scipy tests suite with level and verbosity."""
- from numpy.testing import NumpyTest
- import scipy
- scipy.pkgload()
- return NumpyTest(scipy).test(level, verbosity)
-
__doc__ += """
Utility tools
Modified: trunk/scipy/cluster/__init__.py
===================================================================
--- trunk/scipy/cluster/__init__.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/cluster/__init__.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -7,5 +7,5 @@
__all__ = ['vq']
import vq
-from numpy.testing import NumpyTest
-test = NumpyTest().test
+from scipy.testing.pkgtester import Tester
+test = Tester().test
Modified: trunk/scipy/cluster/tests/test_vq.py
===================================================================
--- trunk/scipy/cluster/tests/test_vq.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/cluster/tests/test_vq.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -7,26 +7,22 @@
# kmeans works OK for trivial examples.
import sys
-from numpy.testing import *
+import os.path
+from scipy.testing import *
import numpy as N
-set_package_path()
-from cluster.vq import kmeans, kmeans2, py_vq, py_vq2, _py_vq_1d, vq, ClusterError
+from scipy.cluster.vq import kmeans, kmeans2, py_vq, py_vq2, _py_vq_1d, vq, ClusterError
try:
- from cluster import _vq
+ from scipy.cluster import _vq
TESTC=True
except ImportError:
print "== Error while importing _vq, not testing C imp of vq =="
TESTC=False
-restore_path()
-import os.path
#Optional:
-set_local_path()
# import modules that are located in the same directory as this file.
-DATAFILE1 = os.path.join(sys.path[0], "data.txt")
-restore_path()
+DATAFILE1 = os.path.join(os.path.dirname(__file__), "data.txt")
# Global data
X = N.array([[3.0, 3], [4, 3], [4, 2],
@@ -43,20 +39,20 @@
LABEL1 = N.array([0, 1, 2, 2, 2, 2, 1, 2, 1, 1, 1])
-class TestVq(NumpyTestCase):
- def check_py_vq(self, level=1):
+class TestVq(TestCase):
+ def test_py_vq(self):
initc = N.concatenate(([[X[0]], [X[1]], [X[2]]]))
code = initc.copy()
label1 = py_vq(X, initc)[0]
assert_array_equal(label1, LABEL1)
- def check_py_vq2(self, level=1):
+ def test_py_vq2(self):
initc = N.concatenate(([[X[0]], [X[1]], [X[2]]]))
code = initc.copy()
label1 = py_vq2(X, initc)[0]
assert_array_equal(label1, LABEL1)
- def check_vq(self, level=1):
+ def test_vq(self):
initc = N.concatenate(([[X[0]], [X[1]], [X[2]]]))
code = initc.copy()
if TESTC:
@@ -66,7 +62,7 @@
else:
print "== not testing C imp of vq =="
- #def check_py_vq_1d(self, level=1):
+ #def test_py_vq_1d(self):
# """Test special rank 1 vq algo, python implementation."""
# data = X[:, 0]
# initc = data[:3]
@@ -76,7 +72,7 @@
# assert_array_equal(a, ta)
# assert_array_equal(b, tb)
- def check_vq_1d(self, level=1):
+ def test_vq_1d(self):
"""Test special rank 1 vq algo, python implementation."""
data = X[:, 0]
initc = data[:3]
@@ -89,15 +85,15 @@
else:
print "== not testing C imp of vq (rank 1) =="
-class TestKMean(NumpyTestCase):
- def check_kmeans_simple(self, level=1):
+class TestKMean(TestCase):
+ def test_kmeans_simple(self):
initc = N.concatenate(([[X[0]], [X[1]], [X[2]]]))
code = initc.copy()
code1 = kmeans(X, code, iter = 1)[0]
assert_array_almost_equal(code1, CODET2)
- def check_kmeans_lost_cluster(self, level=1):
+ def test_kmeans_lost_cluster(self):
"""This will cause kmean to have a cluster with no points."""
data = N.fromfile(open(DATAFILE1), sep = ", ")
data = data.reshape((200, 2))
@@ -113,7 +109,7 @@
except ClusterError, e:
print "exception raised as expected: " + str(e)
- def check_kmeans2_simple(self, level=1):
+ def test_kmeans2_simple(self):
"""Testing simple call to kmeans2 and its results."""
initc = N.concatenate(([[X[0]], [X[1]], [X[2]]]))
code = initc.copy()
@@ -123,7 +119,7 @@
assert_array_almost_equal(code1, CODET1)
assert_array_almost_equal(code2, CODET2)
- def check_kmeans2_rank1(self, level=1):
+ def test_kmeans2_rank1(self):
"""Testing simple call to kmeans2 with rank 1 data."""
data = N.fromfile(open(DATAFILE1), sep = ", ")
data = data.reshape((200, 2))
@@ -135,7 +131,7 @@
code1 = kmeans2(data1, code, iter = 1)[0]
code2 = kmeans2(data1, code, iter = 2)[0]
- def check_kmeans2_init(self, level = 1):
+ def test_kmeans2_init(self):
"""Testing that kmeans2 init methods work."""
data = N.fromfile(open(DATAFILE1), sep = ", ")
data = data.reshape((200, 2))
@@ -149,4 +145,4 @@
kmeans2(data, 3, minit = 'points')
if __name__ == "__main__":
- NumpyTest().run()
+ unittest.main()
Modified: trunk/scipy/fftpack/__init__.py
===================================================================
--- trunk/scipy/fftpack/__init__.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/fftpack/__init__.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -17,5 +17,5 @@
del k, register_func
-from numpy.testing import NumpyTest
-test = NumpyTest().test
+from scipy.testing.pkgtester import Tester
+test = Tester().test
Modified: trunk/scipy/fftpack/tests/test_basic.py
===================================================================
--- trunk/scipy/fftpack/tests/test_basic.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/fftpack/tests/test_basic.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -6,16 +6,14 @@
Build fftpack:
python setup_fftpack.py build
Run tests if scipy is installed:
- python -c 'import scipy;scipy.fftpack.test(<level>)'
+ python -c 'import scipy;scipy.fftpack.test()'
Run tests if fftpack is not installed:
- python tests/test_basic.py [<level>]
+ python tests/test_basic.py
"""
import sys
-from numpy.testing import *
-set_package_path()
-from fftpack import ifft,fft,fftn,ifftn,rfft,irfft
-from fftpack import _fftpack as fftpack
-restore_path()
+from scipy.testing import *
+from scipy.fftpack import ifft,fft,fftn,ifftn,rfft,irfft
+from scipy.fftpack import _fftpack as fftpack
from numpy import arange, add, array, asarray, zeros, dot, exp, pi,\
swapaxes, double, cdouble
@@ -90,9 +88,9 @@
x1[0] = x[0]
return direct_idft(x1).real
-class TestFft(NumpyTestCase):
+class TestFft(TestCase):
- def check_definition(self):
+ def test_definition(self):
x = [1,2,3,4+1j,1,2,3,4+2j]
y = fft(x)
y1 = direct_dft(x)
@@ -100,7 +98,7 @@
x = [1,2,3,4+0j,5]
assert_array_almost_equal(fft(x),direct_dft(x))
- def check_n_argument_real(self):
+ def test_n_argument_real(self):
x1 = [1,2,3,4]
x2 = [1,2,3,4]
y = fft([x1,x2],n=4)
@@ -108,7 +106,7 @@
assert_array_almost_equal(y[0],direct_dft(x1))
assert_array_almost_equal(y[1],direct_dft(x2))
- def _check_n_argument_complex(self):
+ def _test_n_argument_complex(self):
x1 = [1,2,3,4+1j]
x2 = [1,2,3,4+1j]
y = fft([x1,x2],n=4)
@@ -116,7 +114,7 @@
assert_array_almost_equal(y[0],direct_dft(x1))
assert_array_almost_equal(y[1],direct_dft(x2))
- def check_djbfft(self):
+ def test_djbfft(self):
for i in range(2,14):
n = 2**i
x = range(n)
@@ -126,7 +124,8 @@
y = fftpack.zrfft(x)
assert_array_almost_equal(y,y2)
- def bench_random(self,level=5):
+ @dec.bench
+ def test_random(self):
from numpy.fft import fft as numpy_fft
print
print ' Fast Fourier Transform'
@@ -152,19 +151,19 @@
if size > 500: y = fft(x)
else: y = direct_dft(x)
assert_array_almost_equal(fft(x),y)
- print '|%8.2f' % self.measure('fft(x)',repeat),
+ print '|%8.2f' % measure('fft(x)',repeat),
sys.stdout.flush()
assert_array_almost_equal(numpy_fft(x),y)
- print '|%8.2f' % self.measure('numpy_fft(x)',repeat),
+ print '|%8.2f' % measure('numpy_fft(x)',repeat),
sys.stdout.flush()
print ' (secs for %s calls)' % (repeat)
sys.stdout.flush()
-class TestIfft(NumpyTestCase):
+class TestIfft(TestCase):
- def check_definition(self):
+ def test_definition(self):
x = [1,2,3,4+1j,1,2,3,4+2j]
y = ifft(x)
y1 = direct_idft(x)
@@ -178,7 +177,7 @@
x = [1,2,3,4,5]
assert_array_almost_equal(ifft(x),direct_idft(x))
- def check_djbfft(self):
+ def test_djbfft(self):
for i in range(2,14):
n = 2**i
x = range(n)
@@ -188,20 +187,21 @@
y = fftpack.zrfft(x,direction=-1)
assert_array_almost_equal(y,y2)
- def check_random_complex(self):
+ def test_random_complex(self):
for size in [1,51,111,100,200,64,128,256,1024]:
x = random([size]).astype(cdouble)
x = random([size]).astype(cdouble) +1j*x
assert_array_almost_equal (ifft(fft(x)),x)
assert_array_almost_equal (fft(ifft(x)),x)
- def check_random_real(self):
+ def test_random_real(self):
for size in [1,51,111,100,200,64,128,256,1024]:
x = random([size]).astype(double)
assert_array_almost_equal (ifft(fft(x)),x)
assert_array_almost_equal (fft(ifft(x)),x)
- def bench_random(self,level=5):
+ @dec.bench
+ def test_random(self):
from numpy.fft import ifft as numpy_ifft
print
print ' Inverse Fast Fourier Transform'
@@ -227,19 +227,19 @@
if size > 500: y = ifft(x)
else: y = direct_idft(x)
assert_array_almost_equal(ifft(x),y)
- print '|%8.2f' % self.measure('ifft(x)',repeat),
+ print '|%8.2f' % measure('ifft(x)',repeat),
sys.stdout.flush()
assert_array_almost_equal(numpy_ifft(x),y)
- print '|%8.2f' % self.measure('numpy_ifft(x)',repeat),
+ print '|%8.2f' % measure('numpy_ifft(x)',repeat),
sys.stdout.flush()
print ' (secs for %s calls)' % (repeat)
sys.stdout.flush()
-class TestRfft(NumpyTestCase):
+class TestRfft(TestCase):
- def check_definition(self):
+ def test_definition(self):
x = [1,2,3,4,1,2,3,4]
y = rfft(x)
y1 = direct_rdft(x)
@@ -249,7 +249,7 @@
y1 = direct_rdft(x)
assert_array_almost_equal(y,y1)
- def check_djbfft(self):
+ def test_djbfft(self):
from numpy.fft import fft as numpy_fft
for i in range(2,14):
n = 2**i
@@ -264,7 +264,8 @@
y = fftpack.drfft(x)
assert_array_almost_equal(y,y1)
- def bench_random(self,level=5):
+ @dec.bench
+ def test_random(self):
from numpy.fft import rfft as numpy_rfft
print
print 'Fast Fourier Transform (real data)'
@@ -283,18 +284,18 @@
sys.stdout.flush()
x = random([size]).astype(double)
- print '|%8.2f' % self.measure('rfft(x)',repeat),
+ print '|%8.2f' % measure('rfft(x)',repeat),
sys.stdout.flush()
- print '|%8.2f' % self.measure('numpy_rfft(x)',repeat),
+ print '|%8.2f' % measure('numpy_rfft(x)',repeat),
sys.stdout.flush()
print ' (secs for %s calls)' % (repeat)
sys.stdout.flush()
-class TestIrfft(NumpyTestCase):
+class TestIrfft(TestCase):
- def check_definition(self):
+ def test_definition(self):
x = [1,2,3,4,1,2,3,4]
x1 = [1,2+3j,4+1j,2+3j,4,2-3j,4-1j,2-3j]
y = irfft(x)
@@ -308,7 +309,7 @@
assert_array_almost_equal(y,y1)
assert_array_almost_equal(y,ifft(x1))
- def check_djbfft(self):
+ def test_djbfft(self):
from numpy.fft import ifft as numpy_ifft
for i in range(2,14):
n = 2**i
@@ -323,13 +324,14 @@
y = fftpack.drfft(x,direction=-1)
assert_array_almost_equal(y,y1)
- def check_random_real(self):
+ def test_random_real(self):
for size in [1,51,111,100,200,64,128,256,1024]:
x = random([size]).astype(double)
assert_array_almost_equal (irfft(rfft(x)),x)
assert_array_almost_equal (rfft(irfft(x)),x)
- def bench_random(self,level=5):
+ @dec.bench
+ def test_random(self):
from numpy.fft import irfft as numpy_irfft
print
@@ -357,20 +359,20 @@
x1[-1] = x[-1]
y = irfft(x)
- print '|%8.2f' % self.measure('irfft(x)',repeat),
+ print '|%8.2f' % measure('irfft(x)',repeat),
sys.stdout.flush()
assert_array_almost_equal(numpy_irfft(x1,size),y)
- print '|%8.2f' % self.measure('numpy_irfft(x1,size)',repeat),
+ print '|%8.2f' % measure('numpy_irfft(x1,size)',repeat),
sys.stdout.flush()
print ' (secs for %s calls)' % (repeat)
sys.stdout.flush()
-class TestFftn(NumpyTestCase):
+class TestFftn(TestCase):
- def check_definition(self):
+ def test_definition(self):
x = [[1,2,3],[4,5,6],[7,8,9]]
y = fftn(x)
assert_array_almost_equal(y,direct_dftn(x))
@@ -379,7 +381,7 @@
x = random((5,4,3,20))
assert_array_almost_equal(fftn(x),direct_dftn(x))
- def check_axes_argument(self):
+ def test_axes_argument(self):
#plane == ji_plane, x== kji_space
plane1 = [[1,2,3],[4,5,6],[7,8,9]]
plane2 = [[10,11,12],[13,14,15],[16,17,18]]
@@ -469,7 +471,7 @@
y = fftn(x,axes=()) # point
assert_array_almost_equal(y,x)
- def check_shape_argument(self):
+ def test_shape_argument(self):
small_x = [[1,2,3],[4,5,6]]
large_x1 = [[1,2,3,0],[4,5,6,0],[0,0,0,0],[0,0,0,0]]
y = fftn(small_x,shape=(4,4))
@@ -477,7 +479,7 @@
y = fftn(small_x,shape=(3,4))
assert_array_almost_equal (y,fftn(large_x1[:-1]))
- def check_shape_axes_argument(self):
+ def test_shape_axes_argument(self):
small_x = [[1,2,3],[4,5,6],[7,8,9]]
large_x1 = array([[1,2,3,0],
[4,5,6,0],
@@ -495,7 +497,8 @@
assert_array_almost_equal (y,swapaxes(\
fftn(swapaxes(large_x1,-1,-2)),-1,-2))
- def bench_random(self,level=5):
+ @dec.bench
+ def test_random(self):
from numpy.fft import fftn as numpy_fftn
print
print ' Multi-dimensional Fast Fourier Transform'
@@ -518,20 +521,20 @@
#if size > 500: y = fftn(x)
#else: y = direct_dft(x)
assert_array_almost_equal(fftn(x),y)
- print '|%8.2f' % self.measure('fftn(x)',repeat),
+ print '|%8.2f' % measure('fftn(x)',repeat),
sys.stdout.flush()
assert_array_almost_equal(numpy_fftn(x),y)
- print '|%8.2f' % self.measure('numpy_fftn(x)',repeat),
+ print '|%8.2f' % measure('numpy_fftn(x)',repeat),
sys.stdout.flush()
print ' (secs for %s calls)' % (repeat)
sys.stdout.flush()
-class TestIfftn(NumpyTestCase):
+class TestIfftn(TestCase):
- def check_definition(self):
+ def test_definition(self):
x = [[1,2,3],[4,5,6],[7,8,9]]
y = ifftn(x)
assert_array_almost_equal(y,direct_idftn(x))
@@ -540,11 +543,11 @@
x = random((5,4,3,20))
assert_array_almost_equal(ifftn(x),direct_idftn(x))
- def check_random_complex(self):
+ def test_random_complex(self):
for size in [1,2,51,32,64,92]:
x = random([size,size]) + 1j*random([size,size])
assert_array_almost_equal (ifftn(fftn(x)),x)
assert_array_almost_equal (fftn(ifftn(x)),x)
if __name__ == "__main__":
- NumpyTest().run()
+ unittest.main()
Modified: trunk/scipy/fftpack/tests/test_helper.py
===================================================================
--- trunk/scipy/fftpack/tests/test_helper.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/fftpack/tests/test_helper.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -12,19 +12,17 @@
"""
import sys
-from numpy.testing import *
-set_package_path()
-from fftpack import fftshift,ifftshift,fftfreq,rfftfreq
-restore_path()
+from scipy.testing import *
+from scipy.fftpack import fftshift,ifftshift,fftfreq,rfftfreq
from numpy import pi
def random(size):
return rand(*size)
-class TestFFTShift(NumpyTestCase):
+class TestFFTShift(TestCase):
- def check_definition(self):
+ def test_definition(self):
x = [0,1,2,3,4,-4,-3,-2,-1]
y = [-4,-3,-2,-1,0,1,2,3,4]
assert_array_almost_equal(fftshift(x),y)
@@ -34,14 +32,14 @@
assert_array_almost_equal(fftshift(x),y)
assert_array_almost_equal(ifftshift(y),x)
- def check_inverse(self):
+ def test_inverse(self):
for n in [1,4,9,100,211]:
x = random((n,))
assert_array_almost_equal(ifftshift(fftshift(x)),x)
-class TestFFTFreq(NumpyTestCase):
+class TestFFTFreq(TestCase):
- def check_definition(self):
+ def test_definition(self):
x = [0,1,2,3,4,-4,-3,-2,-1]
assert_array_almost_equal(9*fftfreq(9),x)
assert_array_almost_equal(9*pi*fftfreq(9,pi),x)
@@ -49,9 +47,9 @@
assert_array_almost_equal(10*fftfreq(10),x)
assert_array_almost_equal(10*pi*fftfreq(10,pi),x)
-class TestRFFTFreq(NumpyTestCase):
+class TestRFFTFreq(TestCase):
- def check_definition(self):
+ def test_definition(self):
x = [0,1,1,2,2,3,3,4,4]
assert_array_almost_equal(9*rfftfreq(9),x)
assert_array_almost_equal(9*pi*rfftfreq(9,pi),x)
@@ -60,4 +58,4 @@
assert_array_almost_equal(10*pi*rfftfreq(10,pi),x)
if __name__ == "__main__":
- NumpyTest().run()
+ unittest.main()
Modified: trunk/scipy/fftpack/tests/test_pseudo_diffs.py
===================================================================
--- trunk/scipy/fftpack/tests/test_pseudo_diffs.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/fftpack/tests/test_pseudo_diffs.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -11,12 +11,10 @@
python tests/test_pseudo_diffs.py [<level>]
"""
import sys
-from numpy.testing import *
-set_package_path()
-from fftpack import diff,fft,ifft,tilbert,itilbert,hilbert,ihilbert,rfft
-from fftpack import shift
-from fftpack import fftfreq
-restore_path()
+from scipy.testing import *
+from scipy.fftpack import diff,fft,ifft,tilbert,itilbert,hilbert,ihilbert,rfft
+from scipy.fftpack import shift
+from scipy.fftpack import fftfreq
from numpy import arange, add, array, sin, cos, pi,exp,tanh,sum,sign
@@ -77,9 +75,9 @@
return ifft(fft(x)*exp(k*a)).real
-class TestDiff(NumpyTestCase):
+class TestDiff(TestCase):
- def check_definition(self):
+ def test_definition(self):
for n in [16,17,64,127,32]:
x = arange(n)*2*pi/n
assert_array_almost_equal(diff(sin(x)),direct_diff(sin(x)))
@@ -100,7 +98,7 @@
assert_array_almost_equal(diff(sin(4*x),k),direct_diff(sin(4*x),k))
assert_array_almost_equal(diff(cos(4*x),k),direct_diff(cos(4*x),k))
- def check_period(self):
+ def test_period(self):
for n in [17,64]:
x = arange(n)/float(n)
assert_array_almost_equal(diff(sin(2*pi*x),period=1),
@@ -108,7 +106,7 @@
assert_array_almost_equal(diff(sin(2*pi*x),3,period=1),
-(2*pi)**3*cos(2*pi*x))
- def check_sin(self):
+ def test_sin(self):
for n in [32,64,77]:
x = arange(n)*2*pi/n
assert_array_almost_equal(diff(sin(x)),cos(x))
@@ -118,7 +116,7 @@
assert_array_almost_equal(diff(sin(4*x)),4*cos(4*x))
assert_array_almost_equal(diff(sin(sin(x))),cos(x)*cos(sin(x)))
- def check_expr(self):
+ def test_expr(self):
for n in [64,77,100,128,256,512,1024,2048,4096,8192][:5]:
x = arange(n)*2*pi/n
f=sin(x)*cos(4*x)+exp(sin(3*x))
@@ -132,7 +130,7 @@
assert_array_almost_equal(diff(ddf,-1),df)
#print max(abs(d1-df))
- def check_expr_large(self):
+ def test_expr_large(self):
for n in [2048,4096]:
x = arange(n)*2*pi/n
f=sin(x)*cos(4*x)+exp(sin(3*x))
@@ -144,7 +142,7 @@
assert_array_almost_equal(diff(ddf,-1),df)
assert_array_almost_equal(diff(f,2),ddf)
- def check_int(self):
+ def test_int(self):
n = 64
x = arange(n)*2*pi/n
assert_array_almost_equal(diff(sin(x),-1),-cos(x))
@@ -152,7 +150,7 @@
assert_array_almost_equal(diff(sin(x),-4),sin(x))
assert_array_almost_equal(diff(2*cos(2*x),-1),sin(2*x))
- def check_random_even(self):
+ def test_random_even(self):
for k in [0,2,4,6]:
for n in [60,32,64,56,55]:
f=random ((n,))
@@ -164,7 +162,7 @@
assert_array_almost_equal(diff(diff(f,k),-k),f)
assert_array_almost_equal(diff(diff(f,-k),k),f)
- def check_random_odd(self):
+ def test_random_odd(self):
for k in [0,1,2,3,4,5,6]:
for n in [33,65,55]:
f=random ((n,))
@@ -174,7 +172,7 @@
assert_array_almost_equal(diff(diff(f,k),-k),f)
assert_array_almost_equal(diff(diff(f,-k),k),f)
- def check_zero_nyquist (self):
+ def test_zero_nyquist (self):
for k in [0,1,2,3,4,5,6]:
for n in [32,33,64,56,55]:
f=random ((n,))
@@ -186,7 +184,8 @@
assert_array_almost_equal(diff(diff(f,k),-k),f)
assert_array_almost_equal(diff(diff(f,-k),k),f)
- def bench_random(self,level=5):
+ @dec.bench
+ def test_random(self):
print
print 'Differentiation of periodic functions'
print '====================================='
@@ -209,16 +208,16 @@
f = sin(x)*cos(4*x)
assert_array_almost_equal(diff(f,1),direct_diff(f,1))
assert_array_almost_equal(diff(f,2),direct_diff(f,2))
- print '| %9.2f' % self.measure('diff(f,3)',repeat),
+ print '| %9.2f' % measure('diff(f,3)',repeat),
sys.stdout.flush()
- print '| %9.2f' % self.measure('direct_diff(f,3)',repeat),
+ print '| %9.2f' % measure('direct_diff(f,3)',repeat),
sys.stdout.flush()
print ' (secs for %s calls)' % (repeat)
-class TestTilbert(NumpyTestCase):
+class TestTilbert(TestCase):
- def check_definition(self):
+ def test_definition(self):
for h in [0.1,0.5,1,5.5,10]:
for n in [16,17,64,127]:
x = arange(n)*2*pi/n
@@ -230,7 +229,7 @@
assert_array_almost_equal(tilbert(sin(2*x),h),
direct_tilbert(sin(2*x),h))
- def check_random_even(self):
+ def test_random_even(self):
for h in [0.1,0.5,1,5.5,10]:
for n in [32,64,56]:
f=random ((n,))
@@ -239,7 +238,7 @@
assert_almost_equal(sum(f,axis=0),0.0)
assert_array_almost_equal(direct_tilbert(direct_itilbert(f,h),h),f)
- def check_random_odd(self):
+ def test_random_odd(self):
for h in [0.1,0.5,1,5.5,10]:
for n in [33,65,55]:
f=random ((n,))
@@ -249,7 +248,8 @@
assert_array_almost_equal(itilbert(tilbert(f,h),h),f)
assert_array_almost_equal(tilbert(itilbert(f,h),h),f)
- def bench_random(self,level=5):
+ @dec.bench
+ def test_random(self):
print
print ' Tilbert transform of periodic functions'
print '========================================='
@@ -271,15 +271,15 @@
else:
f = sin(x)*cos(4*x)
assert_array_almost_equal(tilbert(f,1),direct_tilbert(f,1))
- print '| %9.2f' % self.measure('tilbert(f,1)',repeat),
+ print '| %9.2f' % measure('tilbert(f,1)',repeat),
sys.stdout.flush()
- print '| %9.2f' % self.measure('direct_tilbert(f,1)',repeat),
+ print '| %9.2f' % measure('direct_tilbert(f,1)',repeat),
sys.stdout.flush()
print ' (secs for %s calls)' % (repeat)
-class TestITilbert(NumpyTestCase):
+class TestITilbert(TestCase):
- def check_definition(self):
+ def test_definition(self):
for h in [0.1,0.5,1,5.5,10]:
for n in [16,17,64,127]:
x = arange(n)*2*pi/n
@@ -291,9 +291,9 @@
assert_array_almost_equal(itilbert(sin(2*x),h),
direct_itilbert(sin(2*x),h))
-class TestHilbert(NumpyTestCase):
+class TestHilbert(TestCase):
- def check_definition(self):
+ def test_definition(self):
for n in [16,17,64,127]:
x = arange(n)*2*pi/n
y = hilbert(sin(x))
@@ -302,7 +302,7 @@
assert_array_almost_equal(hilbert(sin(2*x)),
direct_hilbert(sin(2*x)))
- def check_tilbert_relation(self):
+ def test_tilbert_relation(self):
for n in [16,17,64,127]:
x = arange(n)*2*pi/n
f = sin (x)+cos (2*x)*sin(x)
@@ -312,7 +312,7 @@
y2 = tilbert(f,h=10)
assert_array_almost_equal (y,y2)
- def check_random_odd(self):
+ def test_random_odd(self):
for n in [33,65,55]:
f=random ((n,))
af=sum(f,axis=0)/n
@@ -321,7 +321,7 @@
assert_array_almost_equal(ihilbert(hilbert(f)),f)
assert_array_almost_equal(hilbert(ihilbert(f)),f)
- def check_random_even(self):
+ def test_random_even(self):
for n in [32,64,56]:
f=random ((n,))
af=sum(f,axis=0)/n
@@ -332,7 +332,8 @@
assert_array_almost_equal(direct_hilbert(direct_ihilbert(f)),f)
assert_array_almost_equal(hilbert(ihilbert(f)),f)
- def bench_random(self,level=5):
+ @dec.bench
+ def test_random(self):
print
print ' Hilbert transform of periodic functions'
print '========================================='
@@ -354,15 +355,15 @@
else:
f = sin(x)*cos(4*x)
assert_array_almost_equal(hilbert(f),direct_hilbert(f))
- print '| %9.2f' % self.measure('hilbert(f)',repeat),
+ print '| %9.2f' % measure('hilbert(f)',repeat),
sys.stdout.flush()
- print '| %9.2f' % self.measure('direct_hilbert(f)',repeat),
+ print '| %9.2f' % measure('direct_hilbert(f)',repeat),
sys.stdout.flush()
print ' (secs for %s calls)' % (repeat)
-class TestIHilbert(NumpyTestCase):
+class TestIHilbert(TestCase):
- def check_definition(self):
+ def test_definition(self):
for n in [16,17,64,127]:
x = arange(n)*2*pi/n
y = ihilbert(sin(x))
@@ -371,7 +372,7 @@
assert_array_almost_equal(ihilbert(sin(2*x)),
direct_ihilbert(sin(2*x)))
- def check_itilbert_relation(self):
+ def test_itilbert_relation(self):
for n in [16,17,64,127]:
x = arange(n)*2*pi/n
f = sin (x)+cos (2*x)*sin(x)
@@ -381,9 +382,9 @@
y2 = itilbert(f,h=10)
assert_array_almost_equal (y,y2)
-class TestShift(NumpyTestCase):
+class TestShift(TestCase):
- def check_definition(self):
+ def test_definition(self):
for n in [18,17,64,127,32,2048,256]:
x = arange(n)*2*pi/n
for a in [0.1,3]:
@@ -397,7 +398,8 @@
assert_array_almost_equal(shift(sin(x),pi),-sin(x))
assert_array_almost_equal(shift(sin(x),pi/2),cos(x))
- def bench_random(self,level=5):
+ @dec.bench
+ def test_random(self):
print
print ' Shifting periodic functions'
print '=============================='
@@ -423,11 +425,11 @@
sf = sin(x+a)*cos(4*(x+a))
assert_array_almost_equal(direct_shift(f,1),sf)
assert_array_almost_equal(shift(f,1),sf)
- print '| %9.2f' % self.measure('shift(f,a)',repeat),
+ print '| %9.2f' % measure('shift(f,a)',repeat),
sys.stdout.flush()
- print '| %9.2f' % self.measure('direct_shift(f,a)',repeat),
+ print '| %9.2f' % measure('direct_shift(f,a)',repeat),
sys.stdout.flush()
print ' (secs for %s calls)' % (repeat)
if __name__ == "__main__":
- NumpyTest('fftpack.pseudo_diffs').run()
+ unittest.main()
Modified: trunk/scipy/integrate/__init__.py
===================================================================
--- trunk/scipy/integrate/__init__.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/integrate/__init__.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -12,5 +12,5 @@
from ode import *
__all__ = filter(lambda s:not s.startswith('_'),dir())
-from numpy.testing import NumpyTest
-test = NumpyTest().test
+from scipy.testing.pkgtester import Tester
+test = Tester().test
Modified: trunk/scipy/integrate/tests/test_integrate.py
===================================================================
--- trunk/scipy/integrate/tests/test_integrate.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/integrate/tests/test_integrate.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -9,12 +9,10 @@
import numpy
from numpy import arange, zeros, array, dot, sqrt, cos, sin
from scipy.linalg import norm
-from numpy.testing import *
-set_package_path()
+from scipy.testing import *
from scipy.integrate import odeint
-restore_path()
-class TestODEInt(NumpyTestCase):
+class TestODEInt(TestCase):
""" Test odeint: free vibration of a simple oscillator
m \ddot{u} + k u = 0, u(0) = u_0 \dot{u}(0) \dot{u}_0
@@ -32,7 +30,7 @@
tmp[1,0] = -self.k / self.m
return dot(tmp,z)
- def check_odeint1(self):
+ def test_odeint1(self):
omega = sqrt(self.k / self.m)
z0 = zeros(2, float)
z0[0] = 1.0 # initial displacement
@@ -51,4 +49,4 @@
assert res < 1.0e-6
if __name__ == "__main__":
- NumpyTest().run()
+ unittest.main()
Modified: trunk/scipy/integrate/tests/test_quadpack.py
===================================================================
--- trunk/scipy/integrate/tests/test_quadpack.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/integrate/tests/test_quadpack.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -1,29 +1,27 @@
import numpy
from numpy import sqrt, cos, sin, arctan, exp, log, pi, Inf
-from numpy.testing import *
-set_package_path()
+from scipy.testing import *
from scipy.integrate import quad, dblquad, tplquad
-restore_path()
def assert_quad((value, err), tabledValue, errTol=1.5e-8):
assert abs(value-tabledValue) < err, (value, tabledValue, err)
if errTol is not None:
assert err < errTol, (err, errTol)
-class TestQuad(NumpyTestCase):
- def check_typical(self):
+class TestQuad(TestCase):
+ def test_typical(self):
# 1) Typical function with two extra arguments:
def myfunc(x,n,z): # Bessel function integrand
return cos(n*x-z*sin(x))/pi
assert_quad(quad(myfunc,0,pi,(2,1.8)), 0.30614353532540296487)
- def check_indefinite(self):
+ def test_indefinite(self):
# 2) Infinite integration limits --- Euler's constant
def myfunc(x): # Euler's constant integrand
return -exp(-x)*log(x)
assert_quad(quad(myfunc,0,Inf), 0.577215664901532860606512)
- def check_singular(self):
+ def test_singular(self):
# 3) Singular points in region of integration.
def myfunc(x):
if x > 0 and x < 2.5:
@@ -36,7 +34,7 @@
assert_quad(quad(myfunc,0,10,points=[2.5,5.0]),
1 - cos(2.5) + exp(-2.5) - exp(-5.0))
- def check_sine_weighted_finite(self):
+ def test_sine_weighted_finite(self):
# 4) Sine weighted integral (finite limits)
def myfunc(x,a):
return exp(a*(x-1))
@@ -45,7 +43,7 @@
assert_quad(quad(myfunc,0,1,args=20,weight='sin',wvar=ome),
(20*sin(ome)-ome*cos(ome)+ome*exp(-20))/(20**2 + ome**2))
- def check_sine_weighted_infinite(self):
+ def test_sine_weighted_infinite(self):
# 5) Sine weighted integral (infinite limits)
def myfunc(x,a):
return exp(-x*a)
@@ -55,7 +53,7 @@
assert_quad(quad(myfunc,0,Inf,args=a,weight='sin',wvar=ome),
ome/(a**2 + ome**2))
- def check_cosine_weighted_infinite(self):
+ def test_cosine_weighted_infinite(self):
# 6) Cosine weighted integral (negative infinite limits)
def myfunc(x,a):
return exp(x*a)
@@ -65,7 +63,7 @@
assert_quad(quad(myfunc,-Inf,0,args=a,weight='cos',wvar=ome),
a/(a**2 + ome**2))
- def check_algebraic_log_weight(self):
+ def test_algebraic_log_weight(self):
# 6) Algebraic-logarithmic weight.
def myfunc(x,a):
return 1/(1+x+2**(-a))
@@ -74,7 +72,7 @@
assert_quad(quad(myfunc,-1,1,args=a,weight='alg',wvar=(-0.5,-0.5)),
pi/sqrt((1+2**(-a))**2 - 1))
- def check_cauchypv_weight(self):
+ def test_cauchypv_weight(self):
# 7) Cauchy prinicpal value weighting w(x) = 1/(x-c)
def myfunc(x,a):
return 2.0**(-a)/((x-1)**2+4.0**(-a))
@@ -85,7 +83,7 @@
assert_quad(quad(myfunc,0,5,args=0.4,weight='cauchy',wvar=2.0),
tabledValue, errTol=1.9e-8)
- def check_double_integral(self):
+ def test_double_integral(self):
# 8) Double Integral test
def simpfunc(y,x): # Note order of arguments.
return x+y
@@ -94,7 +92,7 @@
assert_quad(dblquad(simpfunc,a,b,lambda x: x, lambda x: 2*x),
5/6.0 * (b**3.0-a**3.0))
- def check_triple_integral(self):
+ def test_triple_integral(self):
# 9) Triple Integral test
def simpfunc(z,y,x): # Note order of arguments.
return x+y+z
@@ -106,4 +104,4 @@
8/3.0 * (b**4.0 - a**4.0))
if __name__ == "__main__":
- NumpyTest().run()
+ unittest.main()
Modified: trunk/scipy/integrate/tests/test_quadrature.py
===================================================================
--- trunk/scipy/integrate/tests/test_quadrature.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/integrate/tests/test_quadrature.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -1,17 +1,15 @@
import numpy
from numpy import cos, sin, pi
-from numpy.testing import *
+from scipy.testing import *
-set_package_path()
from scipy.integrate import quadrature, romberg, romb
-restore_path()
-class TestQuadrature(NumpyTestCase):
+class TestQuadrature(TestCase):
def quad(self, x, a, b, args):
raise NotImplementedError
- def check_quadrature(self):
+ def test_quadrature(self):
# Typical function with two extra arguments:
def myfunc(x,n,z): # Bessel function integrand
return cos(n*x-z*sin(x))/pi
@@ -19,7 +17,7 @@
table_val = 0.30614353532540296487
assert_almost_equal(val, table_val, decimal=7)
- def check_romberg(self):
+ def test_romberg(self):
# Typical function with two extra arguments:
def myfunc(x, n, z): # Bessel function integrand
return cos(n*x-z*sin(x))/pi
@@ -27,8 +25,8 @@
table_val = 0.30614353532540296487
assert_almost_equal(val, table_val, decimal=7)
- def check_romb(self):
+ def test_romb(self):
assert_equal(romb(numpy.arange(17)),128)
if __name__ == "__main__":
- NumpyTest().run()
+ unittest.main()
Modified: trunk/scipy/interpolate/__init__.py
===================================================================
--- trunk/scipy/interpolate/__init__.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/interpolate/__init__.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -11,5 +11,5 @@
from fitpack2 import *
__all__ = filter(lambda s:not s.startswith('_'),dir())
-from numpy.testing import NumpyTest
-test = NumpyTest().test
+from scipy.testing.pkgtester import Tester
+test = Tester().test
Modified: trunk/scipy/interpolate/tests/test_fitpack.py
===================================================================
--- trunk/scipy/interpolate/tests/test_fitpack.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/interpolate/tests/test_fitpack.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -13,17 +13,15 @@
#import libwadpy
import sys
-from numpy.testing import *
+from scipy.testing import *
from numpy import array
-set_package_path()
-from interpolate.fitpack2 import UnivariateSpline,LSQUnivariateSpline,\
+from scipy.interpolate.fitpack2 import UnivariateSpline,LSQUnivariateSpline,\
InterpolatedUnivariateSpline
-from interpolate.fitpack2 import LSQBivariateSpline, SmoothBivariateSpline,\
- RectBivariateSpline
-restore_path()
+from scipy.interpolate.fitpack2 import LSQBivariateSpline, \
+ SmoothBivariateSpline, RectBivariateSpline
-class TestUnivariateSpline(NumpyTestCase):
- def check_linear_constant(self):
+class TestUnivariateSpline(TestCase):
+ def test_linear_constant(self):
x = [1,2,3]
y = [3,3,3]
lut = UnivariateSpline(x,y,k=1)
@@ -32,7 +30,7 @@
assert_almost_equal(lut.get_residual(),0.0)
assert_array_almost_equal(lut([1,1.5,2]),[3,3,3])
- def check_linear_1d(self):
+ def test_linear_1d(self):
x = [1,2,3]
y = [0,2,4]
lut = UnivariateSpline(x,y,k=1)
@@ -41,8 +39,8 @@
assert_almost_equal(lut.get_residual(),0.0)
assert_array_almost_equal(lut([1,1.5,2]),[0,1,2])
-class TestLSQBivariateSpline(NumpyTestCase):
- def check_linear_constant(self):
+class TestLSQBivariateSpline(TestCase):
+ def test_linear_constant(self):
x = [1,1,1,2,2,2,3,3,3]
y = [1,2,3,1,2,3,1,2,3]
z = [3,3,3,3,3,3,3,3,3]
@@ -54,8 +52,8 @@
#print lut.get_coeffs()
#print lut.get_residual()
-class TestSmoothBivariateSpline(NumpyTestCase):
- def check_linear_constant(self):
+class TestSmoothBivariateSpline(TestCase):
+ def test_linear_constant(self):
x = [1,1,1,2,2,2,3,3,3]
y = [1,2,3,1,2,3,1,2,3]
z = [3,3,3,3,3,3,3,3,3]
@@ -65,7 +63,7 @@
assert_almost_equal(lut.get_residual(),0.0)
assert_array_almost_equal(lut([1,1.5,2],[1,1.5]),[[3,3],[3,3],[3,3]])
- def check_linear_1d(self):
+ def test_linear_1d(self):
x = [1,1,1,2,2,2,3,3,3]
y = [1,2,3,1,2,3,1,2,3]
z = [0,0,0,2,2,2,4,4,4]
@@ -75,8 +73,8 @@
assert_almost_equal(lut.get_residual(),0.0)
assert_array_almost_equal(lut([1,1.5,2],[1,1.5]),[[0,0],[1,1],[2,2]])
-class TestRectBivariateSpline(NumpyTestCase):
- def check_defaults(self):
+class TestRectBivariateSpline(TestCase):
+ def test_defaults(self):
x = array([1,2,3,4,5])
y = array([1,2,3,4,5])
z = array([[1,2,1,2,1],[1,2,1,2,1],[1,2,3,2,1],[1,2,2,2,1],[1,2,1,2,1]])
@@ -84,4 +82,4 @@
assert_array_almost_equal(lut(x,y),z)
if __name__ == "__main__":
- NumpyTest().run()
+ unittest.main()
Modified: trunk/scipy/interpolate/tests/test_interpolate.py
===================================================================
--- trunk/scipy/interpolate/tests/test_interpolate.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/interpolate/tests/test_interpolate.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -1,13 +1,11 @@
-from numpy.testing import *
+from scipy.testing import *
from numpy import mgrid, pi, sin, ogrid
import numpy as np
-set_package_path()
-from interpolate import interp1d, interp2d
-restore_path()
+from scipy.interpolate import interp1d, interp2d
-class TestInterp2D(NumpyTestCase):
+class TestInterp2D(TestCase):
def test_interp2d(self):
y, x = mgrid[0:pi:20j, 0:pi:21j]
z = sin(x+y)
@@ -18,7 +16,7 @@
assert_almost_equal(I(u.ravel(), v.ravel()), sin(v+u), decimal=2)
-class TestInterp1D(NumpyTestCase):
+class TestInterp1D(TestCase):
def setUp(self):
self.x10 = np.arange(10.)
@@ -202,4 +200,4 @@
if __name__ == "__main__":
- NumpyTest().run()
+ unittest.main()
Modified: trunk/scipy/io/__init__.py
===================================================================
--- trunk/scipy/io/__init__.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/io/__init__.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -83,8 +83,6 @@
from data_store import save_as_module
from mmio import mminfo, mmread, mmwrite
-
-
__all__ = filter(lambda s:not s.startswith('_'),dir())
-from numpy.testing import NumpyTest
-test = NumpyTest().test
+from scipy.testing.pkgtester import Tester
+test = Tester().test
Modified: trunk/scipy/io/matlab/tests/test_mio.py
===================================================================
--- trunk/scipy/io/matlab/tests/test_mio.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/io/matlab/tests/test_mio.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -1,248 +1,242 @@
#!/usr/bin/env python
-
+''' Nose test generators '''
import os
from glob import glob
from cStringIO import StringIO
from tempfile import mkstemp
-from numpy.testing import set_package_path, restore_path, NumpyTestCase, NumpyTest
-from numpy.testing import assert_equal, assert_array_almost_equal
+from scipy.testing import *
from numpy import arange, array, eye, pi, cos, exp, sin, sqrt, ndarray, \
zeros, reshape, transpose, empty
import scipy.sparse as SP
-set_package_path()
-from matlab.mio import loadmat, savemat
-from matlab.mio5 import mat_obj, mat_struct
-restore_path()
+from scipy.io.matlab.mio import loadmat, savemat
+from scipy.io.matlab.mio5 import mat_obj, mat_struct
try: # Python 2.3 support
from sets import Set as set
except:
pass
-test_data_path = os.path.join(os.path.dirname(__file__), './data')
+test_data_path = os.path.join(os.path.dirname(__file__), 'data')
-class TestMIOArray(NumpyTestCase):
- def __init__(self, *args, **kwargs):
- super(TestMIOArray, self).__init__(*args, **kwargs)
+def _check_level(self, label, expected, actual):
+ """ Check one level of a potentially nested object / list """
+ # object array is returned from cell array in mat file
+ typex = type(expected)
+ typac = type(actual)
+ if isinstance(expected, ndarray) and expected.dtype.hasobject:
+ assert typex is typac, "Different types at %s" % label
+ assert len(expected) == len(actual), "Different list lengths at %s" % label
+ for i, ev in enumerate(expected):
+ level_label = "%s, [%d], " % (label, i)
+ self._check_level(level_label, ev, actual[i])
+ return
+ # object, as container for matlab structs and objects
+ elif isinstance(expected, mat_struct) or isinstance(expected, mat_obj):
+ assert isinstance(actual, typex), \
+ "Different types %s and %s at %s" % (typex, typac, label)
+ ex_fields = dir(expected)
+ ac_fields = dir(actual)
+ for k in ex_fields:
+ if k.startswith('__') and k.endswith('__'):
+ continue
+ assert k in ac_fields, "Missing property at %s" % label
+ ev = expected.__dict__[k]
+ v = actual.__dict__[k]
+ level_label = "%s, property %s, " % (label, k)
+ self._check_level(level_label, ev, v)
+ return
+ # hoping this is a single value, which might be an array
+ if SP.issparse(expected):
+ assert SP.issparse(actual), "Expected sparse at %s" % label
+ assert_array_almost_equal(actual.todense(),
+ expected.todense(),
+ err_msg = label,
+ decimal = 5)
+ elif isinstance(expected, ndarray):
+ if expected.shape: # allow scalar and 0d array comparisons
+ assert isinstance(actual, ndarray), "Expected ndarray at %s" % label
+ assert_array_almost_equal(actual, expected, err_msg=label, decimal=5)
+ else:
+ assert isinstance(expected, typac), \
+ "Types %s and %s do not match at %s" % (typex, typac, label)
+ assert_equal(actual, expected, err_msg=label)
- def _check_level(self, label, expected, actual):
- """ Check one level of a potentially nested object / list """
- # object array is returned from cell array in mat file
- typex = type(expected)
- typac = type(actual)
- if isinstance(expected, ndarray) and expected.dtype.hasobject:
- assert typex is typac, "Different types at %s" % label
- assert len(expected) == len(actual), "Different list lengths at %s" % label
- for i, ev in enumerate(expected):
- level_label = "%s, [%d], " % (label, i)
- self._check_level(level_label, ev, actual[i])
- return
- # object, as container for matlab structs and objects
- elif isinstance(expected, mat_struct) or isinstance(expected, mat_obj):
- assert isinstance(actual, typex), \
- "Different types %s and %s at %s" % (typex, typac, label)
- ex_fields = dir(expected)
- ac_fields = dir(actual)
- for k in ex_fields:
- if k.startswith('__') and k.endswith('__'):
- continue
- assert k in ac_fields, "Missing property at %s" % label
- ev = expected.__dict__[k]
- v = actual.__dict__[k]
- level_label = "%s, property %s, " % (label, k)
- self._check_level(level_label, ev, v)
- return
- # hoping this is a single value, which might be an array
- if SP.issparse(expected):
- assert SP.issparse(actual), "Expected sparse at %s" % label
- assert_array_almost_equal(actual.todense(),
- expected.todense(),
- err_msg = label,
- decimal = 5)
- elif isinstance(expected, ndarray):
- if expected.shape: # allow scalar and 0d array comparisons
- assert isinstance(actual, ndarray), "Expected ndarray at %s" % label
- assert_array_almost_equal(actual, expected, err_msg=label, decimal=5)
- else:
- assert isinstance(expected, typac), \
- "Types %s and %s do not match at %s" % (typex, typac, label)
- assert_equal(actual, expected, err_msg=label)
+def _check_case(self, name, files, case):
+ for file_name in files:
+ matdict = loadmat(file_name)
+ label = "test %s; file %s" % (name, file_name)
+ for k, expected in case.items():
+ k_label = "%s, variable %s" % (label, k)
+ assert k in matdict, "Missing key at %s" % k_label
+ self._check_level(k_label, expected, matdict[k])
- def _check_case(self, name, files, case):
- for file_name in files:
- matdict = loadmat(file_name)
- label = "test %s; file %s" % (name, file_name)
- for k, expected in case.items():
- k_label = "%s, variable %s" % (label, k)
- assert k in matdict, "Missing key at %s" % k_label
- self._check_level(k_label, expected, matdict[k])
+# Add the load tests dynamically, with given parameters
+def _make_check_case(name, files, expected):
+ def cc(self):
+ self._check_case(name, files, expected)
+ cc.__doc__ = "check loadmat case %s" % name
+ return cc
- # Add the load tests dynamically, with given parameters
- def _make_check_case(name, files, expected):
- def cc(self):
- self._check_case(name, files, expected)
- cc.__doc__ = "check loadmat case %s" % name
- return cc
+# Add the round trip tests dynamically, with given parameters
+def _make_rt_check_case(name, expected, format):
+ def cc(self):
+ mat_stream = StringIO()
+ savemat(mat_stream, expected, format=format)
+ mat_stream.seek(0)
+ self._check_case(name, [mat_stream], expected)
+ cc.__doc__ = "check loadmat case %s" % name
+ return cc
- # Add the round trip tests dynamically, with given parameters
- def _make_rt_check_case(name, expected, format):
- def cc(self):
- mat_stream = StringIO()
- savemat(mat_stream, expected, format=format)
- mat_stream.seek(0)
- self._check_case(name, [mat_stream], expected)
- cc.__doc__ = "check loadmat case %s" % name
- return cc
+# Define cases to test
+theta = pi/4*arange(9,dtype=float)
+case_table4 = [
+ {'name': 'double',
+ 'expected': {'testdouble': theta}
+ }]
+case_table4.append(
+ {'name': 'string',
+ 'expected': {'teststring': u'"Do nine men interpret?" "Nine men," I nod.'},
+ })
+case_table4.append(
+ {'name': 'complex',
+ 'expected': {'testcomplex': cos(theta) + 1j*sin(theta)}
+ })
+A = zeros((3,5))
+A[0] = range(1,6)
+A[:,0] = range(1,4)
+case_table4.append(
+ {'name': 'matrix',
+ 'expected': {'testmatrix': A},
+ })
+case_table4.append(
+ {'name': 'sparse',
+ 'expected': {'testsparse': SP.csc_matrix(A)},
+ })
+B = A.astype(complex)
+B[0,0] += 1j
+case_table4.append(
+ {'name': 'sparsecomplex',
+ 'expected': {'testsparsecomplex': SP.csc_matrix(B)},
+ })
+case_table4.append(
+ {'name': 'multi',
+ 'expected': {'theta': theta,
+ 'a': A},
+ })
+case_table4.append(
+ {'name': 'minus',
+ 'expected': {'testminus': array(-1)},
+ })
+case_table4.append(
+ {'name': 'onechar',
+ 'expected': {'testonechar': u'r'},
+ })
+case_table5 = [
+ {'name': 'cell',
+ 'expected': {'testcell':
+ array([u'This cell contains this string and 3 arrays of '+\
+ 'increasing length',
+ array(1), array([1,2]), array([1,2,3])],
+ dtype=object)}
+ }]
+case_table5.append(
+ {'name': 'emptycell',
+ 'expected': {'testemptycell':
+ array([array(1), array(2), array([]),
+ array([]), array(3)], dtype=object)}
+ })
+case_table5.append(
+ {'name': 'stringarray',
+ 'expected': {'teststringarray': array(
+ [u'one ', u'two ', u'three'], dtype=object)},
+ })
+case_table5.append(
+ {'name': '3dmatrix',
+ 'expected': {'test3dmatrix': transpose(reshape(range(1,25), (4,3,2)))}
+ })
+case_table5_rt = [
+ {'name': '3dmatrix',
+ 'expected': {'test3dmatrix': transpose(reshape(range(1,25), (4,3,2)))}
+ },
+ {'name': 'sparsefloat',
+ 'expected': {'testsparsefloat': SP.csc_matrix(array([[1,0,2],[0,-3.5,0]]))},
+ },
+ {'name': 'sparsecomplex',
+ 'expected': {'testsparsefloat': SP.csc_matrix(array([[-1+2j,0,2],[0,-3j,0]]))},
+ },
+ ]
+st = mat_struct()
+st.stringfield = u'Rats live on no evil star.'
+st.doublefield = array([sqrt(2),exp(1),pi])
+st.complexfield = (1+1j)*array([sqrt(2),exp(1),pi])
+case_table5.append(
+ {'name': 'struct',
+ 'expected': {'teststruct': st}
+ })
+a = array([array(1),
+ array([array(2), array(3),
+ array([array(4), array(5)],
+ dtype=object)],
+ dtype=object)],
+ dtype=object)
+case_table5.append(
+ {'name': 'cellnest',
+ 'expected': {'testcellnest': a},
+ })
+st = mat_struct()
+st.one = array(1)
+st.two = mat_struct()
+st.two.three = u'number 3'
+case_table5.append(
+ {'name': 'structnest',
+ 'expected': {'teststructnest': st}
+ })
+a = array([mat_struct(), mat_struct()])
+a[0].one = array(1)
+a[0].two = array(2)
+a[1].one = u'number 1'
+a[1].two = u'number 2'
+case_table5.append(
+ {'name': 'structarr',
+ 'expected': {'teststructarr': a}
+ })
+a = mat_obj()
+a._classname = 'inline'
+a.expr = u'x'
+a.inputExpr = u' x = INLINE_INPUTS_{1};'
+a.args = u'x'
+a.isEmpty = array(0)
+a.numArgs = array(1)
+a.version = array(1)
+case_table5.append(
+ {'name': 'object',
+ 'expected': {'testobject': a}
+ })
+u_str = file(
+ os.path.join(test_data_path, 'japanese_utf8.txt'),
+ 'rb').read().decode('utf-8')
+case_table5.append(
+ {'name': 'unicode',
+ 'expected': {'testunicode': u_str}
+ })
- # Define cases to test
- theta = pi/4*arange(9,dtype=float)
- case_table4 = [
- {'name': 'double',
- 'expected': {'testdouble': theta}
- }]
- case_table4.append(
- {'name': 'string',
- 'expected': {'teststring': u'"Do nine men interpret?" "Nine men," I nod.'},
- })
- case_table4.append(
- {'name': 'complex',
- 'expected': {'testcomplex': cos(theta) + 1j*sin(theta)}
- })
- A = zeros((3,5))
- A[0] = range(1,6)
- A[:,0] = range(1,4)
- case_table4.append(
- {'name': 'matrix',
- 'expected': {'testmatrix': A},
- })
- case_table4.append(
- {'name': 'sparse',
- 'expected': {'testsparse': SP.csc_matrix(A)},
- })
- B = A.astype(complex)
- B[0,0] += 1j
- case_table4.append(
- {'name': 'sparsecomplex',
- 'expected': {'testsparsecomplex': SP.csc_matrix(B)},
- })
- case_table4.append(
- {'name': 'multi',
- 'expected': {'theta': theta,
- 'a': A},
- })
- case_table4.append(
- {'name': 'minus',
- 'expected': {'testminus': array(-1)},
- })
- case_table4.append(
- {'name': 'onechar',
- 'expected': {'testonechar': u'r'},
- })
- case_table5 = [
- {'name': 'cell',
- 'expected': {'testcell':
- array([u'This cell contains this string and 3 arrays of '+\
- 'increasing length',
- array(1), array([1,2]), array([1,2,3])],
- dtype=object)}
- }]
- case_table5.append(
- {'name': 'emptycell',
- 'expected': {'testemptycell':
- array([array(1), array(2), array([]),
- array([]), array(3)], dtype=object)}
- })
- case_table5.append(
- {'name': 'stringarray',
- 'expected': {'teststringarray': array(
- [u'one ', u'two ', u'three'], dtype=object)},
- })
- case_table5.append(
- {'name': '3dmatrix',
- 'expected': {'test3dmatrix': transpose(reshape(range(1,25), (4,3,2)))}
- })
- case_table5_rt = [
- {'name': '3dmatrix',
- 'expected': {'test3dmatrix': transpose(reshape(range(1,25), (4,3,2)))}
- },
- {'name': 'sparsefloat',
- 'expected': {'testsparsefloat': SP.csc_matrix(array([[1,0,2],[0,-3.5,0]]))},
- },
- {'name': 'sparsecomplex',
- 'expected': {'testsparsefloat': SP.csc_matrix(array([[-1+2j,0,2],[0,-3j,0]]))},
- },
- ]
- st = mat_struct()
- st.stringfield = u'Rats live on no evil star.'
- st.doublefield = array([sqrt(2),exp(1),pi])
- st.complexfield = (1+1j)*array([sqrt(2),exp(1),pi])
- case_table5.append(
- {'name': 'struct',
- 'expected': {'teststruct': st}
- })
- a = array([array(1),
- array([array(2), array(3),
- array([array(4), array(5)],
- dtype=object)],
- dtype=object)],
- dtype=object)
- case_table5.append(
- {'name': 'cellnest',
- 'expected': {'testcellnest': a},
- })
- st = mat_struct()
- st.one = array(1)
- st.two = mat_struct()
- st.two.three = u'number 3'
- case_table5.append(
- {'name': 'structnest',
- 'expected': {'teststructnest': st}
- })
- a = array([mat_struct(), mat_struct()])
- a[0].one = array(1)
- a[0].two = array(2)
- a[1].one = u'number 1'
- a[1].two = u'number 2'
- case_table5.append(
- {'name': 'structarr',
- 'expected': {'teststructarr': a}
- })
- a = mat_obj()
- a._classname = 'inline'
- a.expr = u'x'
- a.inputExpr = u' x = INLINE_INPUTS_{1};'
- a.args = u'x'
- a.isEmpty = array(0)
- a.numArgs = array(1)
- a.version = array(1)
- case_table5.append(
- {'name': 'object',
- 'expected': {'testobject': a}
- })
- u_str = file(
- os.path.join(test_data_path, 'japanese_utf8.txt'),
- 'rb').read().decode('utf-8')
- case_table5.append(
- {'name': 'unicode',
- 'expected': {'testunicode': u_str}
- })
- # add load tests
+# generator for load tests
+def test_load():
for case in case_table4 + case_table5:
name = case['name']
expected = case['expected']
filt = os.path.join(test_data_path, 'test%s_*.mat' % name)
files = glob(filt)
assert files, "No files for test %s using filter %s" % (name, filt)
- exec 'check_%s = _make_check_case(name, files, expected)' % name
+ yield _make_check_case, name, files, expected
+
# round trip tests
+def test_round_trip():
for case in case_table4 + case_table5_rt:
name = case['name'] + '_round_trip'
expected = case['expected']
format = case in case_table4 and '4' or '5'
- exec 'check_%s = _make_rt_check_case(name, expected, format)' \
- % name
+ yield _make_rt_check_case, name, expected, format
-if __name__ == "__main__":
- NumpyTest().run()
Modified: trunk/scipy/lib/__init__.py
===================================================================
--- trunk/scipy/lib/__init__.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/lib/__init__.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -1,5 +1,5 @@
from info import __doc__, __all__
-from numpy.testing import NumpyTest
-test = NumpyTest().test
+from scipy.testing.pkgtester import Tester
+test = Tester().test
Modified: trunk/scipy/lib/blas/__init__.py
===================================================================
--- trunk/scipy/lib/blas/__init__.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/lib/blas/__init__.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -58,5 +58,5 @@
funcs.append(func)
return tuple(funcs)
-from numpy.testing import NumpyTest
-test = NumpyTest().test
+from scipy.testing.pkgtester import Tester
+test = Tester().test
Modified: trunk/scipy/lib/blas/tests/test_blas.py
===================================================================
--- trunk/scipy/lib/blas/tests/test_blas.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/lib/blas/tests/test_blas.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -12,21 +12,18 @@
python tests/test_blas.py [<level>]
"""
+import sys
+import math
from numpy import arange, add, array
-import math
+from scipy.testing import *
+from scipy.lib.blas import fblas
+from scipy.lib.blas import cblas
+from scipy.lib.blas import get_blas_funcs
-import sys
-from numpy.testing import *
-set_package_path()
-from blas import fblas
-from blas import cblas
-from blas import get_blas_funcs
-restore_path()
+class TestCBLAS1Simple(TestCase):
-class TestCBLAS1Simple(NumpyTestCase):
-
- def check_axpy(self):
+ def test_axpy(self):
for p in 'sd':
f = getattr(cblas,p+'axpy',None)
if f is None: continue
@@ -36,9 +33,9 @@
if f is None: continue
assert_array_almost_equal(f([1,2j,3],[2,-1,3],a=5),[7,10j-1,18])
-class TestFBLAS1Simple(NumpyTestCase):
+class TestFBLAS1Simple(TestCase):
- def check_axpy(self):
+ def test_axpy(self):
for p in 'sd':
f = getattr(fblas,p+'axpy',None)
if f is None: continue
@@ -47,7 +44,7 @@
f = getattr(fblas,p+'axpy',None)
if f is None: continue
assert_array_almost_equal(f([1,2j,3],[2,-1,3],a=5),[7,10j-1,18])
- def check_copy(self):
+ def test_copy(self):
for p in 'sd':
f = getattr(fblas,p+'copy',None)
if f is None: continue
@@ -56,7 +53,7 @@
f = getattr(fblas,p+'copy',None)
if f is None: continue
assert_array_almost_equal(f([3,4j,5+3j],[8]*3),[3,4j,5+3j])
- def check_asum(self):
+ def test_asum(self):
for p in 'sd':
f = getattr(fblas,p+'asum',None)
if f is None: continue
@@ -65,7 +62,7 @@
f = getattr(fblas,p+'asum',None)
if f is None: continue
assert_almost_equal(f([3j,-4,3-4j]),14)
- def check_dot(self):
+ def test_dot(self):
for p in 'sd':
f = getattr(fblas,p+'dot',None)
if f is None: continue
@@ -76,7 +73,7 @@
assert_almost_equal(f([3j,-4,3-4j],[2,3,1]),-9+2j)
f = getattr(fblas,p+'dotc')
assert_almost_equal(f([3j,-4,3-4j],[2,3j,1]),3-14j)
- def check_nrm2(self):
+ def test_nrm2(self):
for p in 'sd':
f = getattr(fblas,p+'nrm2',None)
if f is None: continue
@@ -85,7 +82,7 @@
f = getattr(fblas,p+'nrm2',None)
if f is None: continue
assert_almost_equal(f([3j,-4,3-4j]),math.sqrt(50))
- def check_scal(self):
+ def test_scal(self):
for p in 'sd':
f = getattr(fblas,p+'scal',None)
if f is None: continue
@@ -98,7 +95,7 @@
f = getattr(fblas,p+'scal',None)
if f is None: continue
assert_array_almost_equal(f(3,[3j,-4,3-4j]),[9j,-12,9-12j])
- def check_swap(self):
+ def test_swap(self):
for p in 'sd':
f = getattr(fblas,p+'swap',None)
if f is None: continue
@@ -113,7 +110,7 @@
x1,y1 = f(x,y)
assert_array_almost_equal(x1,y)
assert_array_almost_equal(y1,x)
- def check_amax(self):
+ def test_amax(self):
for p in 'sd':
f = getattr(fblas,'i'+p+'amax')
assert_equal(f([-2,4,3]),1)
@@ -122,9 +119,9 @@
assert_equal(f([-5,4+3j,6]),1)
#XXX: need tests for rot,rotm,rotg,rotmg
-class TestFBLAS2Simple(NumpyTestCase):
+class TestFBLAS2Simple(TestCase):
- def check_gemv(self):
+ def test_gemv(self):
for p in 'sd':
f = getattr(fblas,p+'gemv',None)
if f is None: continue
@@ -136,7 +133,7 @@
assert_array_almost_equal(f(3j,[[3-4j]],[-4]),[-48-36j])
assert_array_almost_equal(f(3j,[[3-4j]],[-4],3,[5j]),[-48-21j])
- def check_ger(self):
+ def test_ger(self):
for p in 'sd':
f = getattr(fblas,p+'ger',None)
@@ -170,9 +167,9 @@
2j,
3j],[3j,4j]),[[6,8],[12,16],[18,24]])
-class TestFBLAS3Simple(NumpyTestCase):
+class TestFBLAS3Simple(TestCase):
- def check_gemm(self):
+ def test_gemm(self):
for p in 'sd':
f = getattr(fblas,p+'gemm',None)
if f is None: continue
@@ -188,22 +185,22 @@
assert_array_almost_equal(f(1,[[1,2],[1,2]],[[3],[4]]),[[11],[11]])
assert_array_almost_equal(f(1,[[1,2]],[[3,3],[4,4]]),[[11,11]])
- def check_gemm2(self):
+ def test_gemm2(self):
for p in 'sdcz':
f = getattr(fblas,p+'gemm',None)
if f is None: continue
assert_array_almost_equal(f(1,[[1,2]],[[3],[4]]),[[11]])
assert_array_almost_equal(f(1,[[1,2],[1,2]],[[3],[4]]),[[11],[11]])
-class TestBLAS(NumpyTestCase):
+class TestBLAS(TestCase):
- def check_blas(self):
+ def test_blas(self):
a = array([[1,1,1]])
b = array([[1],[1],[1]])
gemm, = get_blas_funcs(('gemm',),(a,b))
assert_array_almost_equal(gemm(1,a,b),[[3]],15)
- def check_fblas(self):
+ def test_fblas(self):
if hasattr(fblas,'empty_module'):
print """
****************************************************************
@@ -212,7 +209,7 @@
See scipy/INSTALL.txt for troubleshooting.
****************************************************************
"""
- def check_cblas(self):
+ def test_cblas(self):
if hasattr(cblas,'empty_module'):
print """
****************************************************************
@@ -226,4 +223,4 @@
"""
if __name__ == "__main__":
- NumpyTest().run()
+ unittest.main()
Modified: trunk/scipy/lib/blas/tests/test_fblas.py
===================================================================
--- trunk/scipy/lib/blas/tests/test_fblas.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/lib/blas/tests/test_fblas.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -6,13 +6,12 @@
# !! Complex calculations really aren't checked that carefully.
# !! Only real valued complex numbers are used in tests.
-from numpy import *
-
import sys
-from numpy.testing import *
-set_package_path()
-from blas import fblas
-restore_path()
+from numpy import zeros, transpose, newaxis, shape, float32, \
+ float64, complex64, complex128, arange, array, common_type, \
+ conjugate
+from scipy.testing import *
+from scipy.lib.blas import fblas
#decimal accuracy to require between Python and LAPACK/BLAS calculations
accuracy = 5
@@ -40,39 +39,40 @@
##################################################
### Test blas ?axpy
-class BaseAxpy(NumpyTestCase):
- def check_default_a(self):
+class BaseAxpy(object):
+ # Mixin class to test dtypes
+ def test_default_a(self):
x = arange(3.,dtype=self.dtype)
y = arange(3.,dtype=x.dtype)
real_y = x*1.+y
self.blas_func(x,y)
assert_array_almost_equal(real_y,y)
- def check_simple(self):
+ def test_simple(self):
x = arange(3.,dtype=self.dtype)
y = arange(3.,dtype=x.dtype)
real_y = x*3.+y
self.blas_func(x,y,a=3.)
assert_array_almost_equal(real_y,y)
- def check_x_stride(self):
+ def test_x_stride(self):
x = arange(6.,dtype=self.dtype)
y = zeros(3,x.dtype)
y = arange(3.,dtype=x.dtype)
real_y = x[::2]*3.+y
self.blas_func(x,y,a=3.,n=3,incx=2)
assert_array_almost_equal(real_y,y)
- def check_y_stride(self):
+ def test_y_stride(self):
x = arange(3.,dtype=self.dtype)
y = zeros(6,x.dtype)
real_y = x*3.+y[::2]
self.blas_func(x,y,a=3.,n=3,incy=2)
assert_array_almost_equal(real_y,y[::2])
- def check_x_and_y_stride(self):
+ def test_x_and_y_stride(self):
x = arange(12.,dtype=self.dtype)
y = zeros(6,x.dtype)
real_y = x[::4]*3.+y[::2]
self.blas_func(x,y,a=3.,n=3,incx=4,incy=2)
assert_array_almost_equal(real_y,y[::2])
- def check_x_bad_size(self):
+ def test_x_bad_size(self):
x = arange(12.,dtype=self.dtype)
y = zeros(6,x.dtype)
try:
@@ -81,7 +81,7 @@
return
# should catch error and never get here
assert(0)
- def check_y_bad_size(self):
+ def test_y_bad_size(self):
x = arange(12.,dtype=complex64)
y = zeros(6,x.dtype)
try:
@@ -92,21 +92,21 @@
assert(0)
try:
- class TestSaxpy(BaseAxpy):
+ class TestSaxpy(TestCase, BaseAxpy):
blas_func = fblas.saxpy
dtype = float32
except AttributeError:
class TestSaxpy: pass
-class TestDaxpy(BaseAxpy):
+class TestDaxpy(TestCase, BaseAxpy):
blas_func = fblas.daxpy
dtype = float64
try:
- class TestCaxpy(BaseAxpy):
+ class TestCaxpy(TestCase, BaseAxpy):
blas_func = fblas.caxpy
dtype = complex64
except AttributeError:
class TestCaxpy: pass
-class TestZaxpy(BaseAxpy):
+class TestZaxpy(TestCase, BaseAxpy):
blas_func = fblas.zaxpy
dtype = complex128
@@ -114,19 +114,20 @@
##################################################
### Test blas ?scal
-class BaseScal(NumpyTestCase):
- def check_simple(self):
+class BaseScal(object):
+ # Mixin class for testing particular dtypes
+ def test_simple(self):
x = arange(3.,dtype=self.dtype)
real_x = x*3.
self.blas_func(3.,x)
assert_array_almost_equal(real_x,x)
- def check_x_stride(self):
+ def test_x_stride(self):
x = arange(6.,dtype=self.dtype)
real_x = x.copy()
real_x[::2] = x[::2]*array(3.,self.dtype)
self.blas_func(3.,x,n=3,incx=2)
assert_array_almost_equal(real_x,x)
- def check_x_bad_size(self):
+ def test_x_bad_size(self):
x = arange(12.,dtype=self.dtype)
try:
self.blas_func(2.,x,n=4,incx=5)
@@ -135,21 +136,21 @@
# should catch error and never get here
assert(0)
try:
- class TestSscal(BaseScal):
+ class TestSscal(TestCase, BaseScal):
blas_func = fblas.sscal
dtype = float32
except AttributeError:
class TestSscal: pass
-class TestDscal(BaseScal):
+class TestDscal(TestCase, BaseScal):
blas_func = fblas.dscal
dtype = float64
try:
- class TestCscal(BaseScal):
+ class TestCscal(TestCase, BaseScal):
blas_func = fblas.cscal
dtype = complex64
except AttributeError:
class TestCscal: pass
-class TestZscal(BaseScal):
+class TestZscal(TestCase, BaseScal):
blas_func = fblas.zscal
dtype = complex128
@@ -159,28 +160,29 @@
##################################################
### Test blas ?copy
-class BaseCopy(NumpyTestCase):
- def check_simple(self):
+class BaseCopy(object):
+ # Mixin class for testing dtypes
+ def test_simple(self):
x = arange(3.,dtype=self.dtype)
y = zeros(shape(x),x.dtype)
self.blas_func(x,y)
assert_array_almost_equal(x,y)
- def check_x_stride(self):
+ def test_x_stride(self):
x = arange(6.,dtype=self.dtype)
y = zeros(3,x.dtype)
self.blas_func(x,y,n=3,incx=2)
assert_array_almost_equal(x[::2],y)
- def check_y_stride(self):
+ def test_y_stride(self):
x = arange(3.,dtype=self.dtype)
y = zeros(6,x.dtype)
self.blas_func(x,y,n=3,incy=2)
assert_array_almost_equal(x,y[::2])
- def check_x_and_y_stride(self):
+ def test_x_and_y_stride(self):
x = arange(12.,dtype=self.dtype)
y = zeros(6,x.dtype)
self.blas_func(x,y,n=3,incx=4,incy=2)
assert_array_almost_equal(x[::4],y[::2])
- def check_x_bad_size(self):
+ def test_x_bad_size(self):
x = arange(12.,dtype=self.dtype)
y = zeros(6,x.dtype)
try:
@@ -189,7 +191,7 @@
return
# should catch error and never get here
assert(0)
- def check_y_bad_size(self):
+ def test_y_bad_size(self):
x = arange(12.,dtype=complex64)
y = zeros(6,x.dtype)
try:
@@ -198,7 +200,7 @@
return
# should catch error and never get here
assert(0)
- #def check_y_bad_type(self):
+ #def test_y_bad_type(self):
## Hmmm. Should this work? What should be the output.
# x = arange(3.,dtype=self.dtype)
# y = zeros(shape(x))
@@ -206,21 +208,21 @@
# assert_array_almost_equal(x,y)
try:
- class TestScopy(BaseCopy):
+ class TestScopy(TestCase, BaseCopy):
blas_func = fblas.scopy
dtype = float32
except AttributeError:
class TestScopy: pass
-class TestDcopy(BaseCopy):
+class TestDcopy(TestCase, BaseCopy):
blas_func = fblas.dcopy
dtype = float64
try:
- class TestCcopy(BaseCopy):
+ class TestCcopy(TestCase, BaseCopy):
blas_func = fblas.ccopy
dtype = complex64
except AttributeError:
class TestCcopy: pass
-class TestZcopy(BaseCopy):
+class TestZcopy(TestCase, BaseCopy):
blas_func = fblas.zcopy
dtype = complex128
@@ -228,8 +230,9 @@
##################################################
### Test blas ?swap
-class BaseSwap(NumpyTestCase):
- def check_simple(self):
+class BaseSwap(object):
+ # Mixin class to implement test objects
+ def test_simple(self):
x = arange(3.,dtype=self.dtype)
y = zeros(shape(x),x.dtype)
desired_x = y.copy()
@@ -237,7 +240,7 @@
self.blas_func(x,y)
assert_array_almost_equal(desired_x,x)
assert_array_almost_equal(desired_y,y)
- def check_x_stride(self):
+ def test_x_stride(self):
x = arange(6.,dtype=self.dtype)
y = zeros(3,x.dtype)
desired_x = y.copy()
@@ -245,7 +248,7 @@
self.blas_func(x,y,n=3,incx=2)
assert_array_almost_equal(desired_x,x[::2])
assert_array_almost_equal(desired_y,y)
- def check_y_stride(self):
+ def test_y_stride(self):
x = arange(3.,dtype=self.dtype)
y = zeros(6,x.dtype)
desired_x = y.copy()[::2]
@@ -254,7 +257,7 @@
assert_array_almost_equal(desired_x,x)
assert_array_almost_equal(desired_y,y[::2])
- def check_x_and_y_stride(self):
+ def test_x_and_y_stride(self):
x = arange(12.,dtype=self.dtype)
y = zeros(6,x.dtype)
desired_x = y.copy()[::2]
@@ -262,7 +265,7 @@
self.blas_func(x,y,n=3,incx=4,incy=2)
assert_array_almost_equal(desired_x,x[::4])
assert_array_almost_equal(desired_y,y[::2])
- def check_x_bad_size(self):
+ def test_x_bad_size(self):
x = arange(12.,dtype=self.dtype)
y = zeros(6,x.dtype)
try:
@@ -271,7 +274,7 @@
return
# should catch error and never get here
assert(0)
- def check_y_bad_size(self):
+ def test_y_bad_size(self):
x = arange(12.,dtype=complex64)
y = zeros(6,x.dtype)
try:
@@ -282,21 +285,21 @@
assert(0)
try:
- class TestSswap(BaseSwap):
+ class TestSswap(TestCase, BaseSwap):
blas_func = fblas.sswap
dtype = float32
except AttributeError:
class TestSswap: pass
-class TestDswap(BaseSwap):
+class TestDswap(TestCase, BaseSwap):
blas_func = fblas.dswap
dtype = float64
try:
- class TestCswap(BaseSwap):
+ class TestCswap(TestCase, BaseSwap):
blas_func = fblas.cswap
dtype = complex64
except AttributeError:
class TestCswap: pass
-class TestZswap(BaseSwap):
+class TestZswap(TestCase, BaseSwap):
blas_func = fblas.zswap
dtype = complex128
@@ -304,7 +307,8 @@
### Test blas ?gemv
### This will be a mess to test all cases.
-class BaseGemv(NumpyTestCase):
+class BaseGemv(object):
+ # Mixin class to test dtypes
def get_data(self,x_stride=1,y_stride=1):
mult = array(1, dtype = self.dtype)
if self.dtype in [complex64, complex128]:
@@ -316,37 +320,37 @@
x = arange(shape(a)[0]*x_stride,dtype=self.dtype) * mult
y = arange(shape(a)[1]*y_stride,dtype=self.dtype) * mult
return alpha,beta,a,x,y
- def check_simple(self):
+ def test_simple(self):
alpha,beta,a,x,y = self.get_data()
desired_y = alpha*matrixmultiply(a,x)+beta*y
y = self.blas_func(alpha,a,x,beta,y)
assert_array_almost_equal(desired_y,y)
- def check_default_beta_y(self):
+ def test_default_beta_y(self):
alpha,beta,a,x,y = self.get_data()
desired_y = matrixmultiply(a,x)
y = self.blas_func(1,a,x)
assert_array_almost_equal(desired_y,y)
- def check_simple_transpose(self):
+ def test_simple_transpose(self):
alpha,beta,a,x,y = self.get_data()
desired_y = alpha*matrixmultiply(transpose(a),x)+beta*y
y = self.blas_func(alpha,a,x,beta,y,trans=1)
assert_array_almost_equal(desired_y,y)
- def check_simple_transpose_conj(self):
+ def test_simple_transpose_conj(self):
alpha,beta,a,x,y = self.get_data()
desired_y = alpha*matrixmultiply(transpose(conjugate(a)),x)+beta*y
y = self.blas_func(alpha,a,x,beta,y,trans=2)
assert_array_almost_equal(desired_y,y)
- def check_x_stride(self):
+ def test_x_stride(self):
alpha,beta,a,x,y = self.get_data(x_stride=2)
desired_y = alpha*matrixmultiply(a,x[::2])+beta*y
y = self.blas_func(alpha,a,x,beta,y,incx=2)
assert_array_almost_equal(desired_y,y)
- def check_x_stride_transpose(self):
+ def test_x_stride_transpose(self):
alpha,beta,a,x,y = self.get_data(x_stride=2)
desired_y = alpha*matrixmultiply(transpose(a),x[::2])+beta*y
y = self.blas_func(alpha,a,x,beta,y,trans=1,incx=2)
assert_array_almost_equal(desired_y,y)
- def check_x_stride_assert(self):
+ def test_x_stride_assert(self):
# What is the use of this test?
alpha,beta,a,x,y = self.get_data(x_stride=2)
try:
@@ -359,19 +363,19 @@
assert(0)
except:
pass
- def check_y_stride(self):
+ def test_y_stride(self):
alpha,beta,a,x,y = self.get_data(y_stride=2)
desired_y = y.copy()
desired_y[::2] = alpha*matrixmultiply(a,x)+beta*y[::2]
y = self.blas_func(alpha,a,x,beta,y,incy=2)
assert_array_almost_equal(desired_y,y)
- def check_y_stride_transpose(self):
+ def test_y_stride_transpose(self):
alpha,beta,a,x,y = self.get_data(y_stride=2)
desired_y = y.copy()
desired_y[::2] = alpha*matrixmultiply(transpose(a),x)+beta*y[::2]
y = self.blas_func(alpha,a,x,beta,y,trans=1,incy=2)
assert_array_almost_equal(desired_y,y)
- def check_y_stride_assert(self):
+ def test_y_stride_assert(self):
# What is the use of this test?
alpha,beta,a,x,y = self.get_data(y_stride=2)
try:
@@ -386,21 +390,21 @@
pass
try:
- class TestSgemv(BaseGemv):
+ class TestSgemv(TestCase, BaseGemv):
blas_func = fblas.sgemv
dtype = float32
except AttributeError:
class TestSgemv: pass
-class TestDgemv(BaseGemv):
+class TestDgemv(TestCase, BaseGemv):
blas_func = fblas.dgemv
dtype = float64
try:
- class TestCgemv(BaseGemv):
+ class TestCgemv(TestCase, BaseGemv):
blas_func = fblas.cgemv
dtype = complex64
except AttributeError:
class TestCgemv: pass
-class TestZgemv(BaseGemv):
+class TestZgemv(TestCase, BaseGemv):
blas_func = fblas.zgemv
dtype = complex128
@@ -409,7 +413,7 @@
### Test blas ?ger
### This will be a mess to test all cases.
-class BaseGer(NumpyTestCase):
+class BaseGer(TestCase):
def get_data(self,x_stride=1,y_stride=1):
from numpy.random import normal
alpha = array(1., dtype = self.dtype)
@@ -417,31 +421,31 @@
x = arange(shape(a)[0]*x_stride,dtype=self.dtype)
y = arange(shape(a)[1]*y_stride,dtype=self.dtype)
return alpha,a,x,y
- def check_simple(self):
+ def test_simple(self):
alpha,a,x,y = self.get_data()
# tranpose takes care of Fortran vs. C(and Python) memory layout
desired_a = alpha*transpose(x[:,newaxis]*y) + a
self.blas_func(x,y,a)
assert_array_almost_equal(desired_a,a)
- def check_x_stride(self):
+ def test_x_stride(self):
alpha,a,x,y = self.get_data(x_stride=2)
desired_a = alpha*transpose(x[::2,newaxis]*y) + a
self.blas_func(x,y,a,incx=2)
assert_array_almost_equal(desired_a,a)
- def check_x_stride_assert(self):
+ def test_x_stride_assert(self):
alpha,a,x,y = self.get_data(x_stride=2)
try:
self.blas_func(x,y,a,incx=3)
assert(0)
except:
pass
- def check_y_stride(self):
+ def test_y_stride(self):
alpha,a,x,y = self.get_data(y_stride=2)
desired_a = alpha*transpose(x[:,newaxis]*y[::2]) + a
self.blas_func(x,y,a,incy=2)
assert_array_almost_equal(desired_a,a)
- def check_y_stride_assert(self):
+ def test_y_stride_assert(self):
alpha,a,x,y = self.get_data(y_stride=2)
try:
self.blas_func(a,x,y,incy=3)
@@ -472,7 +476,7 @@
y = normal(0.,1.,shape(a)[1]*y_stride).astype(self.dtype)
y = y + y * array(1j, dtype = self.dtype)
return alpha,a,x,y
- def check_simple(self):
+ def test_simple(self):
alpha,a,x,y = self.get_data()
# tranpose takes care of Fortran vs. C(and Python) memory layout
a = a * array(0.,dtype = self.dtype)
@@ -482,12 +486,12 @@
fblas.cgeru(x,y,a,alpha = alpha)
assert_array_almost_equal(desired_a,a)
- #def check_x_stride(self):
+ #def test_x_stride(self):
# alpha,a,x,y = self.get_data(x_stride=2)
# desired_a = alpha*transpose(x[::2,newaxis]*self.transform(y)) + a
# self.blas_func(x,y,a,incx=2)
# assert_array_almost_equal(desired_a,a)
- #def check_y_stride(self):
+ #def test_y_stride(self):
# alpha,a,x,y = self.get_data(y_stride=2)
# desired_a = alpha*transpose(x[:,newaxis]*self.transform(y[::2])) + a
# self.blas_func(x,y,a,incy=2)
@@ -518,4 +522,4 @@
"""
if __name__ == "__main__":
- NumpyTest().run()
+ unittest.main()
Modified: trunk/scipy/lib/lapack/__init__.py
===================================================================
--- trunk/scipy/lib/lapack/__init__.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/lib/lapack/__init__.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -90,5 +90,5 @@
func_code = %(func_name)s.func_code
'''
-from numpy.testing import NumpyTest
-test = NumpyTest().test
+from scipy.testing.pkgtester import Tester
+test = Tester().test
Modified: trunk/scipy/lib/lapack/tests/esv_tests.py
===================================================================
--- trunk/scipy/lib/lapack/tests/esv_tests.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/lib/lapack/tests/esv_tests.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -1,10 +1,10 @@
-from numpy.testing import *
-from numpy import *
+from scipy.testing import *
+from numpy import dot
-class _test_ev:
+class _test_ev(object):
- def check_syev(self,level=1,sym='sy',suffix=''):
+ def check_syev(self,sym='sy',suffix=''):
a = [[1,2,3],[2,2,3],[3,3,6]]
exact_w = [-0.6699243371851365,0.4876938861533345,9.182230451031804]
f = getattr(self.lapack,sym+'ev'+suffix)
@@ -20,7 +20,7 @@
#def check_heevd(self): self.check_syev(sym='he',suffix='d')
-## def check_heev_complex(self,level=1,suffix=''):
+## def check_heev_complex(self,suffix=''):
## a= [[1,2-2j,3+7j],[2+2j,2,3],[3-7j,3,5]]
## exact_w=[-6.305141710654834,2.797880950890922,11.50726075976392]
## f = getattr(self.lapack,'heev'+suffix)
@@ -32,7 +32,7 @@
#def check_heevd_complex(self): self.check_heev_complex(suffix='d')
- def check_syevr(self,level=1,sym='sy'):
+ def check_syevr(self,sym='sy'):
a = [[1,2,3],[2,2,3],[3,3,6]]
exact_w = [-0.6699243371851365,0.4876938861533345,9.182230451031804]
f = getattr(self.lapack,sym+'evr')
@@ -42,7 +42,7 @@
for i in range(3):
assert_array_almost_equal(dot(a,v[:,i]),w[i]*v[:,i])
-## def check_heevr_complex(self,level=1):
+## def check_heevr_complex(self):
## a= [[1,2-2j,3+7j],[2+2j,2,3],[3-7j,3,5]]
## exact_w=[-6.305141710654834,2.797880950890922,11.50726075976392]
## f = self.lapack.heevr
@@ -54,7 +54,7 @@
## def check_heevr(self): self.check_syevr(sym='he')
- def check_syevr_irange(self,level=1,sym='sy',irange=[0,2]):
+ def check_syevr_irange(self,sym='sy',irange=[0,2]):
a = [[1,2,3],[2,2,3],[3,3,6]]
exact_w = [-0.6699243371851365,0.4876938861533345,9.182230451031804]
f = getattr(self.lapack,sym+'evr')
@@ -79,7 +79,7 @@
## def check_heevr_irange_high(self): self.check_syevr_irange(sym='he',irange=[1,2])
- def check_syevr_vrange(self,level=1,sym='sy',vrange=None):
+ def check_syevr_vrange(self,sym='sy',vrange=None):
a = [[1,2,3],[2,2,3],[3,3,6]]
exact_w = [-0.6699243371851365,0.4876938861533345,9.182230451031804]
if vrange is None:
Modified: trunk/scipy/lib/lapack/tests/gesv_tests.py
===================================================================
--- trunk/scipy/lib/lapack/tests/gesv_tests.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/lib/lapack/tests/gesv_tests.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -1,10 +1,10 @@
-from numpy.testing import *
-from numpy import *
+from scipy.testing import *
+from numpy import dot
-class _test_gev:
+class _test_gev(object):
- def check_sygv(self,level=1,sym='sy',suffix='',itype=1):
+ def check_sygv(self,sym='sy',suffix='',itype=1):
a = [[1,2,3],[2,2,3],[3,3,6]]
b = [[10,-1,1],[-1,8,-2],[1,-2,6]]
f = getattr(self.lapack,sym+'gv'+suffix)
Modified: trunk/scipy/lib/lapack/tests/test_lapack.py
===================================================================
--- trunk/scipy/lib/lapack/tests/test_lapack.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/lib/lapack/tests/test_lapack.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -2,33 +2,33 @@
#
# Created by: Pearu Peterson, September 2002
#
+'''
+This file adapted for nose tests 1/1/08
-__usage__ = """
-Build lapack:
- python setup_lapack.py build
-Run tests if scipy is installed:
- python -c 'import scipy;scipy.lib.lapack.test(<level>)'
-Run tests if lapack is not installed:
- python tests/test_lapack.py [<level>]
-"""
+Note that the conversion is not very complete.
+This and the included files deliberately use "check_" as the test
+method names. There are no subclasses of TestCase. Thus nose will
+pick up nothing but the final test_all_lapack generator function.
+This does the work of collecting the test methods and checking if they
+can be run (see the isrunnable method).
+'''
+
+import os
import sys
-from numpy.testing import *
-from numpy import *
+from scipy.testing import *
+from numpy import dot, ones, zeros
-set_package_path()
-from lapack import flapack,clapack
-restore_path()
+from scipy.lib.lapack import flapack, clapack
-set_local_path()
+sys.path.insert(0, os.path.split(__file__))
from gesv_tests import _test_gev
from esv_tests import _test_ev
-restore_path()
+del sys.path[0]
#class _test_ev: pass
-class _TestLapack(NumpyTestCase,
- _test_ev,
+class _TestLapack( _test_ev,
_test_gev):
def check_gebal(self):
@@ -57,12 +57,13 @@
assert not info,`info`
def isrunnable(self,mthname):
+ ''' Return True if required routines for check method present in module '''
l = mthname.split('_')
if len(l)>1 and l[0]=='check':
return hasattr(self.lapack,l[1])
return 2
-class PrefixWrapper:
+class PrefixWrapper(object):
def __init__(self,module,prefix):
self.module = module
self.prefix = prefix
@@ -122,5 +123,18 @@
lapack = PrefixWrapper(clapack,'z')
decimal = 12
-if __name__ == "__main__":
- NumpyTest().run()
+# Collect test classes and methods with generator
+# This is a moderate hack replicating some obscure numpy testing
+# functionality for use with nose
+
+def test_all_lapack():
+ methods = []
+ for name, value in globals().items():
+ if not (name.startswith('Test')
+ and issubclass(value, _TestLapack)):
+ continue
+ o = value()
+ methods += [getattr(o, n) for n in dir(o) if o.isrunnable(n) is True]
+ for method in methods:
+ yield (method, )
+
Modified: trunk/scipy/linalg/__init__.py
===================================================================
--- trunk/scipy/linalg/__init__.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/linalg/__init__.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -28,5 +28,5 @@
del k, register_func
-from numpy.testing import NumpyTest
-test = NumpyTest().test
+from scipy.testing.pkgtester import Tester
+test = Tester().test
Modified: trunk/scipy/linalg/tests/test_atlas_version.py
===================================================================
--- trunk/scipy/linalg/tests/test_atlas_version.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/linalg/tests/test_atlas_version.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -4,10 +4,10 @@
#
import sys
-from numpy.testing import *
-set_package_path()
-import linalg.atlas_version
-restore_path()
+from scipy.testing import *
+import scipy.linalg.atlas_version
+
+
# No futher tests possible.
# Importing atlas_version will print out atlas version.
Modified: trunk/scipy/linalg/tests/test_basic.py
===================================================================
--- trunk/scipy/linalg/tests/test_basic.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/linalg/tests/test_basic.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -14,21 +14,21 @@
Build linalg:
python setup_linalg.py build
Run tests if scipy is installed:
- python -c 'import scipy;scipy.linalg.test(<level>)'
+ python -c 'import scipy;scipy.linalg.test()'
Run tests if linalg is not installed:
- python tests/test_basic.py [<level>]
+ python tests/test_basic.py
"""
import numpy
from numpy import arange, add, array, dot, zeros, identity, conjugate, transpose
import sys
-from numpy.testing import *
-set_package_path()
-from linalg import solve,inv,det,lstsq, toeplitz, hankel, tri, triu, tril
-from linalg import pinv, pinv2, solve_banded
-restore_path()
+from scipy.testing import *
+from scipy.linalg import solve,inv,det,lstsq, toeplitz, hankel, tri, triu, \
+ tril, pinv, pinv2, solve_banded
+
+
def random(size):
return rand(*size)
@@ -37,9 +37,9 @@
data = add.outer(data,data)
return data
-class TestSolveBanded(NumpyTestCase):
+class TestSolveBanded(TestCase):
- def check_simple(self):
+ def test_simple(self):
a = [[1,20,0,0],[-30,4,6,0],[2,1,20,2],[0,-1,7,14]]
ab = [[0,20,6,2],
@@ -52,9 +52,9 @@
x = solve_banded((l,u),ab,b)
assert_array_almost_equal(numpy.dot(a,x),b)
-class TestSolve(NumpyTestCase):
+class TestSolve(TestCase):
- def check_20Feb04_bug(self):
+ def test_20Feb04_bug(self):
a = [[1,1],[1.0,0]] # ok
x0 = solve(a,[1,0j])
assert_array_almost_equal(numpy.dot(a,x0),[1,0])
@@ -64,21 +64,21 @@
x0 = solve(a,b)
assert_array_almost_equal(numpy.dot(a,x0),[1,0])
- def check_simple(self):
+ def test_simple(self):
a = [[1,20],[-30,4]]
for b in ([[1,0],[0,1]],[1,0],
[[2,1],[-30,4]]):
x = solve(a,b)
assert_array_almost_equal(numpy.dot(a,x),b)
- def check_simple_sym(self):
+ def test_simple_sym(self):
a = [[2,3],[3,5]]
for lower in [0,1]:
for b in ([[1,0],[0,1]],[1,0]):
x = solve(a,b,sym_pos=1,lower=lower)
assert_array_almost_equal(numpy.dot(a,x),b)
- def check_simple_sym_complex(self):
+ def test_simple_sym_complex(self):
a = [[5,2],[2,4]]
for b in [[1j,0],
[[1j,1j],
@@ -87,7 +87,7 @@
x = solve(a,b,sym_pos=1)
assert_array_almost_equal(numpy.dot(a,x),b)
- def check_simple_complex(self):
+ def test_simple_complex(self):
a = array([[5,2],[2j,4]],'D')
for b in [[1j,0],
[[1j,1j],
@@ -98,7 +98,7 @@
x = solve(a,b)
assert_array_almost_equal(numpy.dot(a,x),b)
- def check_nils_20Feb04(self):
+ def test_nils_20Feb04(self):
n = 2
A = random([n,n])+random([n,n])*1j
X = zeros((n,n),'D')
@@ -109,7 +109,7 @@
X[:,i] = solve(A,r)
assert_array_almost_equal(X,Ainv)
- def check_random(self):
+ def test_random(self):
n = 20
a = random([n,n])
@@ -119,7 +119,7 @@
x = solve(a,b)
assert_array_almost_equal(numpy.dot(a,x),b)
- def check_random_complex(self):
+ def test_random_complex(self):
n = 20
a = random([n,n]) + 1j * random([n,n])
for i in range(n): a[i,i] = 20*(.1+a[i,i])
@@ -128,7 +128,7 @@
x = solve(a,b)
assert_array_almost_equal(numpy.dot(a,x),b)
- def check_random_sym(self):
+ def test_random_sym(self):
n = 20
a = random([n,n])
for i in range(n):
@@ -140,7 +140,7 @@
x = solve(a,b,sym_pos=1)
assert_array_almost_equal(numpy.dot(a,x),b)
- def check_random_sym_complex(self):
+ def test_random_sym_complex(self):
n = 20
a = random([n,n])
#a = a + 1j*random([n,n]) # XXX: with this the accuracy will be very low
@@ -153,7 +153,8 @@
x = solve(a,b,sym_pos=1)
assert_array_almost_equal(numpy.dot(a,x),b)
- def bench_random(self,level=5):
+ @dec.bench
+ def test_bench_random(self):
import numpy.linalg as linalg
basic_solve = linalg.solve
print
@@ -174,26 +175,26 @@
for i in range(size): a[i,i] = 10*(.1+a[i,i])
b = random([size])
- print '| %6.2f ' % self.measure('solve(a,b)',repeat),
+ print '| %6.2f ' % measure('solve(a,b)',repeat),
sys.stdout.flush()
- print '| %6.2f ' % self.measure('basic_solve(a,b)',repeat),
+ print '| %6.2f ' % measure('basic_solve(a,b)',repeat),
sys.stdout.flush()
a = a[-1::-1,-1::-1] # turn into a non-contiguous array
assert not a.flags['CONTIGUOUS']
- print '| %6.2f ' % self.measure('solve(a,b)',repeat),
+ print '| %6.2f ' % measure('solve(a,b)',repeat),
sys.stdout.flush()
- print '| %6.2f ' % self.measure('basic_solve(a,b)',repeat),
+ print '| %6.2f ' % measure('basic_solve(a,b)',repeat),
sys.stdout.flush()
print ' (secs for %s calls)' % (repeat)
-class TestInv(NumpyTestCase):
+class TestInv(TestCase):
- def check_simple(self):
+ def test_simple(self):
a = [[1,2],[3,4]]
a_inv = inv(a)
assert_array_almost_equal(numpy.dot(a,a_inv),
@@ -203,7 +204,7 @@
assert_array_almost_equal(numpy.dot(a,a_inv),
[[1,0,0],[0,1,0],[0,0,1]])
- def check_random(self):
+ def test_random(self):
n = 20
for i in range(4):
a = random([n,n])
@@ -211,13 +212,13 @@
a_inv = inv(a)
assert_array_almost_equal(numpy.dot(a,a_inv),
numpy.identity(n))
- def check_simple_complex(self):
+ def test_simple_complex(self):
a = [[1,2],[3,4j]]
a_inv = inv(a)
assert_array_almost_equal(numpy.dot(a,a_inv),
[[1,0],[0,1]])
- def check_random_complex(self):
+ def test_random_complex(self):
n = 20
for i in range(4):
a = random([n,n])+2j*random([n,n])
@@ -226,7 +227,8 @@
assert_array_almost_equal(numpy.dot(a,a_inv),
numpy.identity(n))
- def bench_random(self,level=5):
+ @dec.bench
+ def test_bench_random(self):
import numpy.linalg as linalg
basic_inv = linalg.inv
print
@@ -245,37 +247,37 @@
# large diagonal ensures non-singularity:
for i in range(size): a[i,i] = 10*(.1+a[i,i])
- print '| %6.2f ' % self.measure('inv(a)',repeat),
+ print '| %6.2f ' % measure('inv(a)',repeat),
sys.stdout.flush()
- print '| %6.2f ' % self.measure('basic_inv(a)',repeat),
+ print '| %6.2f ' % measure('basic_inv(a)',repeat),
sys.stdout.flush()
a = a[-1::-1,-1::-1] # turn into a non-contiguous array
assert not a.flags['CONTIGUOUS']
- print '| %6.2f ' % self.measure('inv(a)',repeat),
+ print '| %6.2f ' % measure('inv(a)',repeat),
sys.stdout.flush()
- print '| %6.2f ' % self.measure('basic_inv(a)',repeat),
+ print '| %6.2f ' % measure('basic_inv(a)',repeat),
sys.stdout.flush()
print ' (secs for %s calls)' % (repeat)
-class TestDet(NumpyTestCase):
+class TestDet(TestCase):
- def check_simple(self):
+ def test_simple(self):
a = [[1,2],[3,4]]
a_det = det(a)
assert_almost_equal(a_det,-2.0)
- def check_simple_complex(self):
+ def test_simple_complex(self):
a = [[1,2],[3,4j]]
a_det = det(a)
assert_almost_equal(a_det,-6+4j)
- def check_random(self):
+ def test_random(self):
import numpy.linalg as linalg
basic_det = linalg.det
n = 20
@@ -285,7 +287,7 @@
d2 = basic_det(a)
assert_almost_equal(d1,d2)
- def check_random_complex(self):
+ def test_random_complex(self):
import numpy.linalg as linalg
basic_det = linalg.det
n = 20
@@ -295,7 +297,8 @@
d2 = basic_det(a)
assert_almost_equal(d1,d2)
- def bench_random(self,level=5):
+ @dec.bench
+ def test_bench_random(self):
import numpy.linalg as linalg
basic_det = linalg.det
print
@@ -312,19 +315,19 @@
a = random([size,size])
- print '| %6.2f ' % self.measure('det(a)',repeat),
+ print '| %6.2f ' % measure('det(a)',repeat),
sys.stdout.flush()
- print '| %6.2f ' % self.measure('basic_det(a)',repeat),
+ print '| %6.2f ' % measure('basic_det(a)',repeat),
sys.stdout.flush()
a = a[-1::-1,-1::-1] # turn into a non-contiguous array
assert not a.flags['CONTIGUOUS']
- print '| %6.2f ' % self.measure('det(a)',repeat),
+ print '| %6.2f ' % measure('det(a)',repeat),
sys.stdout.flush()
- print '| %6.2f ' % self.measure('basic_det(a)',repeat),
+ print '| %6.2f ' % measure('basic_det(a)',repeat),
sys.stdout.flush()
print ' (secs for %s calls)' % (repeat)
@@ -338,8 +341,8 @@
b1 = dot(at, b)
return solve(a1, b1)
-class TestLstsq(NumpyTestCase):
- def check_random_overdet_large(self):
+class TestLstsq(TestCase):
+ def test_random_overdet_large(self):
#bug report: Nils Wagner
n = 200
a = random([n,2])
@@ -348,21 +351,21 @@
x = lstsq(a,b)[0]
assert_array_almost_equal(x,direct_lstsq(a,b))
- def check_simple_exact(self):
+ def test_simple_exact(self):
a = [[1,20],[-30,4]]
for b in ([[1,0],[0,1]],[1,0],
[[2,1],[-30,4]]):
x = lstsq(a,b)[0]
assert_array_almost_equal(numpy.dot(a,x),b)
- def check_simple_overdet(self):
+ def test_simple_overdet(self):
a = [[1,2],[4,5],[3,4]]
b = [1,2,3]
x,res,r,s = lstsq(a,b)
#XXX: check defintion of res
assert_array_almost_equal(x,direct_lstsq(a,b))
- def check_simple_underdet(self):
+ def test_simple_underdet(self):
a = [[1,2,3],[4,5,6]]
b = [1,2]
x,res,r,s = lstsq(a,b)
@@ -370,7 +373,7 @@
assert_array_almost_equal(x,[[-0.05555556],
[0.11111111],[0.27777778]])
- def check_random_exact(self):
+ def test_random_exact(self):
n = 20
a = random([n,n])
@@ -380,7 +383,7 @@
x = lstsq(a,b)[0]
assert_array_almost_equal(numpy.dot(a,x),b)
- def check_random_complex_exact(self):
+ def test_random_complex_exact(self):
n = 20
a = random([n,n]) + 1j * random([n,n])
for i in range(n): a[i,i] = 20*(.1+a[i,i])
@@ -389,7 +392,7 @@
x = lstsq(a,b)[0]
assert_array_almost_equal(numpy.dot(a,x),b)
- def check_random_overdet(self):
+ def test_random_overdet(self):
n = 20
m = 15
a = random([n,m])
@@ -401,7 +404,7 @@
#XXX: check definition of res
assert_array_almost_equal(x,direct_lstsq(a,b))
- def check_random_complex_overdet(self):
+ def test_random_complex_overdet(self):
n = 20
m = 15
a = random([n,m]) + 1j * random([n,m])
@@ -414,8 +417,8 @@
#XXX: check definition of res
assert_array_almost_equal(x,direct_lstsq(a,b,1))
-class TestTri(NumpyTestCase):
- def check_basic(self):
+class TestTri(TestCase):
+ def test_basic(self):
assert_equal(tri(4),array([[1,0,0,0],
[1,1,0,0],
[1,1,1,0],
@@ -424,7 +427,7 @@
[1,1,0,0],
[1,1,1,0],
[1,1,1,1]],'f'))
- def check_diag(self):
+ def test_diag(self):
assert_equal(tri(4,k=1),array([[1,1,0,0],
[1,1,1,0],
[1,1,1,1],
@@ -433,7 +436,7 @@
[1,0,0,0],
[1,1,0,0],
[1,1,1,0]]))
- def check_2d(self):
+ def test_2d(self):
assert_equal(tri(4,3),array([[1,0,0],
[1,1,0],
[1,1,1],
@@ -441,7 +444,7 @@
assert_equal(tri(3,4),array([[1,0,0,0],
[1,1,0,0],
[1,1,1,0]]))
- def check_diag2d(self):
+ def test_diag2d(self):
assert_equal(tri(3,4,k=2),array([[1,1,1,0],
[1,1,1,1],
[1,1,1,1]]))
@@ -450,8 +453,8 @@
[1,0,0],
[1,1,0]]))
-class TestTril(NumpyTestCase):
- def check_basic(self):
+class TestTril(TestCase):
+ def test_basic(self):
a = (100*get_mat(5)).astype('l')
b = a.copy()
for k in range(5):
@@ -459,7 +462,7 @@
b[k,l] = 0
assert_equal(tril(a),b)
- def check_diag(self):
+ def test_diag(self):
a = (100*get_mat(5)).astype('f')
b = a.copy()
for k in range(5):
@@ -472,8 +475,8 @@
b[k,l] = 0
assert_equal(tril(a,k=-2),b)
-class TestTriu(NumpyTestCase):
- def check_basic(self):
+class TestTriu(TestCase):
+ def test_basic(self):
a = (100*get_mat(5)).astype('l')
b = a.copy()
for k in range(5):
@@ -481,7 +484,7 @@
b[l,k] = 0
assert_equal(triu(a),b)
- def check_diag(self):
+ def test_diag(self):
a = (100*get_mat(5)).astype('f')
b = a.copy()
for k in range(5):
@@ -494,46 +497,46 @@
b[l,k] = 0
assert_equal(triu(a,k=-2),b)
-class TestToeplitz(NumpyTestCase):
- def check_basic(self):
+class TestToeplitz(TestCase):
+ def test_basic(self):
y = toeplitz([1,2,3])
assert_array_equal(y,[[1,2,3],[2,1,2],[3,2,1]])
y = toeplitz([1,2,3],[1,4,5])
assert_array_equal(y,[[1,4,5],[2,1,4],[3,2,1]])
-class TestHankel(NumpyTestCase):
- def check_basic(self):
+class TestHankel(TestCase):
+ def test_basic(self):
y = hankel([1,2,3])
assert_array_equal(y,[[1,2,3],[2,3,0],[3,0,0]])
y = hankel([1,2,3],[3,4,5])
assert_array_equal(y,[[1,2,3],[2,3,4],[3,4,5]])
-class TestPinv(NumpyTestCase):
+class TestPinv(TestCase):
- def check_simple(self):
+ def test_simple(self):
a=array([[1,2,3],[4,5,6.],[7,8,10]])
a_pinv = pinv(a)
assert_array_almost_equal(dot(a,a_pinv),[[1,0,0],[0,1,0],[0,0,1]])
a_pinv = pinv2(a)
assert_array_almost_equal(dot(a,a_pinv),[[1,0,0],[0,1,0],[0,0,1]])
- def check_simple_0det(self):
+ def test_simple_0det(self):
a=array([[1,2,3],[4,5,6.],[7,8,9]])
a_pinv = pinv(a)
a_pinv2 = pinv2(a)
assert_array_almost_equal(a_pinv,a_pinv2)
- def check_simple_cols(self):
+ def test_simple_cols(self):
a=array([[1,2,3],[4,5,6.]])
a_pinv = pinv(a)
a_pinv2 = pinv2(a)
assert_array_almost_equal(a_pinv,a_pinv2)
- def check_simple_rows(self):
+ def test_simple_rows(self):
a=array([[1,2],[3,4],[5,6]])
a_pinv = pinv(a)
a_pinv2 = pinv2(a)
assert_array_almost_equal(a_pinv,a_pinv2)
if __name__ == "__main__":
- NumpyTest().run()
+ unittest.main()
Modified: trunk/scipy/linalg/tests/test_blas.py
===================================================================
--- trunk/scipy/linalg/tests/test_blas.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/linalg/tests/test_blas.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -12,21 +12,19 @@
python tests/test_blas.py [<level>]
"""
+import sys
+import math
from numpy import arange, add, array
-import math
-import sys
-from numpy.testing import *
-set_package_path()
-from linalg import fblas
-print fblas
-from linalg import cblas
-restore_path()
+from scipy.testing import *
-class TestCBLAS1Simple(NumpyTestCase):
+from scipy.linalg import fblas, cblas
- def check_axpy(self):
+
+class TestCBLAS1Simple(TestCase):
+
+ def test_axpy(self):
for p in 'sd':
f = getattr(cblas,p+'axpy',None)
if f is None: continue
@@ -36,9 +34,9 @@
if f is None: continue
assert_array_almost_equal(f(5,[1,2j,3],[2,-1,3]),[7,10j-1,18])
-class TestFBLAS1Simple(NumpyTestCase):
+class TestFBLAS1Simple(TestCase):
- def check_axpy(self):
+ def test_axpy(self):
for p in 'sd':
f = getattr(fblas,p+'axpy',None)
if f is None: continue
@@ -47,7 +45,7 @@
f = getattr(fblas,p+'axpy',None)
if f is None: continue
assert_array_almost_equal(f([1,2j,3],[2,-1,3],a=5),[7,10j-1,18])
- def check_copy(self):
+ def test_copy(self):
for p in 'sd':
f = getattr(fblas,p+'copy',None)
if f is None: continue
@@ -56,7 +54,7 @@
f = getattr(fblas,p+'copy',None)
if f is None: continue
assert_array_almost_equal(f([3,4j,5+3j],[8]*3),[3,4j,5+3j])
- def check_asum(self):
+ def test_asum(self):
for p in 'sd':
f = getattr(fblas,p+'asum',None)
if f is None: continue
@@ -65,24 +63,24 @@
f = getattr(fblas,p+'asum',None)
if f is None: continue
assert_almost_equal(f([3j,-4,3-4j]),14)
- def check_dot(self):
+ def test_dot(self):
for p in 'sd':
f = getattr(fblas,p+'dot',None)
if f is None: continue
assert_almost_equal(f([3,-4,5],[2,5,1]),-9)
- def check_complex_dotu(self):
+ def test_complex_dotu(self):
for p in 'cz':
f = getattr(fblas,p+'dotu',None)
if f is None: continue
assert_almost_equal(f([3j,-4,3-4j],[2,3,1]),-9+2j)
- def check_complex_dotc(self):
+ def test_complex_dotc(self):
for p in 'cz':
f = getattr(fblas,p+'dotc',None)
if f is None: continue
assert_almost_equal(f([3j,-4,3-4j],[2,3j,1]),3-14j)
- def check_nrm2(self):
+ def test_nrm2(self):
for p in 'sd':
f = getattr(fblas,p+'nrm2',None)
if f is None: continue
@@ -91,7 +89,7 @@
f = getattr(fblas,p+'nrm2',None)
if f is None: continue
assert_almost_equal(f([3j,-4,3-4j]),math.sqrt(50))
- def check_scal(self):
+ def test_scal(self):
for p in 'sd':
f = getattr(fblas,p+'scal',None)
if f is None: continue
@@ -104,7 +102,7 @@
f = getattr(fblas,p+'scal',None)
if f is None: continue
assert_array_almost_equal(f(3,[3j,-4,3-4j]),[9j,-12,9-12j])
- def check_swap(self):
+ def test_swap(self):
for p in 'sd':
f = getattr(fblas,p+'swap',None)
if f is None: continue
@@ -119,7 +117,7 @@
x1,y1 = f(x,y)
assert_array_almost_equal(x1,y)
assert_array_almost_equal(y1,x)
- def check_amax(self):
+ def test_amax(self):
for p in 'sd':
f = getattr(fblas,'i'+p+'amax')
assert_equal(f([-2,4,3]),1)
@@ -128,9 +126,9 @@
assert_equal(f([-5,4+3j,6]),1)
#XXX: need tests for rot,rotm,rotg,rotmg
-class TestFBLAS2Simple(NumpyTestCase):
+class TestFBLAS2Simple(TestCase):
- def check_gemv(self):
+ def test_gemv(self):
for p in 'sd':
f = getattr(fblas,p+'gemv',None)
if f is None: continue
@@ -142,7 +140,7 @@
assert_array_almost_equal(f(3j,[[3-4j]],[-4]),[-48-36j])
assert_array_almost_equal(f(3j,[[3-4j]],[-4],3,[5j]),[-48-21j])
- def check_ger(self):
+ def test_ger(self):
for p in 'sd':
f = getattr(fblas,p+'ger',None)
@@ -176,9 +174,9 @@
2j,
3j],[3j,4j]),[[6,8],[12,16],[18,24]])
-class TestFBLAS3Simple(NumpyTestCase):
+class TestFBLAS3Simple(TestCase):
- def check_gemm(self):
+ def test_gemm(self):
for p in 'sd':
f = getattr(fblas,p+'gemm',None)
if f is None: continue
@@ -190,9 +188,9 @@
assert_array_almost_equal(f(3j,[3-4j],[-4]),[[-48-36j]])
assert_array_almost_equal(f(3j,[3-4j],[-4],3,[5j]),[-48-21j])
-class TestBLAS(NumpyTestCase):
+class TestBLAS(TestCase):
- def check_fblas(self):
+ def test_fblas(self):
if hasattr(fblas,'empty_module'):
print """
****************************************************************
@@ -201,7 +199,7 @@
See scipy/INSTALL.txt for troubleshooting.
****************************************************************
"""
- def check_cblas(self):
+ def test_cblas(self):
if hasattr(cblas,'empty_module'):
print """
****************************************************************
@@ -215,4 +213,4 @@
"""
if __name__ == "__main__":
- NumpyTest().run()
+ unittest.main()
Modified: trunk/scipy/linalg/tests/test_decomp.py
===================================================================
--- trunk/scipy/linalg/tests/test_decomp.py 2008-01-12 09:23:49 UTC (rev 3821)
+++ trunk/scipy/linalg/tests/test_decomp.py 2008-01-12 10:06:39 UTC (rev 3822)
@@ -9,37 +9,41 @@
Build linalg:
python setup_linalg.py build
Run tests if scipy is installed:
- python -c 'import scipy;scipy.linalg.test(<level>)'
+ python -c 'import scipy;scipy.linalg.test()'
Run tests if linalg is not installed:
- python tests/test_decomp.py [<level>]
+ python tests/test_decomp.py
"""
import sys
-from numpy.testing import *
+from scipy.testing import *
-set_package_path()
-from linalg import eig,eigvals,lu,svd,svdvals,cholesky,qr,schur,rsf2csf
-from linalg import lu_solve,lu_factor,solve,diagsvd,hessenberg,rq
-from linalg import eig_banded,eigvals_banded
-from linalg.flapack import dgbtrf, dgbtrs, zgbtrf, zgbtrs
-from linalg.flapack import dsbev, dsbevd, dsbevx, zhbevd, zhbevx
-restore_path()
-from numpy import *
+from scipy.linalg import eig,eigvals,lu,svd,svdvals,cholesky,qr, \
+ schur,rsf2csf, lu_solve,lu_factor,solve,diagsvd,hessenberg,rq, \
+ eig_banded, eigvals_banded
+from scipy.linalg.flapack import dgbtrf, dgbtrs, zgbtrf, zgbtrs, \
+ dsbev, dsbevd, dsbevx, zhbevd, zhbevx
+
+from numpy import array, transpose, sometrue, diag, ones, linalg, \
+ argsort, zeros, arange, float32, complex64, dot, conj, identity, \
+ ravel, sqrt, iscomplex, shape, sort, sign, conjugate, sign, bmat, \
+ asarray, matrix, isfinite
+
+
from numpy.random import rand
def random(size):
return rand(*size)
-class TestEigVals(NumpyTestCase):
+class TestEigVals(TestCase):
- def check_simple(self):
+ def test_simple(self):
a = [[1,2,3],[1,2,3],[2,5,6]]
w = eigvals(a)
exact_w = [(9+sqrt(93))/2,0,(9-sqrt(93))/2]
assert_array_almost_equal(w,exact_w)
- def check_simple_tr(self):
+ def test_simple_tr(self):
a = array([[1,2,3],[1,2,3],[2,5,6]],'d')
a = transpose(a).copy()
a = transpose(a)
@@ -47,7 +51,7 @@
exact_w = [(9+sqrt(93))/2,0,(9-sqrt(93))/2]
assert_array_almost_equal(w,exact_w)
- def check_simple_complex(self):
+ def test_simple_complex(self):
a = [[1,2,3],[1,2,3],[2,5,6+1j]]
w = eigvals(a)
exact_w = [(9+1j+sqrt(92+6j))/2,
@@ -55,7 +59,8 @@
(9+1j-sqrt(92+6j))/2]
assert_array_almost_equal(w,exact_w)
- def bench_random(self,level=5):
+ @dec.bench
+ def test_bench_random(self):
import numpy.linalg as linalg
Numeric_eigvals = linalg.eigvals
print
@@ -72,14 +77,14 @@
a = random([size,size])
- print '| %6.2f ' % self.measure('eigvals(a)',repeat),
+ print '| %6.2f ' % measure('eigvals(a)',repeat),
sys.stdout.flush()
print ' (secs for %s calls)' % (repeat)
-class TestEig(NumpyTestCase):
+class TestEig(TestCase):
- def check_simple(self):
+ def test_simple(self):
a = [[1,2,3],[1,2,3],[2,5,6]]
w,v = eig(a)
exact_w = [(9+sqrt(93))/2,0,(9-sqrt(93))/2]
@@ -99,7 +104,7 @@
for i in range(3):
assert_array_almost_equal(dot(transpose(a),v[:,i]),w[i]*v[:,i])
- def check_simple_compl