diff options
| author | Yoshiki Vázquez Baeza <yoshiki.vazquezbaeza@colorado.edu> | 2014-03-25 22:24:44 -0600 |
|---|---|---|
| committer | Yoshiki Vázquez Baeza <yoshiki.vazquezbaeza@colorado.edu> | 2014-03-25 23:11:05 -0600 |
| commit | c94e13542ad6553633da59fb68fe295df555e2c3 (patch) | |
| tree | 9d3c228f6c7e848aefa28212f54cba354f913224 /numpy/testing/tests | |
| parent | 2e58804fe546bf6d476d09ba186c36a69bc577c4 (diff) | |
| download | numpy-c94e13542ad6553633da59fb68fe295df555e2c3.tar.gz | |
TST: Add exception message formatting tests
assert_approx_equal & assert_almost_equal make internal use of
build_err_msg so a few tests have been added to check that the errors
are formatted correctly.
Diffstat (limited to 'numpy/testing/tests')
| -rw-r--r-- | numpy/testing/tests/test_utils.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 3c66c3cb3..dd69831d0 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -282,6 +282,29 @@ class TestAlmostEqual(_GenericTest, unittest.TestCase): self._test_not_equal(x, y) self._test_not_equal(x, z) + def test_error_message(self): + """Check the message is formatted correctly for the decimal value""" + x = np.array([1.00000000001, 2.00000000002, 3.00003]) + y = np.array([1.00000000002, 2.00000000003, 3.00004]) + + # test with a different amount of decimal digits + b = ('\nArrays are not almost equal to 12 decimals\n\n(mismatch ' + '100.0%)\n x: array([ 1.00000000001, 2.00000000002, 3.00003 ' + ' ])\n y: array([ 1.00000000002, 2.00000000003, 3.00004 ])') + try: + self._assert_func(x, y, decimal=12) + except AssertionError as e: + self.assertEqual(e.message, b) + + # with the default value of decimal digits, only the 3rd element differs + b = ('\nArrays are not almost equal to 7 decimals\n\n(mismatch ' + '33.3333333333%)\n x: array([ 1. , 2. , 3.00003])\n y: ' + 'array([ 1. , 2. , 3.00004])') + try: + self._assert_func(x, y) + except AssertionError as e: + self.assertEqual(e.message, b) + class TestApproxEqual(unittest.TestCase): def setUp(self): self._assert_func = assert_approx_equal @@ -329,6 +352,18 @@ class TestApproxEqual(unittest.TestCase): self.assertRaises(AssertionError, lambda : self._assert_func(ainf, anan)) + def test_error_message(self): + """Check the message is formatted correctly for the decimal value""" + x = 1.00000001 + y = 1.00000002 + + b = ('\nItems are not equal to 9 significant digits:\n ACTUAL: ' + '1.00000001\n DESIRED: 1.00000002') + try: + self._assert_func(x, y, significant=9) + except AssertionError as e: + self.assertEqual(e.message, b) + class TestRaises(unittest.TestCase): def setUp(self): class MyException(Exception): |
