diff options
author | Alan McIntyre <alan.mcintyre@local> | 2008-06-17 00:23:20 +0000 |
---|---|---|
committer | Alan McIntyre <alan.mcintyre@local> | 2008-06-17 00:23:20 +0000 |
commit | c331857d8663ecf54bbe88c834755da749e8ab52 (patch) | |
tree | f4cc69ec328a5ff4d3b108f3610acb119a196493 /numpy/testing/utils.py | |
parent | 22ba7886a84dc6a16ca75871f7cd2f10ef8de1f9 (diff) | |
download | numpy-c331857d8663ecf54bbe88c834755da749e8ab52.tar.gz |
Switched to use nose to run tests. Added test and bench functions to all modules.
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r-- | numpy/testing/utils.py | 53 |
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 |