diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2016-02-21 15:20:42 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2016-02-21 15:20:42 -0700 |
commit | a6efa09837b3a71eb6f6450b7dcf08c7381e75d0 (patch) | |
tree | 097a05d37f3f38872e34da0a31ce2345f534355d | |
parent | 1e6666aad7a35f2d8981ea322db147d41bbbdca0 (diff) | |
parent | 91a86f6715604183741f84d429a3a5c2fc7d7e9e (diff) | |
download | numpy-a6efa09837b3a71eb6f6450b7dcf08c7381e75d0.tar.gz |
Merge pull request #7292 from anntzer/assert-equal-repr-failed
Clarify error on repr failure in assert_equal.
-rw-r--r-- | numpy/testing/tests/test_utils.py | 13 | ||||
-rw-r--r-- | numpy/testing/utils.py | 4 |
2 files changed, 15 insertions, 2 deletions
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 7de57d408..fe1f411c4 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -227,6 +227,19 @@ class TestEqual(TestArrayEqual): self._assert_func(x, x) self._test_not_equal(x, y) + def test_error_message(self): + try: + self._assert_func(np.array([1, 2]), np.matrix([1, 2])) + except AssertionError as e: + self.assertEqual( + str(e), + "\nArrays are not equal\n\n" + "(shapes (2,), (1, 2) mismatch)\n" + " x: array([1, 2])\n" + " y: [repr failed for <matrix>: The truth value of an array " + "with more than one element is ambiguous. Use a.any() or " + "a.all()]") + class TestArrayAlmostEqual(_GenericTest, unittest.TestCase): diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index f2588788d..133330a12 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -252,8 +252,8 @@ def build_err_msg(arrays, err_msg, header='Items are not equal:', try: r = r_func(a) - except: - r = '[repr failed]' + except Exception as exc: + r = '[repr failed for <{}>: {}]'.format(type(a).__name__, exc) if r.count('\n') > 3: r = '\n'.join(r.splitlines()[:3]) r += '...' |