diff options
author | Alan McIntyre <alan.mcintyre@local> | 2008-06-17 02:17:34 +0000 |
---|---|---|
committer | Alan McIntyre <alan.mcintyre@local> | 2008-06-17 02:17:34 +0000 |
commit | 2bdd23ef6ddabcf24ef68f08fe7a737e4b52f355 (patch) | |
tree | e2a6f8f65cd88e8cfc5420f9a52fd80ed73f4cab /numpy/testing/utils.py | |
parent | 70974af863b99d49d9a1cf947afc019976e6b8b4 (diff) | |
download | numpy-2bdd23ef6ddabcf24ef68f08fe7a737e4b52f355.tar.gz |
Update README.txt to indicate nose version dependency, and port SciPy r4424 to NumPy
(prevent import of nose until actual execution of tests). Restored
"raises" function to numpy/testing/utils.py until it can be replaced with the function of
the same name from nose.tools after the lazy import.
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r-- | numpy/testing/utils.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index 538014f33..3e99fd386 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -11,7 +11,7 @@ import operator __all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal', 'assert_array_equal', 'assert_array_less', 'assert_string_equal', 'assert_array_almost_equal', 'build_err_msg', 'jiffies', 'memusage', - 'rand', 'rundocs', 'runstring'] + 'raises', 'rand', 'rundocs', 'runstring'] def rand(*args): """Returns an array of random numbers with the given shape. @@ -317,3 +317,34 @@ def rundocs(filename=None): for test in tests: runner.run(test) return + + +def raises(*exceptions): + """ Assert that a test function raises one of the specified exceptions to + pass. + """ + # 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 |