summaryrefslogtreecommitdiff
path: root/numpy/testing/utils.py
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2013-09-24 00:50:16 +0200
committerJulian Taylor <jtaylor.debian@googlemail.com>2013-09-24 00:50:16 +0200
commit79d3a94f41b7e3c661eceed2f26ba6cce362ba4f (patch)
treec8b1a72ba7e7e22a2529d954f033b4911d774a5b /numpy/testing/utils.py
parent2657098fb9d14087a7307c917029d7f911f6ef6d (diff)
downloadnumpy-79d3a94f41b7e3c661eceed2f26ba6cce362ba4f.tar.gz
TST: delay error message building to failures in assert_almost_equal
improves test performance by about 15%
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r--numpy/testing/utils.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
index b9300d612..1aee5c507 100644
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -427,8 +427,10 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True):
except ValueError:
usecomplex = False
- msg = build_err_msg([actual, desired], err_msg, verbose=verbose,
- header=('Arrays are not almost equal to %d decimals' % decimal))
+ def _build_err_msg():
+ header = ('Arrays are not almost equal to %d decimals' % decimal)
+ return build_err_msg([actual, desired], err_msg, verbose=verbose,
+ header=header)
if usecomplex:
if iscomplexobj(actual):
@@ -447,7 +449,7 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True):
assert_almost_equal(actualr, desiredr, decimal=decimal)
assert_almost_equal(actuali, desiredi, decimal=decimal)
except AssertionError:
- raise AssertionError(msg)
+ raise AssertionError(_build_err_msg())
if isinstance(actual, (ndarray, tuple, list)) \
or isinstance(desired, (ndarray, tuple, list)):
@@ -459,15 +461,15 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True):
if not (gisfinite(desired) and gisfinite(actual)):
if gisnan(desired) or gisnan(actual):
if not (gisnan(desired) and gisnan(actual)):
- raise AssertionError(msg)
+ raise AssertionError(_build_err_msg())
else:
if not desired == actual:
- raise AssertionError(msg)
+ raise AssertionError(_build_err_msg())
return
except (NotImplementedError, TypeError):
pass
if round(abs(desired - actual), decimal) != 0 :
- raise AssertionError(msg)
+ raise AssertionError(_build_err_msg())
def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True):