summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/__init__.py2
-rw-r--r--numpy/core/__init__.py2
-rw-r--r--numpy/core/tests/test_defmatrix.py2
-rw-r--r--numpy/core/tests/test_errstate.py2
-rw-r--r--numpy/core/tests/test_memmap.py3
-rw-r--r--numpy/core/tests/test_multiarray.py2
-rw-r--r--numpy/core/tests/test_numeric.py3
-rw-r--r--numpy/core/tests/test_numerictypes.py3
-rw-r--r--numpy/core/tests/test_records.py3
-rw-r--r--numpy/core/tests/test_regression.py2
-rw-r--r--numpy/core/tests/test_scalarmath.py2
-rw-r--r--numpy/core/tests/test_ufunc.py2
-rw-r--r--numpy/core/tests/test_umath.py2
-rw-r--r--numpy/core/tests/test_unicode.py2
-rw-r--r--numpy/distutils/__init__.py2
-rw-r--r--numpy/distutils/tests/f2py_ext/tests/test_fib2.py2
-rw-r--r--numpy/distutils/tests/f2py_f90_ext/tests/test_foo.py2
-rw-r--r--numpy/distutils/tests/gen_ext/tests/test_fib3.py2
-rw-r--r--numpy/distutils/tests/pyrex_ext/tests/test_primes.py2
-rw-r--r--numpy/distutils/tests/swig_ext/tests/test_example.py2
-rw-r--r--numpy/distutils/tests/swig_ext/tests/test_example2.py2
-rw-r--r--numpy/distutils/tests/test_fcompiler_gnu.py2
-rw-r--r--numpy/distutils/tests/test_misc_util.py2
-rw-r--r--numpy/doc/DISTUTILS.txt4
-rw-r--r--numpy/f2py/lib/parser/test_Fortran2003.py2
-rw-r--r--numpy/f2py/lib/parser/test_parser.py2
-rw-r--r--numpy/f2py/lib/tests/test_derived_scalar.py2
-rw-r--r--numpy/f2py/lib/tests/test_module_module.py2
-rw-r--r--numpy/f2py/lib/tests/test_module_scalar.py2
-rw-r--r--numpy/f2py/lib/tests/test_scalar_function_in.py2
-rw-r--r--numpy/f2py/lib/tests/test_scalar_in_out.py2
-rw-r--r--numpy/f2py/tests/array_from_pyobj/tests/test_array_from_pyobj.py2
-rw-r--r--numpy/fft/__init__.py2
-rw-r--r--numpy/fft/tests/test_fftpack.py2
-rw-r--r--numpy/fft/tests/test_helper.py2
-rw-r--r--numpy/lib/__init__.py2
-rw-r--r--numpy/lib/tests/test__datasource.py3
-rw-r--r--numpy/lib/tests/test_arraysetops.py2
-rw-r--r--numpy/lib/tests/test_financial.py2
-rw-r--r--numpy/lib/tests/test_format.py2
-rw-r--r--numpy/lib/tests/test_function_base.py2
-rw-r--r--numpy/lib/tests/test_getlimits.py2
-rw-r--r--numpy/lib/tests/test_index_tricks.py3
-rw-r--r--numpy/lib/tests/test_io.py2
-rw-r--r--numpy/lib/tests/test_machar.py2
-rw-r--r--numpy/lib/tests/test_polynomial.py3
-rw-r--r--numpy/lib/tests/test_regression.py3
-rw-r--r--numpy/lib/tests/test_shape_base.py2
-rw-r--r--numpy/lib/tests/test_twodim_base.py3
-rw-r--r--numpy/lib/tests/test_type_check.py2
-rw-r--r--numpy/lib/tests/test_ufunclike.py8
-rw-r--r--numpy/linalg/__init__.py2
-rw-r--r--numpy/linalg/tests/test_linalg.py2
-rw-r--r--numpy/linalg/tests/test_regression.py2
-rw-r--r--numpy/ma/__init__.py2
-rw-r--r--numpy/ma/tests/test_core.py2
-rw-r--r--numpy/ma/tests/test_extras.py2
-rw-r--r--numpy/ma/tests/test_mrecords.py2
-rw-r--r--numpy/ma/tests/test_old_ma.py2
-rw-r--r--numpy/ma/tests/test_subclassing.py2
-rw-r--r--numpy/numarray/__init__.py2
-rw-r--r--numpy/oldnumeric/__init__.py2
-rw-r--r--numpy/oldnumeric/tests/test_oldnumeric.py2
-rw-r--r--numpy/random/__init__.py2
-rw-r--r--numpy/random/tests/test_random.py2
-rw-r--r--numpy/testing/__init__.py4
-rw-r--r--numpy/testing/nosetester.py103
-rw-r--r--numpy/testing/numpytest.py538
-rw-r--r--numpy/testing/pkgtester.py14
-rw-r--r--numpy/testing/tests/test_utils.py2
-rw-r--r--numpy/tests/test_ctypeslib.py2
71 files changed, 709 insertions, 101 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py
index ffe3e6c1e..def3cac27 100644
--- a/numpy/__init__.py
+++ b/numpy/__init__.py
@@ -95,7 +95,7 @@ else:
pkgload.__doc__ = PackageLoader.__call__.__doc__
- from testing.pkgtester import Tester
+ from testing import Tester
test = Tester().test
bench = Tester().bench
diff --git a/numpy/core/__init__.py b/numpy/core/__init__.py
index e2beb3fb3..469503e25 100644
--- a/numpy/core/__init__.py
+++ b/numpy/core/__init__.py
@@ -31,6 +31,6 @@ __all__ += rec.__all__
__all__ += char.__all__
-from numpy.testing.pkgtester import Tester
+from numpy.testing import Tester
test = Tester().test
bench = Tester().bench
diff --git a/numpy/core/tests/test_defmatrix.py b/numpy/core/tests/test_defmatrix.py
index d5f4ebfaa..98ca393c1 100644
--- a/numpy/core/tests/test_defmatrix.py
+++ b/numpy/core/tests/test_defmatrix.py
@@ -260,4 +260,4 @@ class TestNewScalarIndexing(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/core/tests/test_errstate.py b/numpy/core/tests/test_errstate.py
index b8b98d138..6604d74db 100644
--- a/numpy/core/tests/test_errstate.py
+++ b/numpy/core/tests/test_errstate.py
@@ -54,4 +54,4 @@ class TestErrstate(TestCase):
"""
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/core/tests/test_memmap.py b/numpy/core/tests/test_memmap.py
index ce51514d4..32c01621e 100644
--- a/numpy/core/tests/test_memmap.py
+++ b/numpy/core/tests/test_memmap.py
@@ -47,4 +47,5 @@ class TestMemmap(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
+
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 723536908..2bfd7df41 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -893,4 +893,4 @@ class TestStats(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py
index 4cae58f31..1006598e5 100644
--- a/numpy/core/tests/test_numeric.py
+++ b/numpy/core/tests/test_numeric.py
@@ -773,4 +773,5 @@ class TestStdVarComplex(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
+
diff --git a/numpy/core/tests/test_numerictypes.py b/numpy/core/tests/test_numerictypes.py
index 0384cf88a..f0ab020c4 100644
--- a/numpy/core/tests/test_numerictypes.py
+++ b/numpy/core/tests/test_numerictypes.py
@@ -356,4 +356,5 @@ class TestCommonType(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
+
diff --git a/numpy/core/tests/test_records.py b/numpy/core/tests/test_records.py
index 450aa77ef..8c611dac8 100644
--- a/numpy/core/tests/test_records.py
+++ b/numpy/core/tests/test_records.py
@@ -116,4 +116,5 @@ class TestRecord(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
+
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index 353d76d04..71b417c25 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1154,4 +1154,4 @@ class TestRegression(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/core/tests/test_scalarmath.py b/numpy/core/tests/test_scalarmath.py
index 4a884607a..253ec862e 100644
--- a/numpy/core/tests/test_scalarmath.py
+++ b/numpy/core/tests/test_scalarmath.py
@@ -113,4 +113,4 @@ class TestRepr(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py
index a958d67e0..a624c89e1 100644
--- a/numpy/core/tests/test_ufunc.py
+++ b/numpy/core/tests/test_ufunc.py
@@ -234,4 +234,4 @@ class TestUfunc(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index a57692f5f..44b21dc51 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -222,4 +222,4 @@ class TestAttributes(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/core/tests/test_unicode.py b/numpy/core/tests/test_unicode.py
index 40ddd584e..ea132cd55 100644
--- a/numpy/core/tests/test_unicode.py
+++ b/numpy/core/tests/test_unicode.py
@@ -320,5 +320,5 @@ class test_byteorder_1009_ucs4(byteorder_values, TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/distutils/__init__.py b/numpy/distutils/__init__.py
index 893ab4411..10dec7373 100644
--- a/numpy/distutils/__init__.py
+++ b/numpy/distutils/__init__.py
@@ -15,6 +15,6 @@ except ImportError:
_INSTALLED = False
if _INSTALLED:
- from numpy.testing.pkgtester import Tester
+ from numpy.testing import Tester
test = Tester().test
bench = Tester().bench
diff --git a/numpy/distutils/tests/f2py_ext/tests/test_fib2.py b/numpy/distutils/tests/f2py_ext/tests/test_fib2.py
index 295397aad..8ea7bbfe5 100644
--- a/numpy/distutils/tests/f2py_ext/tests/test_fib2.py
+++ b/numpy/distutils/tests/f2py_ext/tests/test_fib2.py
@@ -10,4 +10,4 @@ class TestFib2(TestCase):
assert_array_equal(fib2.fib(6),[0,1,1,2,3,5])
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/distutils/tests/f2py_f90_ext/tests/test_foo.py b/numpy/distutils/tests/f2py_f90_ext/tests/test_foo.py
index 40402e949..4e2bb0cf4 100644
--- a/numpy/distutils/tests/f2py_f90_ext/tests/test_foo.py
+++ b/numpy/distutils/tests/f2py_f90_ext/tests/test_foo.py
@@ -10,4 +10,4 @@ class TestFoo(TestCase):
assert_equal(foo.foo_free.bar13(),13)
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/distutils/tests/gen_ext/tests/test_fib3.py b/numpy/distutils/tests/gen_ext/tests/test_fib3.py
index 0c1e2d60d..59e41fbbe 100644
--- a/numpy/distutils/tests/gen_ext/tests/test_fib3.py
+++ b/numpy/distutils/tests/gen_ext/tests/test_fib3.py
@@ -10,4 +10,4 @@ class TestFib3(TestCase):
assert_array_equal(fib3.fib(6),[0,1,1,2,3,5])
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/distutils/tests/pyrex_ext/tests/test_primes.py b/numpy/distutils/tests/pyrex_ext/tests/test_primes.py
index c08da8651..7fe03e97f 100644
--- a/numpy/distutils/tests/pyrex_ext/tests/test_primes.py
+++ b/numpy/distutils/tests/pyrex_ext/tests/test_primes.py
@@ -10,4 +10,4 @@ class TestPrimes(TestCase):
l = primes(10)
assert_equal(l, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29])
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/distutils/tests/swig_ext/tests/test_example.py b/numpy/distutils/tests/swig_ext/tests/test_example.py
index 6a3895295..11dea220f 100644
--- a/numpy/distutils/tests/swig_ext/tests/test_example.py
+++ b/numpy/distutils/tests/swig_ext/tests/test_example.py
@@ -15,4 +15,4 @@ class TestExample(TestCase):
assert_equal(example.cvar.My_variable,5.0)
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/distutils/tests/swig_ext/tests/test_example2.py b/numpy/distutils/tests/swig_ext/tests/test_example2.py
index 3cb1db201..062c3e6ea 100644
--- a/numpy/distutils/tests/swig_ext/tests/test_example2.py
+++ b/numpy/distutils/tests/swig_ext/tests/test_example2.py
@@ -14,4 +14,4 @@ class TestExample2(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/distutils/tests/test_fcompiler_gnu.py b/numpy/distutils/tests/test_fcompiler_gnu.py
index 99384bc8f..8158bb749 100644
--- a/numpy/distutils/tests/test_fcompiler_gnu.py
+++ b/numpy/distutils/tests/test_fcompiler_gnu.py
@@ -49,4 +49,4 @@ class TestGortranVersions(TestCase):
if __name__ == '__main__':
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/distutils/tests/test_misc_util.py b/numpy/distutils/tests/test_misc_util.py
index fed1567b7..6130d0eea 100644
--- a/numpy/distutils/tests/test_misc_util.py
+++ b/numpy/distutils/tests/test_misc_util.py
@@ -58,4 +58,4 @@ class TestGpaths(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/doc/DISTUTILS.txt b/numpy/doc/DISTUTILS.txt
index 9a7672d0e..b1a50f376 100644
--- a/numpy/doc/DISTUTILS.txt
+++ b/numpy/doc/DISTUTILS.txt
@@ -471,7 +471,7 @@ of these classes whose names contain ``test`` or start with ``bench`` are
automatically picked up by the test machinery.
A minimal example of a ``test_yyy.py`` file that implements tests for
-a Scipy package module ``numpy.xxx.yyy`` containing a function
+a NumPy package module ``numpy.xxx.yyy`` containing a function
``zzz()``, is shown below::
import sys
@@ -493,7 +493,7 @@ a Scipy package module ``numpy.xxx.yyy`` containing a function
#...
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_tests(file)
Note that all classes that are inherited from ``TestCase`` class, are
automatically picked up by the test runner.
diff --git a/numpy/f2py/lib/parser/test_Fortran2003.py b/numpy/f2py/lib/parser/test_Fortran2003.py
index b8e8fd998..2e61a636d 100644
--- a/numpy/f2py/lib/parser/test_Fortran2003.py
+++ b/numpy/f2py/lib/parser/test_Fortran2003.py
@@ -2098,4 +2098,4 @@ if 1:
print '-----'
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/f2py/lib/parser/test_parser.py b/numpy/f2py/lib/parser/test_parser.py
index 6770ac4a5..f242b867f 100644
--- a/numpy/f2py/lib/parser/test_parser.py
+++ b/numpy/f2py/lib/parser/test_parser.py
@@ -494,4 +494,4 @@ class TestStatements(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/f2py/lib/tests/test_derived_scalar.py b/numpy/f2py/lib/tests/test_derived_scalar.py
index 76b54ae51..a7a93b07b 100644
--- a/numpy/f2py/lib/tests/test_derived_scalar.py
+++ b/numpy/f2py/lib/tests/test_derived_scalar.py
@@ -71,4 +71,4 @@ class TestM(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/f2py/lib/tests/test_module_module.py b/numpy/f2py/lib/tests/test_module_module.py
index 53348b5d8..0eec2f586 100644
--- a/numpy/f2py/lib/tests/test_module_module.py
+++ b/numpy/f2py/lib/tests/test_module_module.py
@@ -58,4 +58,4 @@ class TestM(TestCase):
foo()
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/f2py/lib/tests/test_module_scalar.py b/numpy/f2py/lib/tests/test_module_scalar.py
index 684fab1b2..e988a8e5f 100644
--- a/numpy/f2py/lib/tests/test_module_scalar.py
+++ b/numpy/f2py/lib/tests/test_module_scalar.py
@@ -55,4 +55,4 @@ class TestM(TestCase):
assert_equal(r,4)
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/f2py/lib/tests/test_scalar_function_in.py b/numpy/f2py/lib/tests/test_scalar_function_in.py
index f2497d065..ba8e23b48 100644
--- a/numpy/f2py/lib/tests/test_scalar_function_in.py
+++ b/numpy/f2py/lib/tests/test_scalar_function_in.py
@@ -530,4 +530,4 @@ class TestM(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/f2py/lib/tests/test_scalar_in_out.py b/numpy/f2py/lib/tests/test_scalar_in_out.py
index 2f8ccceab..c0f10be89 100644
--- a/numpy/f2py/lib/tests/test_scalar_in_out.py
+++ b/numpy/f2py/lib/tests/test_scalar_in_out.py
@@ -527,4 +527,4 @@ class TestM(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/f2py/tests/array_from_pyobj/tests/test_array_from_pyobj.py b/numpy/f2py/tests/array_from_pyobj/tests/test_array_from_pyobj.py
index 67df2f09c..771a7f79b 100644
--- a/numpy/f2py/tests/array_from_pyobj/tests/test_array_from_pyobj.py
+++ b/numpy/f2py/tests/array_from_pyobj/tests/test_array_from_pyobj.py
@@ -513,4 +513,4 @@ class test_%s_gen(unittest.TestCase,
''' % (t,t,t)
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/fft/__init__.py b/numpy/fft/__init__.py
index d7f6c3d87..324e39f4d 100644
--- a/numpy/fft/__init__.py
+++ b/numpy/fft/__init__.py
@@ -4,6 +4,6 @@ from info import __doc__
from fftpack import *
from helper import *
-from numpy.testing.pkgtester import Tester
+from numpy.testing import Tester
test = Tester().test
bench = Tester().bench
diff --git a/numpy/fft/tests/test_fftpack.py b/numpy/fft/tests/test_fftpack.py
index 149611e6a..1e896b589 100644
--- a/numpy/fft/tests/test_fftpack.py
+++ b/numpy/fft/tests/test_fftpack.py
@@ -23,4 +23,4 @@ class TestFFT1D(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/fft/tests/test_helper.py b/numpy/fft/tests/test_helper.py
index 42678fb79..7239941e2 100644
--- a/numpy/fft/tests/test_helper.py
+++ b/numpy/fft/tests/test_helper.py
@@ -42,4 +42,4 @@ class TestFFTFreq(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/lib/__init__.py b/numpy/lib/__init__.py
index 643320bc0..aeb43fafb 100644
--- a/numpy/lib/__init__.py
+++ b/numpy/lib/__init__.py
@@ -34,7 +34,7 @@ __all__ += arraysetops.__all__
__all__ += io.__all__
__all__ += financial.__all__
-from numpy.testing.pkgtester import Tester
+from numpy.testing 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 695da0470..abb58701d 100644
--- a/numpy/lib/tests/test__datasource.py
+++ b/numpy/lib/tests/test__datasource.py
@@ -304,4 +304,5 @@ class TestOpenFunc(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
+
diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py
index ca505e9c5..0a15aa8b0 100644
--- a/numpy/lib/tests/test_arraysetops.py
+++ b/numpy/lib/tests/test_arraysetops.py
@@ -172,4 +172,4 @@ class TestAso(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/lib/tests/test_financial.py b/numpy/lib/tests/test_financial.py
index df5a0fbde..e0f20224d 100644
--- a/numpy/lib/tests/test_financial.py
+++ b/numpy/lib/tests/test_financial.py
@@ -37,4 +37,4 @@ def test():
doctest.testmod()
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py
index 4a473c55e..eecbf7356 100644
--- a/numpy/lib/tests/test_format.py
+++ b/numpy/lib/tests/test_format.py
@@ -509,4 +509,4 @@ def test_read_version_1_0_bad_magic():
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index c885f49af..77e572f7a 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -624,4 +624,4 @@ class TestPiecewise(TestCase):
assert y == 0
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/lib/tests/test_getlimits.py b/numpy/lib/tests/test_getlimits.py
index a6be8abd2..3fe939b32 100644
--- a/numpy/lib/tests/test_getlimits.py
+++ b/numpy/lib/tests/test_getlimits.py
@@ -52,4 +52,4 @@ class TestIinfo(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py
index 51d8e59db..2b92ce38e 100644
--- a/numpy/lib/tests/test_index_tricks.py
+++ b/numpy/lib/tests/test_index_tricks.py
@@ -57,4 +57,5 @@ class TestConcatenator(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
+
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 7cc595d4f..a8d2f78e4 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -198,4 +198,4 @@ class Testfromregex(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/lib/tests/test_machar.py b/numpy/lib/tests/test_machar.py
index 7485fc6c2..64abf7236 100644
--- a/numpy/lib/tests/test_machar.py
+++ b/numpy/lib/tests/test_machar.py
@@ -28,4 +28,4 @@ class TestMachAr(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/lib/tests/test_polynomial.py b/numpy/lib/tests/test_polynomial.py
index 3bd002cc0..406c151a1 100644
--- a/numpy/lib/tests/test_polynomial.py
+++ b/numpy/lib/tests/test_polynomial.py
@@ -112,4 +112,5 @@ class TestDocs(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
+
diff --git a/numpy/lib/tests/test_regression.py b/numpy/lib/tests/test_regression.py
index a5ba55928..5bc2d1d96 100644
--- a/numpy/lib/tests/test_regression.py
+++ b/numpy/lib/tests/test_regression.py
@@ -30,4 +30,5 @@ class TestRegression(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
+
diff --git a/numpy/lib/tests/test_shape_base.py b/numpy/lib/tests/test_shape_base.py
index 60265cd80..a578c27de 100644
--- a/numpy/lib/tests/test_shape_base.py
+++ b/numpy/lib/tests/test_shape_base.py
@@ -446,4 +446,4 @@ def compare_results(res,desired):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/lib/tests/test_twodim_base.py b/numpy/lib/tests/test_twodim_base.py
index 33a685bcf..fa50265e7 100644
--- a/numpy/lib/tests/test_twodim_base.py
+++ b/numpy/lib/tests/test_twodim_base.py
@@ -199,4 +199,5 @@ class TestTri(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
+
diff --git a/numpy/lib/tests/test_type_check.py b/numpy/lib/tests/test_type_check.py
index 80f112427..a89e78644 100644
--- a/numpy/lib/tests/test_type_check.py
+++ b/numpy/lib/tests/test_type_check.py
@@ -278,4 +278,4 @@ class TestArrayConversion(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/lib/tests/test_ufunclike.py b/numpy/lib/tests/test_ufunclike.py
index f734355bd..a7fbccea1 100644
--- a/numpy/lib/tests/test_ufunclike.py
+++ b/numpy/lib/tests/test_ufunclike.py
@@ -59,10 +59,10 @@ array([ 2.169925 , 1.20163386, 2.70043972])
from numpy.testing import *
-class TestDocs(TestCase):
- def test_doctests(self):
- return rundocs()
+def test():
+ return rundocs()
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
+
diff --git a/numpy/linalg/__init__.py b/numpy/linalg/__init__.py
index 842c791d2..835fb74a6 100644
--- a/numpy/linalg/__init__.py
+++ b/numpy/linalg/__init__.py
@@ -3,6 +3,6 @@ from info import __doc__
from linalg import *
-from numpy.testing.pkgtester import Tester
+from numpy.testing import Tester
test = Tester().test
bench = Tester().test
diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py
index 58c5cd456..4481e4831 100644
--- a/numpy/linalg/tests/test_linalg.py
+++ b/numpy/linalg/tests/test_linalg.py
@@ -205,4 +205,4 @@ class TestBoolPower(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/linalg/tests/test_regression.py b/numpy/linalg/tests/test_regression.py
index ec9bc695f..c1b118770 100644
--- a/numpy/linalg/tests/test_regression.py
+++ b/numpy/linalg/tests/test_regression.py
@@ -56,4 +56,4 @@ class TestRegression(TestCase):
if __name__ == '__main__':
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/ma/__init__.py b/numpy/ma/__init__.py
index bdf7f6f7a..46aee2082 100644
--- a/numpy/ma/__init__.py
+++ b/numpy/ma/__init__.py
@@ -21,6 +21,6 @@ __all__ = ['core', 'extras']
__all__ += core.__all__
__all__ += extras.__all__
-from numpy.testing.pkgtester import Tester
+from numpy.testing import Tester
test = Tester().test
bench = Tester().bench
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 9203e575e..7c79ef1cd 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -2147,4 +2147,4 @@ class TestMaskedFields(TestCase):
###############################################################################
#------------------------------------------------------------------------------
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py
index 722b88cb0..2d177fbc1 100644
--- a/numpy/ma/tests/test_extras.py
+++ b/numpy/ma/tests/test_extras.py
@@ -385,4 +385,4 @@ class TestPolynomial(TestCase):
###############################################################################
#------------------------------------------------------------------------------
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/ma/tests/test_mrecords.py b/numpy/ma/tests/test_mrecords.py
index 9083d227c..7b5092b9c 100644
--- a/numpy/ma/tests/test_mrecords.py
+++ b/numpy/ma/tests/test_mrecords.py
@@ -429,4 +429,4 @@ class TestMRecordsImport(TestCase):
###############################################################################
#------------------------------------------------------------------------------
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/ma/tests/test_old_ma.py b/numpy/ma/tests/test_old_ma.py
index 81d68df5a..d7940764e 100644
--- a/numpy/ma/tests/test_old_ma.py
+++ b/numpy/ma/tests/test_old_ma.py
@@ -866,4 +866,4 @@ def eqmask(m1, m2):
#testinplace.test_name = 'Inplace operations'
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/ma/tests/test_subclassing.py b/numpy/ma/tests/test_subclassing.py
index d61087f01..4d9842506 100644
--- a/numpy/ma/tests/test_subclassing.py
+++ b/numpy/ma/tests/test_subclassing.py
@@ -154,7 +154,7 @@ class TestSubclassing(TestCase):
################################################################################
if __name__ == '__main__':
- nose.run(argv=['', __file__])
+ run_module_suite()
if 0:
x = array(arange(5), mask=[0]+[1]*4)
diff --git a/numpy/numarray/__init__.py b/numpy/numarray/__init__.py
index b7736db3c..441ec4450 100644
--- a/numpy/numarray/__init__.py
+++ b/numpy/numarray/__init__.py
@@ -25,6 +25,6 @@ del functions
del ufuncs
del compat
-from numpy.testing.pkgtester import Tester
+from numpy.testing import Tester
test = Tester().test
bench = Tester().bench
diff --git a/numpy/oldnumeric/__init__.py b/numpy/oldnumeric/__init__.py
index ad30ba68e..05712c02c 100644
--- a/numpy/oldnumeric/__init__.py
+++ b/numpy/oldnumeric/__init__.py
@@ -40,6 +40,6 @@ del precision
del ufuncs
del misc
-from numpy.testing.pkgtester import Tester
+from numpy.testing import Tester
test = Tester().test
bench = Tester().bench
diff --git a/numpy/oldnumeric/tests/test_oldnumeric.py b/numpy/oldnumeric/tests/test_oldnumeric.py
index 6e641c756..e182a1a31 100644
--- a/numpy/oldnumeric/tests/test_oldnumeric.py
+++ b/numpy/oldnumeric/tests/test_oldnumeric.py
@@ -83,4 +83,4 @@ class test_oldtypes(NumPyTestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/random/__init__.py b/numpy/random/__init__.py
index 723285874..a60b57ccc 100644
--- a/numpy/random/__init__.py
+++ b/numpy/random/__init__.py
@@ -13,6 +13,6 @@ def __RandomState_ctor():
"""
return RandomState()
-from numpy.testing.pkgtester import Tester
+from numpy.testing import Tester
test = Tester().test
bench = Tester().bench
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py
index c42b02442..a665ff423 100644
--- a/numpy/random/tests/test_random.py
+++ b/numpy/random/tests/test_random.py
@@ -62,4 +62,4 @@ class TestSetState(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/testing/__init__.py b/numpy/testing/__init__.py
index 17ca80c37..06e49cf2a 100644
--- a/numpy/testing/__init__.py
+++ b/numpy/testing/__init__.py
@@ -10,6 +10,8 @@ from unittest import TestCase
import decorators as dec
from utils import *
+from parametric import ParametricTestCase
from numpytest import *
-from pkgtester import Tester
+from nosetester import NoseTester as Tester
+from nosetester import run_module_suite
test = Tester().test
diff --git a/numpy/testing/nosetester.py b/numpy/testing/nosetester.py
index d35890446..3b98363ea 100644
--- a/numpy/testing/nosetester.py
+++ b/numpy/testing/nosetester.py
@@ -6,6 +6,7 @@ Implements test and bench functions for modules.
import os
import sys
import re
+import warnings
def import_nose():
""" Import nose only when needed.
@@ -27,6 +28,15 @@ def import_nose():
return nose
+def run_module_suite(file_to_run = None):
+ if file_to_run is None:
+ f = sys._getframe(1)
+ file_to_run = f.f_locals.get('__file__', None)
+ assert file_to_run is not None
+
+ import_nose().run(argv=['',file_to_run])
+
+
class NoseTester(object):
""" Nose test runner.
@@ -39,15 +49,10 @@ class NoseTester(object):
>>> test = NoseTester().test
- In practice, because nose may not be importable, the __init__
- files actually have:
+ This class is made available as numpy.testing.Tester:
- >>> from scipy.testing.pkgtester import Tester
+ >>> from scipy.testing import Tester
>>> test = Tester().test
-
- The pkgtester module checks for the presence of nose on the path,
- returning this class if nose is present, and a null class
- otherwise.
"""
def __init__(self, package=None):
@@ -69,6 +74,26 @@ class NoseTester(object):
package = os.path.dirname(package.__file__)
self.package_path = package
+ # find the package name under test; this name is used to limit coverage
+ # reporting (if enabled)
+ pkg_temp = package
+ pkg_name = []
+ while 'site-packages' in pkg_temp:
+ pkg_temp, p2 = os.path.split(pkg_temp)
+ if p2 == 'site-packages':
+ break
+ pkg_name.append(p2)
+
+ # if package name determination failed, just default to numpy/scipy
+ if not pkg_name:
+ if 'scipy' in self.package_path:
+ self.package_name = 'scipy'
+ else:
+ self.package_name = 'numpy'
+ else:
+ pkg_name.reverse()
+ self.package_name = '.'.join(pkg_name)
+
def _add_doc(testtype):
''' Decorator to add docstring to functions using test labels
@@ -123,22 +148,51 @@ class NoseTester(object):
return argv
@_add_doc('test')
- def test(self, label='fast', verbose=1, extra_argv=None, doctests=False,
- coverage=False):
+ def test(self, label='fast', verbose=1, extra_argv=None, doctests=False,
+ coverage=False, **kwargs):
''' Run tests for module using nose
%(test_header)s
doctests : boolean
If True, run doctests in module, default False
+ coverage : boolean
+ If True, report coverage of NumPy code, default False
+ (Requires the coverage module:
+ http://nedbatchelder.com/code/modules/coverage.html)
'''
- nose = import_nose()
+ old_args = set(['level', 'verbosity', 'all', 'sys_argv', 'testcase_pattern'])
+ unexpected_args = set(kwargs.keys()) - old_args
+ if len(unexpected_args) > 0:
+ ua = ', '.join(unexpected_args)
+ raise TypeError("test() got unexpected arguments: %s" % ua)
+
+ # issue a deprecation warning if any of the pre-1.2 arguments to
+ # test are given
+ if old_args.intersection(kwargs.keys()):
+ warnings.warn("This method's signature will change in the next release; the level, verbosity, all, sys_argv, and testcase_pattern keyword arguments will be removed. Please update your code.",
+ DeprecationWarning, stacklevel=2)
+
+ # Use old arguments if given (where it makes sense)
+ # For the moment, level and sys_argv are ignored
+
+ # replace verbose with verbosity
+ if kwargs.get('verbosity') is not None:
+ verbose = kwargs.get('verbosity')
+ # cap verbosity at 3 because nose becomes *very* verbose beyond that
+ verbose = min(verbose, 3)
+
+ # if all evaluates as True, omit attribute filter and run doctests
+ if kwargs.get('all'):
+ label = ''
+ doctests = True
+
argv = self._test_argv(label, verbose, extra_argv)
if doctests:
argv+=['--with-doctest','--doctest-tests']
if coverage:
- argv+=['--cover-package=numpy','--with-coverage',
- '--cover-tests','--cover-inclusive','--cover-erase']
+ argv+=['--cover-package=%s' % self.package_name, '--with-coverage',
+ '--cover-tests', '--cover-inclusive', '--cover-erase']
# bypass these samples under distutils
argv += ['--exclude','f2py_ext']
@@ -147,7 +201,28 @@ class NoseTester(object):
argv += ['--exclude','pyrex_ext']
argv += ['--exclude','swig_ext']
- nose.run(argv=argv)
+ nose = import_nose()
+
+ # Because nose currently discards the test result object, but we need to
+ # return it to the user, override TestProgram.runTests to retain the result
+ class NumpyTestProgram(nose.core.TestProgram):
+ def runTests(self):
+ """Run Tests. Returns true on success, false on failure, and sets
+ self.success to the same value.
+ """
+ if self.testRunner is None:
+ self.testRunner = nose.core.TextTestRunner(stream=self.config.stream,
+ verbosity=self.config.verbosity,
+ config=self.config)
+ plug_runner = self.config.plugins.prepareTestRunner(self.testRunner)
+ if plug_runner is not None:
+ self.testRunner = plug_runner
+ self.result = self.testRunner.run(self.test)
+ self.success = self.result.wasSuccessful()
+ return self.success
+
+ t = NumpyTestProgram(argv=argv, exit=False)
+ return t.result
@_add_doc('benchmark')
def bench(self, label='fast', verbose=1, extra_argv=None):
@@ -157,4 +232,4 @@ class NoseTester(object):
nose = import_nose()
argv = self._test_argv(label, verbose, extra_argv)
argv += ['--match', r'(?:^|[\\b_\\.%s-])[Bb]ench' % os.sep]
- nose.run(argv=argv)
+ return nose.run(argv=argv)
diff --git a/numpy/testing/numpytest.py b/numpy/testing/numpytest.py
index 73002f92f..4daa3bf8e 100644
--- a/numpy/testing/numpytest.py
+++ b/numpy/testing/numpytest.py
@@ -10,7 +10,7 @@ import traceback
import warnings
__all__ = ['set_package_path', 'set_local_path', 'restore_path',
- 'IgnoreException', 'importall',]
+ 'IgnoreException', 'NumpyTestCase', 'NumpyTest', 'importall',]
DEBUG=0
from numpy.testing.utils import jiffies
@@ -110,6 +110,93 @@ class _dummy_stream:
self.stream.flush()
+class NumpyTestCase (unittest.TestCase):
+ def __init__(self, *args, **kwds):
+ warnings.warn("NumpyTestCase will be removed in the next release; please update your code to use nose or unittest",
+ DeprecationWarning, stacklevel=2)
+ unittest.TestCase.__init__(self, *args, **kwds)
+
+ def measure(self,code_str,times=1):
+ """ Return elapsed time for executing code_str in the
+ namespace of the caller for given times.
+ """
+ frame = get_frame(1)
+ locs,globs = frame.f_locals,frame.f_globals
+ code = compile(code_str,
+ 'NumpyTestCase runner for '+self.__class__.__name__,
+ 'exec')
+ i = 0
+ elapsed = jiffies()
+ while i<times:
+ i += 1
+ exec code in globs,locs
+ elapsed = jiffies() - elapsed
+ return 0.01*elapsed
+
+ def __call__(self, result=None):
+ if result is None or not hasattr(result, 'errors') \
+ or not hasattr(result, 'stream'):
+ return unittest.TestCase.__call__(self, result)
+
+ nof_errors = len(result.errors)
+ save_stream = result.stream
+ result.stream = _dummy_stream(save_stream)
+ unittest.TestCase.__call__(self, result)
+ if nof_errors != len(result.errors):
+ test, errstr = result.errors[-1][:2]
+ if isinstance(errstr, tuple):
+ errstr = str(errstr[0])
+ elif isinstance(errstr, str):
+ errstr = errstr.split('\n')[-2]
+ else:
+ # allow for proxy classes
+ errstr = str(errstr).split('\n')[-2]
+ l = len(result.stream.data)
+ if errstr.startswith('IgnoreException:'):
+ if l==1:
+ assert result.stream.data[-1]=='E', \
+ repr(result.stream.data)
+ result.stream.data[-1] = 'i'
+ else:
+ assert result.stream.data[-1]=='ERROR\n', \
+ repr(result.stream.data)
+ result.stream.data[-1] = 'ignoring\n'
+ del result.errors[-1]
+ map(save_stream.write, result.stream.data)
+ save_stream.flush()
+ result.stream = save_stream
+
+ def warn(self, message):
+ from numpy.distutils.misc_util import yellow_text
+ print>>sys.stderr,yellow_text('Warning: %s' % (message))
+ sys.stderr.flush()
+ def info(self, message):
+ print>>sys.stdout, message
+ sys.stdout.flush()
+
+ def rundocs(self, filename=None):
+ """ Run doc string tests found in filename.
+ """
+ import doctest
+ if filename is None:
+ f = get_frame(1)
+ filename = f.f_globals['__file__']
+ name = os.path.splitext(os.path.basename(filename))[0]
+ path = [os.path.dirname(filename)]
+ file, pathname, description = imp.find_module(name, path)
+ try:
+ m = imp.load_module(name, file, pathname, description)
+ finally:
+ file.close()
+ if sys.version[:3]<'2.4':
+ doctest.testmod(m, verbose=False)
+ else:
+ tests = doctest.DocTestFinder().find(m)
+ runner = doctest.DocTestRunner(verbose=False)
+ for test in tests:
+ runner.run(test)
+ return
+
def _get_all_method_names(cls):
names = dir(cls)
@@ -122,6 +209,455 @@ def _get_all_method_names(cls):
# for debug build--check for memory leaks during the test.
+class _NumPyTextTestResult(unittest._TextTestResult):
+ def startTest(self, test):
+ unittest._TextTestResult.startTest(self, test)
+ if self.showAll:
+ N = len(sys.getobjects(0))
+ self._totnumobj = N
+ self._totrefcnt = sys.gettotalrefcount()
+ return
+
+ def stopTest(self, test):
+ if self.showAll:
+ N = len(sys.getobjects(0))
+ self.stream.write("objects: %d ===> %d; " % (self._totnumobj, N))
+ self.stream.write("refcnts: %d ===> %d\n" % (self._totrefcnt,
+ sys.gettotalrefcount()))
+ return
+
+class NumPyTextTestRunner(unittest.TextTestRunner):
+ def _makeResult(self):
+ return _NumPyTextTestResult(self.stream, self.descriptions, self.verbosity)
+
+
+class NumpyTest:
+ """ Numpy tests site manager.
+
+ Usage: NumpyTest(<package>).test(level=1,verbosity=1)
+
+ <package> is package name or its module object.
+
+ Package is supposed to contain a directory tests/ with test_*.py
+ files where * refers to the names of submodules. See .rename()
+ method to redefine name mapping between test_*.py files and names of
+ submodules. Pattern test_*.py can be overwritten by redefining
+ .get_testfile() method.
+
+ test_*.py files are supposed to define a classes, derived from
+ NumpyTestCase or unittest.TestCase, with methods having names
+ starting with test or bench or check. The names of TestCase classes
+ must have a prefix test. This can be overwritten by redefining
+ .check_testcase_name() method.
+
+ And that is it! No need to implement test or test_suite functions
+ in each .py file.
+
+ Old-style test_suite(level=1) hooks are also supported.
+ """
+ _check_testcase_name = re.compile(r'test.*|Test.*').match
+ def check_testcase_name(self, name):
+ """ Return True if name matches TestCase class.
+ """
+ return not not self._check_testcase_name(name)
+
+ testfile_patterns = ['test_%(modulename)s.py']
+ def get_testfile(self, module, verbosity = 0):
+ """ Return path to module test file.
+ """
+ mstr = self._module_str
+ short_module_name = self._get_short_module_name(module)
+ d = os.path.split(module.__file__)[0]
+ test_dir = os.path.join(d,'tests')
+ local_test_dir = os.path.join(os.getcwd(),'tests')
+ if os.path.basename(os.path.dirname(local_test_dir)) \
+ == os.path.basename(os.path.dirname(test_dir)):
+ test_dir = local_test_dir
+ for pat in self.testfile_patterns:
+ fn = os.path.join(test_dir, pat % {'modulename':short_module_name})
+ if os.path.isfile(fn):
+ return fn
+ if verbosity>1:
+ self.warn('No test file found in %s for module %s' \
+ % (test_dir, mstr(module)))
+ return
+
+ def __init__(self, package=None):
+ warnings.warn("NumpyTest will be removed in the next release; please update your code to use nose or unittest",
+ DeprecationWarning, stacklevel=2)
+ if package is None:
+ from numpy.distutils.misc_util import get_frame
+ f = get_frame(1)
+ package = f.f_locals.get('__name__',f.f_globals.get('__name__',None))
+ assert package is not None
+ self.package = package
+ self._rename_map = {}
+
+ def rename(self, **kws):
+ """Apply renaming submodule test file test_<name>.py to
+ test_<newname>.py.
+
+ Usage: self.rename(name='newname') before calling the
+ self.test() method.
+
+ If 'newname' is None, then no tests will be executed for a given
+ module.
+ """
+ for k,v in kws.items():
+ self._rename_map[k] = v
+ return
+
+ def _module_str(self, module):
+ filename = module.__file__[-30:]
+ if filename!=module.__file__:
+ filename = '...'+filename
+ return '<module %r from %r>' % (module.__name__, filename)
+
+ def _get_method_names(self,clsobj,level):
+ names = []
+ for mthname in _get_all_method_names(clsobj):
+ if mthname[:5] not in ['bench','check'] \
+ and mthname[:4] not in ['test']:
+ continue
+ mth = getattr(clsobj, mthname)
+ if type(mth) is not types.MethodType:
+ continue
+ d = mth.im_func.func_defaults
+ if d is not None:
+ mthlevel = d[0]
+ else:
+ mthlevel = 1
+ if level>=mthlevel:
+ if mthname not in names:
+ names.append(mthname)
+ for base in clsobj.__bases__:
+ for n in self._get_method_names(base,level):
+ if n not in names:
+ names.append(n)
+ return names
+
+ def _get_short_module_name(self, module):
+ d,f = os.path.split(module.__file__)
+ short_module_name = os.path.splitext(os.path.basename(f))[0]
+ if short_module_name=='__init__':
+ short_module_name = module.__name__.split('.')[-1]
+ short_module_name = self._rename_map.get(short_module_name,short_module_name)
+ return short_module_name
+
+ def _get_module_tests(self, module, level, verbosity):
+ mstr = self._module_str
+
+ short_module_name = self._get_short_module_name(module)
+ if short_module_name is None:
+ return []
+
+ test_file = self.get_testfile(module, verbosity)
+
+ if test_file is None:
+ return []
+
+ if not os.path.isfile(test_file):
+ if short_module_name[:5]=='info_' \
+ and short_module_name[5:]==module.__name__.split('.')[-2]:
+ return []
+ if short_module_name in ['__cvs_version__','__svn_version__']:
+ return []
+ if short_module_name[-8:]=='_version' \
+ and short_module_name[:-8]==module.__name__.split('.')[-2]:
+ return []
+ if verbosity>1:
+ self.warn(test_file)
+ self.warn(' !! No test file %r found for %s' \
+ % (os.path.basename(test_file), mstr(module)))
+ return []
+
+ if test_file in self.test_files:
+ return []
+
+ parent_module_name = '.'.join(module.__name__.split('.')[:-1])
+ test_module_name,ext = os.path.splitext(os.path.basename(test_file))
+ test_dir_module = parent_module_name+'.tests'
+ test_module_name = test_dir_module+'.'+test_module_name
+
+ if test_dir_module not in sys.modules:
+ sys.modules[test_dir_module] = imp.new_module(test_dir_module)
+
+ old_sys_path = sys.path[:]
+ try:
+ f = open(test_file,'r')
+ test_module = imp.load_module(test_module_name, f,
+ test_file, ('.py', 'r', 1))
+ f.close()
+ except:
+ sys.path[:] = old_sys_path
+ self.warn('FAILURE importing tests for %s' % (mstr(module)))
+ output_exception(sys.stderr)
+ return []
+ sys.path[:] = old_sys_path
+
+ self.test_files.append(test_file)
+
+ return self._get_suite_list(test_module, level, module.__name__)
+
+ def _get_suite_list(self, test_module, level, module_name='__main__',
+ verbosity=1):
+ suite_list = []
+ if hasattr(test_module, 'test_suite'):
+ suite_list.extend(test_module.test_suite(level)._tests)
+ for name in dir(test_module):
+ obj = getattr(test_module, name)
+ if type(obj) is not type(unittest.TestCase) \
+ or not issubclass(obj, unittest.TestCase) \
+ or not self.check_testcase_name(obj.__name__):
+ continue
+ for mthname in self._get_method_names(obj,level):
+ suite = obj(mthname)
+ if getattr(suite,'isrunnable',lambda mthname:1)(mthname):
+ suite_list.append(suite)
+ matched_suite_list = [suite for suite in suite_list \
+ if self.testcase_match(suite.id()\
+ .replace('__main__.',''))]
+ if verbosity>=0:
+ self.info(' Found %s/%s tests for %s' \
+ % (len(matched_suite_list), len(suite_list), module_name))
+ return matched_suite_list
+
+ def _test_suite_from_modules(self, this_package, level, verbosity):
+ package_name = this_package.__name__
+ modules = []
+ for name, module in sys.modules.items():
+ if not name.startswith(package_name) or module is None:
+ continue
+ if not hasattr(module,'__file__'):
+ continue
+ if os.path.basename(os.path.dirname(module.__file__))=='tests':
+ continue
+ modules.append((name, module))
+
+ modules.sort()
+ modules = [m[1] for m in modules]
+
+ self.test_files = []
+ suites = []
+ for module in modules:
+ suites.extend(self._get_module_tests(module, abs(level), verbosity))
+
+ suites.extend(self._get_suite_list(sys.modules[package_name],
+ abs(level), verbosity=verbosity))
+ return unittest.TestSuite(suites)
+
+ def _test_suite_from_all_tests(self, this_package, level, verbosity):
+ importall(this_package)
+ package_name = this_package.__name__
+
+ # Find all tests/ directories under the package
+ test_dirs_names = {}
+ for name, module in sys.modules.items():
+ if not name.startswith(package_name) or module is None:
+ continue
+ if not hasattr(module, '__file__'):
+ continue
+ d = os.path.dirname(module.__file__)
+ if os.path.basename(d)=='tests':
+ continue
+ d = os.path.join(d, 'tests')
+ if not os.path.isdir(d):
+ continue
+ if d in test_dirs_names:
+ continue
+ test_dir_module = '.'.join(name.split('.')[:-1]+['tests'])
+ test_dirs_names[d] = test_dir_module
+
+ test_dirs = test_dirs_names.keys()
+ test_dirs.sort()
+
+ # For each file in each tests/ directory with a test case in it,
+ # import the file, and add the test cases to our list
+ suite_list = []
+ testcase_match = re.compile(r'\s*class\s+\w+\s*\(.*TestCase').match
+ for test_dir in test_dirs:
+ test_dir_module = test_dirs_names[test_dir]
+
+ if test_dir_module not in sys.modules:
+ sys.modules[test_dir_module] = imp.new_module(test_dir_module)
+
+ for fn in os.listdir(test_dir):
+ base, ext = os.path.splitext(fn)
+ if ext != '.py':
+ continue
+ f = os.path.join(test_dir, fn)
+
+ # check that file contains TestCase class definitions:
+ fid = open(f, 'r')
+ skip = True
+ for line in fid:
+ if testcase_match(line):
+ skip = False
+ break
+ fid.close()
+ if skip:
+ continue
+
+ # import the test file
+ n = test_dir_module + '.' + base
+ # in case test files import local modules
+ sys.path.insert(0, test_dir)
+ fo = None
+ try:
+ try:
+ fo = open(f)
+ test_module = imp.load_module(n, fo, f,
+ ('.py', 'U', 1))
+ except Exception, msg:
+ print 'Failed importing %s: %s' % (f,msg)
+ continue
+ finally:
+ if fo:
+ fo.close()
+ del sys.path[0]
+
+ suites = self._get_suite_list(test_module, level,
+ module_name=n,
+ verbosity=verbosity)
+ suite_list.extend(suites)
+
+ all_tests = unittest.TestSuite(suite_list)
+ return all_tests
+
+ def test(self, level=1, verbosity=1, all=True, sys_argv=[],
+ testcase_pattern='.*'):
+ """Run Numpy module test suite with level and verbosity.
+
+ level:
+ None --- do nothing, return None
+ < 0 --- scan for tests of level=abs(level),
+ don't run them, return TestSuite-list
+ > 0 --- scan for tests of level, run them,
+ return TestRunner
+ > 10 --- run all tests (same as specifying all=True).
+ (backward compatibility).
+
+ verbosity:
+ >= 0 --- show information messages
+ > 1 --- show warnings on missing tests
+
+ all:
+ True --- run all test files (like self.testall())
+ False (default) --- only run test files associated with a module
+
+ sys_argv --- replacement of sys.argv[1:] during running
+ tests.
+
+ testcase_pattern --- run only tests that match given pattern.
+
+ It is assumed (when all=False) that package tests suite follows
+ the following convention: for each package module, there exists
+ file <packagepath>/tests/test_<modulename>.py that defines
+ TestCase classes (with names having prefix 'test_') with methods
+ (with names having prefixes 'check_' or 'bench_'); each of these
+ methods are called when running unit tests.
+ """
+ if level is None: # Do nothing.
+ return
+
+ if isinstance(self.package, str):
+ exec 'import %s as this_package' % (self.package)
+ else:
+ this_package = self.package
+
+ self.testcase_match = re.compile(testcase_pattern).match
+
+ if all:
+ all_tests = self._test_suite_from_all_tests(this_package,
+ level, verbosity)
+ else:
+ all_tests = self._test_suite_from_modules(this_package,
+ level, verbosity)
+
+ if level < 0:
+ return all_tests
+
+ runner = unittest.TextTestRunner(verbosity=verbosity)
+ old_sys_argv = sys.argv[1:]
+ sys.argv[1:] = sys_argv
+ # Use the builtin displayhook. If the tests are being run
+ # under IPython (for instance), any doctest test suites will
+ # fail otherwise.
+ old_displayhook = sys.displayhook
+ sys.displayhook = sys.__displayhook__
+ try:
+ r = runner.run(all_tests)
+ finally:
+ sys.displayhook = old_displayhook
+ sys.argv[1:] = old_sys_argv
+ return r
+
+ def testall(self, level=1,verbosity=1):
+ """ Run Numpy module test suite with level and verbosity.
+
+ level:
+ None --- do nothing, return None
+ < 0 --- scan for tests of level=abs(level),
+ don't run them, return TestSuite-list
+ > 0 --- scan for tests of level, run them,
+ return TestRunner
+
+ verbosity:
+ >= 0 --- show information messages
+ > 1 --- show warnings on missing tests
+
+ Different from .test(..) method, this method looks for
+ TestCase classes from all files in <packagedir>/tests/
+ directory and no assumptions are made for naming the
+ TestCase classes or their methods.
+ """
+ return self.test(level=level, verbosity=verbosity, all=True)
+
+ def run(self):
+ """ Run Numpy module test suite with level and verbosity
+ taken from sys.argv. Requires optparse module.
+ """
+ try:
+ from optparse import OptionParser
+ except ImportError:
+ self.warn('Failed to import optparse module, ignoring.')
+ return self.test()
+ usage = r'usage: %prog [-v <verbosity>] [-l <level>]'\
+ r' [-s "<replacement of sys.argv[1:]>"]'\
+ r' [-t "<testcase pattern>"]'
+ parser = OptionParser(usage)
+ parser.add_option("-v", "--verbosity",
+ action="store",
+ dest="verbosity",
+ default=1,
+ type='int')
+ parser.add_option("-l", "--level",
+ action="store",
+ dest="level",
+ default=1,
+ type='int')
+ parser.add_option("-s", "--sys-argv",
+ action="store",
+ dest="sys_argv",
+ default='',
+ type='string')
+ parser.add_option("-t", "--testcase-pattern",
+ action="store",
+ dest="testcase_pattern",
+ default=r'.*',
+ type='string')
+ (options, args) = parser.parse_args()
+ return self.test(options.level,options.verbosity,
+ sys_argv=shlex.split(options.sys_argv or ''),
+ testcase_pattern=options.testcase_pattern)
+
+ def warn(self, message):
+ from numpy.distutils.misc_util import yellow_text
+ print>>sys.stderr,yellow_text('Warning: %s' % (message))
+ sys.stderr.flush()
+ def info(self, message):
+ print>>sys.stdout, message
+ sys.stdout.flush()
def importall(package):
"""
diff --git a/numpy/testing/pkgtester.py b/numpy/testing/pkgtester.py
deleted file mode 100644
index 51e8d62c4..000000000
--- a/numpy/testing/pkgtester.py
+++ /dev/null
@@ -1,14 +0,0 @@
-''' Define test function for scipy package
-
-Module tests for presence of useful version of nose. If present
-returns NoseTester, otherwise returns a placeholder test routine
-reporting lack of nose and inability to run tests. Typical use is in
-module __init__:
-
-from scipy.testing.pkgtester import Tester
-test = Tester().test
-
-See nosetester module for test implementation
-
-'''
-from numpy.testing.nosetester import NoseTester as Tester
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py
index 27cc4a809..ea8fa044b 100644
--- a/numpy/testing/tests/test_utils.py
+++ b/numpy/testing/tests/test_utils.py
@@ -163,4 +163,4 @@ class TestRaises(unittest.TestCase):
if __name__ == '__main__':
- nose.run(argv=['', __file__])
+ run_module_suite()
diff --git a/numpy/tests/test_ctypeslib.py b/numpy/tests/test_ctypeslib.py
index 12e4dce01..f17860db4 100644
--- a/numpy/tests/test_ctypeslib.py
+++ b/numpy/tests/test_ctypeslib.py
@@ -85,4 +85,4 @@ class TestNdpointer(TestCase):
if __name__ == "__main__":
- nose.run(argv=['', __file__])
+ run_module_suite()