summaryrefslogtreecommitdiff
path: root/numpy/testing/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r--numpy/testing/utils.py53
1 files changed, 23 insertions, 30 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
index 680b4f168..538014f33 100644
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -10,8 +10,8 @@ import operator
__all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal',
'assert_array_equal', 'assert_array_less', 'assert_string_equal',
- 'assert_array_almost_equal', 'jiffies', 'memusage', 'rand',
- 'runstring', 'raises']
+ 'assert_array_almost_equal', 'build_err_msg', 'jiffies', 'memusage',
+ 'rand', 'rundocs', 'runstring']
def rand(*args):
"""Returns an array of random numbers with the given shape.
@@ -295,32 +295,25 @@ def assert_string_equal(actual, desired):
assert actual==desired, msg
-def raises(*exceptions):
- """ Assert that a test function raises one of the specified exceptions to
- pass.
+def rundocs(filename=None):
+ """ Run doc string tests found in filename.
"""
- # FIXME: when we transition to nose, just use its implementation. It's
- # better.
- def deco(function):
- def f2(*args, **kwds):
- try:
- function(*args, **kwds)
- except exceptions:
- pass
- except:
- # Anything else.
- raise
- else:
- raise AssertionError('%s() did not raise one of (%s)' %
- (function.__name__, ', '.join([e.__name__ for e in exceptions])))
- try:
- f2.__name__ = function.__name__
- except TypeError:
- # Python 2.3 does not permit this.
- pass
- f2.__dict__ = function.__dict__
- f2.__doc__ = function.__doc__
- f2.__module__ = function.__module__
- return f2
-
- return deco
+ import doctest, imp
+ if filename is None:
+ f = sys._getframe(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