From 37f318c8be5c0f0eb7e7d217690446fbbc0d50d2 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Mon, 7 Dec 2009 22:22:10 +0000 Subject: BUG: make assert_equal and assert_almost_equal always display err_msg --- numpy/testing/utils.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'numpy/testing/utils.py') diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index 08cec9a8b..87ca389f7 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -273,9 +273,7 @@ def assert_equal(actual,desired,err_msg='',verbose=True): assert_equal(actualr, desiredr) assert_equal(actuali, desiredi) except AssertionError: - raise AssertionError("Items are not equal:\n" \ - "ACTUAL: %s\n" \ - "DESIRED: %s\n" % (str(actual), str(desired))) + raise AssertionError(msg) # Inf/nan/negative zero handling try: @@ -413,6 +411,9 @@ 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') + if usecomplex: if iscomplexobj(actual): actualr = real(actual) @@ -430,15 +431,11 @@ 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("Items are not equal:\n" \ - "ACTUAL: %s\n" \ - "DESIRED: %s\n" % (str(actual), str(desired))) + raise AssertionError(msg) if isinstance(actual, (ndarray, tuple, list)) \ or isinstance(desired, (ndarray, tuple, list)): return assert_array_almost_equal(actual, desired, decimal, err_msg) - msg = build_err_msg([actual, desired], err_msg, verbose=verbose, - header='Arrays are not almost equal') try: # If one of desired/actual is not finite, handle it specially here: # check that both are nan if any is a nan, and test for equality -- cgit v1.2.1