From c331857d8663ecf54bbe88c834755da749e8ab52 Mon Sep 17 00:00:00 2001 From: Alan McIntyre Date: Tue, 17 Jun 2008 00:23:20 +0000 Subject: Switched to use nose to run tests. Added test and bench functions to all modules. --- numpy/lib/__init__.py | 7 +- numpy/lib/tests/test__datasource.py | 14 +-- numpy/lib/tests/test_arraysetops.py | 26 ++--- numpy/lib/tests/test_financial.py | 7 +- numpy/lib/tests/test_format.py | 4 + numpy/lib/tests/test_function_base.py | 163 ++++++++++++++++--------------- numpy/lib/tests/test_getlimits.py | 28 +++--- numpy/lib/tests/test_index_tricks.py | 19 ++-- numpy/lib/tests/test_io.py | 9 +- numpy/lib/tests/test_machar.py | 7 +- numpy/lib/tests/test_polynomial.py | 14 +-- numpy/lib/tests/test_regression.py | 4 +- numpy/lib/tests/test_shape_base.py | 175 ++++++++++++++++++++-------------- numpy/lib/tests/test_twodim_base.py | 46 ++++----- numpy/lib/tests/test_type_check.py | 127 ++++++++++++------------ numpy/lib/tests/test_ufunclike.py | 8 +- 16 files changed, 356 insertions(+), 302 deletions(-) (limited to 'numpy/lib') diff --git a/numpy/lib/__init__.py b/numpy/lib/__init__.py index b011095f3..643320bc0 100644 --- a/numpy/lib/__init__.py +++ b/numpy/lib/__init__.py @@ -34,6 +34,7 @@ __all__ += arraysetops.__all__ __all__ += io.__all__ __all__ += financial.__all__ -def test(level=1, verbosity=1): - from numpy.testing import NumpyTest - return NumpyTest().test(level, verbosity) +from numpy.testing.pkgtester import Tester +test = Tester().test +bench = Tester().bench + diff --git a/numpy/lib/tests/test__datasource.py b/numpy/lib/tests/test__datasource.py index 93e77d28c..695da0470 100644 --- a/numpy/lib/tests/test__datasource.py +++ b/numpy/lib/tests/test__datasource.py @@ -67,7 +67,7 @@ def valid_httpfile(): def invalid_httpfile(): return http_fakefile -class TestDataSourceOpen(NumpyTestCase): +class TestDataSourceOpen(TestCase): def setUp(self): self.tmpdir = mkdtemp() self.ds = datasource.DataSource(self.tmpdir) @@ -127,7 +127,7 @@ class TestDataSourceOpen(NumpyTestCase): self.assertEqual(magic_line, result) -class TestDataSourceExists(NumpyTestCase): +class TestDataSourceExists(TestCase): def setUp(self): self.tmpdir = mkdtemp() self.ds = datasource.DataSource(self.tmpdir) @@ -157,7 +157,7 @@ class TestDataSourceExists(NumpyTestCase): self.assertEqual(self.ds.exists(tmpfile), False) -class TestDataSourceAbspath(NumpyTestCase): +class TestDataSourceAbspath(TestCase): def setUp(self): self.tmpdir = os.path.abspath(mkdtemp()) self.ds = datasource.DataSource(self.tmpdir) @@ -222,7 +222,7 @@ class TestDataSourceAbspath(NumpyTestCase): os.sep = orig_os_sep -class TestRepositoryAbspath(NumpyTestCase): +class TestRepositoryAbspath(TestCase): def setUp(self): self.tmpdir = os.path.abspath(mkdtemp()) self.repos = datasource.Repository(valid_baseurl(), self.tmpdir) @@ -255,7 +255,7 @@ class TestRepositoryAbspath(NumpyTestCase): os.sep = orig_os_sep -class TestRepositoryExists(NumpyTestCase): +class TestRepositoryExists(TestCase): def setUp(self): self.tmpdir = mkdtemp() self.repos = datasource.Repository(valid_baseurl(), self.tmpdir) @@ -288,7 +288,7 @@ class TestRepositoryExists(NumpyTestCase): assert self.repos.exists(tmpfile) -class TestOpenFunc(NumpyTestCase): +class TestOpenFunc(TestCase): def setUp(self): self.tmpdir = mkdtemp() @@ -304,4 +304,4 @@ class TestOpenFunc(NumpyTestCase): if __name__ == "__main__": - NumpyTest().run() + nose.run(argv=['', __file__]) diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py index 5a5a8fbd8..ca505e9c5 100644 --- a/numpy/lib/tests/test_arraysetops.py +++ b/numpy/lib/tests/test_arraysetops.py @@ -6,15 +6,14 @@ from numpy.testing import * set_package_path() import numpy from numpy.lib.arraysetops import * -from numpy.lib.arraysetops import ediff1d restore_path() ################################################## -class TestAso(NumpyTestCase): +class TestAso(TestCase): ## # 03.11.2005, c - def check_unique1d( self ): + def test_unique1d( self ): a = numpy.array( [5, 7, 1, 2, 1, 5, 7] ) @@ -26,7 +25,7 @@ class TestAso(NumpyTestCase): ## # 03.11.2005, c - def check_intersect1d( self ): + def test_intersect1d( self ): a = numpy.array( [5, 7, 1, 2] ) b = numpy.array( [2, 4, 3, 1, 5] ) @@ -39,7 +38,7 @@ class TestAso(NumpyTestCase): ## # 03.11.2005, c - def check_intersect1d_nu( self ): + def test_intersect1d_nu( self ): a = numpy.array( [5, 5, 7, 1, 2] ) b = numpy.array( [2, 1, 4, 3, 3, 1, 5] ) @@ -52,7 +51,7 @@ class TestAso(NumpyTestCase): ## # 03.11.2005, c - def check_setxor1d( self ): + def test_setxor1d( self ): a = numpy.array( [5, 7, 1, 2] ) b = numpy.array( [2, 4, 3, 1, 5] ) @@ -77,7 +76,7 @@ class TestAso(NumpyTestCase): assert_array_equal([], setxor1d([],[])) - def check_ediff1d(self): + def test_ediff1d(self): zero_elem = numpy.array([]) one_elem = numpy.array([1]) two_elem = numpy.array([1,2]) @@ -91,7 +90,7 @@ class TestAso(NumpyTestCase): ## # 03.11.2005, c - def check_setmember1d( self ): + def test_setmember1d( self ): a = numpy.array( [5, 7, 1, 2] ) b = numpy.array( [2, 4, 3, 1, 5] ) @@ -114,7 +113,7 @@ class TestAso(NumpyTestCase): ## # 03.11.2005, c - def check_union1d( self ): + def test_union1d( self ): a = numpy.array( [5, 4, 7, 1, 2] ) b = numpy.array( [2, 4, 3, 3, 2, 1, 5] ) @@ -128,7 +127,7 @@ class TestAso(NumpyTestCase): ## # 03.11.2005, c # 09.01.2006 - def check_setdiff1d( self ): + def test_setdiff1d( self ): a = numpy.array( [6, 5, 4, 7, 1, 2] ) b = numpy.array( [2, 4, 3, 3, 2, 1, 5] ) @@ -145,14 +144,14 @@ class TestAso(NumpyTestCase): assert_array_equal([], setdiff1d([],[])) - def check_setdiff1d_char_array(self): + def test_setdiff1d_char_array(self): a = numpy.array(['a','b','c']) b = numpy.array(['a','b','s']) assert_array_equal(setdiff1d(a,b),numpy.array(['c'])) ## # 03.11.2005, c - def check_manyways( self ): + def test_manyways( self ): nItem = 100 a = numpy.fix( nItem / 10 * numpy.random.random( nItem ) ) @@ -171,5 +170,6 @@ class TestAso(NumpyTestCase): c2 = setdiff1d( aux2, aux1 ) assert_array_equal( c1, c2 ) + if __name__ == "__main__": - NumpyTest().run() + nose.run(argv=['', __file__]) diff --git a/numpy/lib/tests/test_financial.py b/numpy/lib/tests/test_financial.py index ee38c10dc..df5a0fbde 100644 --- a/numpy/lib/tests/test_financial.py +++ b/numpy/lib/tests/test_financial.py @@ -32,8 +32,9 @@ True from numpy.testing import * import numpy as np -class TestDocs(NumpyTestCase): - def check_doctests(self): return self.rundocs() +def test(): + import doctest + doctest.testmod() if __name__ == "__main__": - NumpyTest().run() + nose.run(argv=['', __file__]) diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py index e7b27ce94..4a473c55e 100644 --- a/numpy/lib/tests/test_format.py +++ b/numpy/lib/tests/test_format.py @@ -506,3 +506,7 @@ def test_read_version_1_0_bad_magic(): for magic in bad_version_magic + malformed_magic: f = StringIO(magic) yield raises(ValueError)(format.read_array), f + + +if __name__ == "__main__": + nose.run(argv=['', __file__]) diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index e1a7ae67a..3cd7cd6bb 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -5,11 +5,10 @@ set_package_path() import numpy.lib;reload(numpy.lib) from numpy.lib import * from numpy.core import * +restore_path() -del sys.path[0] - -class TestAny(NumpyTestCase): - def check_basic(self): +class TestAny(TestCase): + def test_basic(self): y1 = [0,0,1,0] y2 = [0,0,0,0] y3 = [1,0,1,0] @@ -17,14 +16,14 @@ class TestAny(NumpyTestCase): assert(any(y3)) assert(not any(y2)) - def check_nd(self): + def test_nd(self): y1 = [[0,0,0],[0,1,0],[1,1,0]] assert(any(y1)) assert_array_equal(sometrue(y1,axis=0),[1,1,0]) assert_array_equal(sometrue(y1,axis=1),[0,1,1]) -class TestAll(NumpyTestCase): - def check_basic(self): +class TestAll(TestCase): + def test_basic(self): y1 = [0,1,1,0] y2 = [0,0,0,0] y3 = [1,1,1,1] @@ -33,14 +32,14 @@ class TestAll(NumpyTestCase): assert(not all(y2)) assert(all(~array(y2))) - def check_nd(self): + def test_nd(self): y1 = [[0,0,1],[0,1,1],[1,1,1]] assert(not all(y1)) assert_array_equal(alltrue(y1,axis=0),[0,0,1]) assert_array_equal(alltrue(y1,axis=1),[0,0,1]) -class TestAverage(NumpyTestCase): - def check_basic(self): +class TestAverage(TestCase): + def test_basic(self): y1 = array([1,2,3]) assert(average(y1,axis=0) == 2.) y2 = array([1.,2.,3.]) @@ -61,7 +60,7 @@ class TestAverage(NumpyTestCase): y6 = matrix(rand(5,5)) assert_array_equal(y6.mean(0), average(y6,0)) - def check_weights(self): + def test_weights(self): y = arange(10) w = arange(10) assert_almost_equal(average(y, weights=w), (arange(10)**2).sum()*1./arange(10).sum()) @@ -89,7 +88,7 @@ class TestAverage(NumpyTestCase): assert_equal(average(y1, weights=w2), 5.) - def check_returned(self): + def test_returned(self): y = array([[1,2,3],[4,5,6]]) # No weights @@ -116,14 +115,14 @@ class TestAverage(NumpyTestCase): assert_array_equal(scl, array([1.,6.])) -class TestSelect(NumpyTestCase): +class TestSelect(TestCase): def _select(self,cond,values,default=0): output = [] for m in range(len(cond)): output += [V[m] for V,C in zip(values,cond) if C[m]] or [default] return output - def check_basic(self): + def test_basic(self): choices = [array([1,2,3]), array([4,5,6]), array([7,8,9])] @@ -136,8 +135,8 @@ class TestSelect(NumpyTestCase): assert_equal(len(choices),3) assert_equal(len(conditions),3) -class TestLogspace(NumpyTestCase): - def check_basic(self): +class TestLogspace(TestCase): + def test_basic(self): y = logspace(0,6) assert(len(y)==50) y = logspace(0,6,num=100) @@ -147,8 +146,8 @@ class TestLogspace(NumpyTestCase): y = logspace(0,6,num=7) assert_array_equal(y,[1,10,100,1e3,1e4,1e5,1e6]) -class TestLinspace(NumpyTestCase): - def check_basic(self): +class TestLinspace(TestCase): + def test_basic(self): y = linspace(0,10) assert(len(y)==50) y = linspace(2,10,num=100) @@ -159,28 +158,28 @@ class TestLinspace(NumpyTestCase): assert_almost_equal(st,8/49.0) assert_array_almost_equal(y,mgrid[2:10:50j],13) - def check_corner(self): + def test_corner(self): y = list(linspace(0,1,1)) assert y == [0.0], y y = list(linspace(0,1,2.5)) assert y == [0.0, 1.0] - def check_type(self): + def test_type(self): t1 = linspace(0,1,0).dtype t2 = linspace(0,1,1).dtype t3 = linspace(0,1,2).dtype assert_equal(t1, t2) assert_equal(t2, t3) -class TestInsert(NumpyTestCase): - def check_basic(self): +class TestInsert(TestCase): + def test_basic(self): a = [1,2,3] assert_equal(insert(a,0,1), [1,1,2,3]) assert_equal(insert(a,3,1), [1,2,3,1]) assert_equal(insert(a,[1,1,1],[1,2,3]), [1,1,2,3,2,3]) -class TestAmax(NumpyTestCase): - def check_basic(self): +class TestAmax(TestCase): + def test_basic(self): a = [3,4,5,10,-3,-5,6.0] assert_equal(amax(a),10.0) b = [[3,6.0, 9.0], @@ -189,8 +188,8 @@ class TestAmax(NumpyTestCase): assert_equal(amax(b,axis=0),[8.0,10.0,9.0]) assert_equal(amax(b,axis=1),[9.0,10.0,8.0]) -class TestAmin(NumpyTestCase): - def check_basic(self): +class TestAmin(TestCase): + def test_basic(self): a = [3,4,5,10,-3,-5,6.0] assert_equal(amin(a),-5.0) b = [[3,6.0, 9.0], @@ -199,8 +198,8 @@ class TestAmin(NumpyTestCase): assert_equal(amin(b,axis=0),[3.0,3.0,2.0]) assert_equal(amin(b,axis=1),[3.0,4.0,2.0]) -class TestPtp(NumpyTestCase): - def check_basic(self): +class TestPtp(TestCase): + def test_basic(self): a = [3,4,5,10,-3,-5,6.0] assert_equal(ptp(a,axis=0),15.0) b = [[3,6.0, 9.0], @@ -209,8 +208,8 @@ class TestPtp(NumpyTestCase): assert_equal(ptp(b,axis=0),[5.0,7.0,7.0]) assert_equal(ptp(b,axis=-1),[6.0,6.0,6.0]) -class TestCumsum(NumpyTestCase): - def check_basic(self): +class TestCumsum(TestCase): + def test_basic(self): ba = [1,2,10,11,6,5,4] ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]] for ctype in [int8,uint8,int16,uint16,int32,uint32, @@ -225,8 +224,8 @@ class TestCumsum(NumpyTestCase): [5,11,18,27], [10,13,17,22]],ctype)) -class TestProd(NumpyTestCase): - def check_basic(self): +class TestProd(TestCase): + def test_basic(self): ba = [1,2,10,11,6,5,4] ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]] for ctype in [int16,uint16,int32,uint32, @@ -243,8 +242,8 @@ class TestProd(NumpyTestCase): array([50,36,84,180],ctype)) assert_array_equal(prod(a2,axis=-1),array([24, 1890, 600],ctype)) -class TestCumprod(NumpyTestCase): - def check_basic(self): +class TestCumprod(TestCase): + def test_basic(self): ba = [1,2,10,11,6,5,4] ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]] for ctype in [int16,uint16,int32,uint32, @@ -268,8 +267,8 @@ class TestCumprod(NumpyTestCase): [ 5, 30, 210, 1890], [10, 30, 120, 600]],ctype)) -class TestDiff(NumpyTestCase): - def check_basic(self): +class TestDiff(TestCase): + def test_basic(self): x = [1,4,6,7,12] out = array([3,2,1,5]) out2 = array([-1,-1,4]) @@ -278,7 +277,7 @@ class TestDiff(NumpyTestCase): assert_array_equal(diff(x,n=2),out2) assert_array_equal(diff(x,n=3),out3) - def check_nd(self): + def test_nd(self): x = 20*rand(10,20,30) out1 = x[:,:,1:] - x[:,:,:-1] out2 = out1[:,:,1:] - out1[:,:,:-1] @@ -289,8 +288,8 @@ class TestDiff(NumpyTestCase): assert_array_equal(diff(x,axis=0),out3) assert_array_equal(diff(x,n=2,axis=0),out4) -class TestAngle(NumpyTestCase): - def check_basic(self): +class TestAngle(TestCase): + def test_basic(self): x = [1+3j,sqrt(2)/2.0+1j*sqrt(2)/2,1,1j,-1,-1j,1-3j,-1+3j] y = angle(x) yo = [arctan(3.0/1.0),arctan(1.0),0,pi/2,pi,-pi/2.0, @@ -300,33 +299,33 @@ class TestAngle(NumpyTestCase): assert_array_almost_equal(y,yo,11) assert_array_almost_equal(z,zo,11) -class TestTrimZeros(NumpyTestCase): +class TestTrimZeros(TestCase): """ only testing for integer splits. """ - def check_basic(self): + def test_basic(self): a= array([0,0,1,2,3,4,0]) res = trim_zeros(a) assert_array_equal(res,array([1,2,3,4])) - def check_leading_skip(self): + def test_leading_skip(self): a= array([0,0,1,0,2,3,4,0]) res = trim_zeros(a) assert_array_equal(res,array([1,0,2,3,4])) - def check_trailing_skip(self): + def test_trailing_skip(self): a= array([0,0,1,0,2,3,0,4,0]) res = trim_zeros(a) assert_array_equal(res,array([1,0,2,3,0,4])) -class TestExtins(NumpyTestCase): - def check_basic(self): +class TestExtins(TestCase): + def test_basic(self): a = array([1,3,2,1,2,3,3]) b = extract(a>1,a) assert_array_equal(b,[3,2,2,3,3]) - def check_place(self): + def test_place(self): a = array([1,4,3,2,5,8,7]) place(a,[0,1,0,1,0,1,0],[2,4,6]) assert_array_equal(a,[1,2,3,4,5,6,7]) - def check_both(self): + def test_both(self): a = rand(10) mask = a > 0.5 ac = a.copy() @@ -335,8 +334,8 @@ class TestExtins(NumpyTestCase): place(a,mask,c) assert_array_equal(a,ac) -class TestVectorize(NumpyTestCase): - def check_simple(self): +class TestVectorize(TestCase): + def test_simple(self): def addsubtract(a,b): if a > b: return a - b @@ -345,7 +344,7 @@ class TestVectorize(NumpyTestCase): f = vectorize(addsubtract) r = f([0,3,6,9],[1,3,5,7]) assert_array_equal(r,[1,6,1,2]) - def check_scalar(self): + def test_scalar(self): def addsubtract(a,b): if a > b: return a - b @@ -354,59 +353,59 @@ class TestVectorize(NumpyTestCase): f = vectorize(addsubtract) r = f([0,3,6,9],5) assert_array_equal(r,[5,8,1,4]) - def check_large(self): + def test_large(self): x = linspace(-3,2,10000) f = vectorize(lambda x: x) y = f(x) assert_array_equal(y, x) -class TestDigitize(NumpyTestCase): - def check_forward(self): +class TestDigitize(TestCase): + def test_forward(self): x = arange(-6,5) bins = arange(-5,5) assert_array_equal(digitize(x,bins),arange(11)) - def check_reverse(self): + def test_reverse(self): x = arange(5,-6,-1) bins = arange(5,-5,-1) assert_array_equal(digitize(x,bins),arange(11)) - def check_random(self): + def test_random(self): x = rand(10) bin = linspace(x.min(), x.max(), 10) assert all(digitize(x,bin) != 0) -class TestUnwrap(NumpyTestCase): - def check_simple(self): +class TestUnwrap(TestCase): + def test_simple(self): #check that unwrap removes jumps greather that 2*pi assert_array_equal(unwrap([1,1+2*pi]),[1,1]) #check that unwrap maintans continuity assert(all(diff(unwrap(rand(10)*100)) 1e10) and assert_all(isfinite(vals[2])) - def check_integer(self): + def test_integer(self): vals = nan_to_num(1) assert_all(vals == 1) - def check_complex_good(self): + def test_complex_good(self): vals = nan_to_num(1+1j) assert_all(vals == 1+1j) - def check_complex_bad(self): + def test_complex_bad(self): v = 1+1j olderr = seterr(divide='ignore', invalid='ignore') v += array(0+1.j)/0. @@ -245,7 +245,7 @@ class TestNanToNum(NumpyTestCase): vals = nan_to_num(v) # !! This is actually (unexpectedly) zero assert_all(isfinite(vals)) - def check_complex_bad2(self): + def test_complex_bad2(self): v = 1+1j olderr = seterr(divide='ignore', invalid='ignore') v += array(-1+1.j)/0. @@ -259,8 +259,8 @@ class TestNanToNum(NumpyTestCase): #assert_all(vals.real < -1e10) and assert_all(isfinite(vals)) -class TestRealIfClose(NumpyTestCase): - def check_basic(self): +class TestRealIfClose(TestCase): + def test_basic(self): a = rand(10) b = real_if_close(a+1e-15j) assert_all(isrealobj(b)) @@ -270,11 +270,12 @@ class TestRealIfClose(NumpyTestCase): b = real_if_close(a+1e-7j,tol=1e-6) assert_all(isrealobj(b)) -class TestArrayConversion(NumpyTestCase): - def check_asfarray(self): +class TestArrayConversion(TestCase): + def test_asfarray(self): a = asfarray(array([1,2,3])) assert_equal(a.__class__,ndarray) assert issubdtype(a.dtype,float) + if __name__ == "__main__": - NumpyTest().run() + nose.run(argv=['', __file__]) diff --git a/numpy/lib/tests/test_ufunclike.py b/numpy/lib/tests/test_ufunclike.py index 926439fb4..f734355bd 100644 --- a/numpy/lib/tests/test_ufunclike.py +++ b/numpy/lib/tests/test_ufunclike.py @@ -59,8 +59,10 @@ array([ 2.169925 , 1.20163386, 2.70043972]) from numpy.testing import * -class TestDocs(NumpyTestCase): - def check_doctests(self): return self.rundocs() +class TestDocs(TestCase): + def test_doctests(self): + return rundocs() + if __name__ == "__main__": - NumpyTest().run() + nose.run(argv=['', __file__]) -- cgit v1.2.1