diff options
author | Alan McIntyre <alan.mcintyre@local> | 2008-07-21 06:55:48 +0000 |
---|---|---|
committer | Alan McIntyre <alan.mcintyre@local> | 2008-07-21 06:55:48 +0000 |
commit | 8e86b69357c931b9dc0544d0210f7b2a0720ef11 (patch) | |
tree | 0e2edf22cd0867ac75a6dfd4d54adeaccb14c313 /numpy/testing/utils.py | |
parent | 77effddb80562fa5e2de16ac4fb5470477bda652 (diff) | |
download | numpy-8e86b69357c931b9dc0544d0210f7b2a0720ef11.tar.gz |
Added numpy.testing.verbose, to allow tests to vary output accordingly.
Added numpy.testing.print_assert_equal, to allow removing the multiple
identical implementations of this function in SciPy tests.
Display version info for NumPy, Python, and nose (and SciPy when running SciPy
tests), in a manner similar to the original test framework.
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r-- | numpy/testing/utils.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index 2051bc7bc..c27d524c9 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -13,8 +13,10 @@ from nosetester import import_nose __all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal', 'assert_array_equal', 'assert_array_less', 'assert_string_equal', 'assert_array_almost_equal', 'assert_raises', 'build_err_msg', - 'decorate_methods', 'jiffies', 'memusage', 'raises', 'rand', - 'rundocs', 'runstring'] + 'decorate_methods', 'jiffies', 'memusage', 'print_assert_equal', + 'raises', 'rand', 'rundocs', 'runstring', 'verbose'] + +verbose = 0 def rand(*args): """Returns an array of random numbers with the given shape. @@ -147,6 +149,20 @@ def assert_equal(actual,desired,err_msg='',verbose=True): msg = build_err_msg([actual, desired], err_msg, verbose=verbose) assert desired == actual, msg +def print_assert_equal(test_string,actual,desired): + import pprint + try: + assert(actual == desired) + except AssertionError: + import cStringIO + msg = cStringIO.StringIO() + msg.write(test_string) + msg.write(' failed\nACTUAL: \n') + pprint.pprint(actual,msg) + msg.write('DESIRED: \n') + pprint.pprint(desired,msg) + raise AssertionError, msg.getvalue() + def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raise an assertion if two items are not equal. |