diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-07-06 07:06:44 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-07-06 07:06:44 +0000 |
commit | 640a99d367e691eef576af04a29da06ba34acf23 (patch) | |
tree | c28ada0b8be4b58b0b07abdf73f28d6c13a20676 /numpy/testing/utils.py | |
parent | 485f171d57748773f8f8d162e89cb668cfc55c11 (diff) | |
download | numpy-640a99d367e691eef576af04a29da06ba34acf23.tar.gz |
Fix assert_array_compare to handle boolean return from equality testing (which can happen)
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r-- | numpy/testing/utils.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index ee7439d50..15323854d 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -180,7 +180,7 @@ def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True): verbose=verbose) assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg -def assert_array_compare(comparision, x, y, err_msg='', verbose=True, +def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header=''): from numpy.core import asarray x = asarray(x) @@ -195,10 +195,16 @@ def assert_array_compare(comparision, x, y, err_msg='', verbose=True, verbose=verbose, header=header, names=('x', 'y')) assert cond, msg - reduced = comparision(x, y).ravel() - cond = reduced.all() + val = comparison(x,y) + if isinstance(val, bool): + cond = val + reduced = [0] + else: + reduced = val.ravel() + cond = reduced.all() + reduced = reduced.tolist() if not cond: - match = 100-100.0*reduced.tolist().count(1)/len(reduced) + match = 100-100.0*reduced.count(1)/len(reduced) msg = build_err_msg([x, y], err_msg + '\n(mismatch %s%%)' % (match,), |