diff options
author | Yoshiki Vázquez Baeza <yoshiki.vazquezbaeza@colorado.edu> | 2014-03-24 22:34:59 -0600 |
---|---|---|
committer | Yoshiki Vázquez Baeza <yoshiki.vazquezbaeza@colorado.edu> | 2014-03-24 22:57:41 -0600 |
commit | 4112bf1a19f614fc426b82ff6b3ae86d8b25f92b (patch) | |
tree | 7b6ee9b7503fb0205f522038cb435332e466098d | |
parent | de7c651d531c227d04195b5da21313c57b702b08 (diff) | |
download | numpy-4112bf1a19f614fc426b82ff6b3ae86d8b25f92b.tar.gz |
TST: Add tests for build_err_msg
-rw-r--r-- | numpy/testing/tests/test_utils.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 5956a4294..3c66c3cb3 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -134,6 +134,49 @@ class TestArrayEqual(_GenericTest, unittest.TestCase): self._test_not_equal(c, b) +class TestBuildErrorMessage(unittest.TestCase): + def test_build_err_msg_defaults(self): + x = np.array([1.00001, 2.00002, 3.00003]) + y = np.array([1.00002, 2.00003, 3.00004]) + err_msg = 'There is a mismatch' + + a = build_err_msg([x, y], err_msg) + b = ('\nItems are not equal: There is a mismatch\n ACTUAL: array([ ' + '1.00001, 2.00002, 3.00003])\n DESIRED: array([ 1.00002, ' + '2.00003, 3.00004])') + self.assertEqual(a, b) + + def test_build_err_msg_no_verbose(self): + x = np.array([1.00001, 2.00002, 3.00003]) + y = np.array([1.00002, 2.00003, 3.00004]) + err_msg = 'There is a mismatch' + + a = build_err_msg([x, y], err_msg, verbose=False) + b = '\nItems are not equal: There is a mismatch' + self.assertEqual(a, b) + + def test_build_err_msg_custom_names(self): + x = np.array([1.00001, 2.00002, 3.00003]) + y = np.array([1.00002, 2.00003, 3.00004]) + err_msg = 'There is a mismatch' + + a = build_err_msg([x, y], err_msg, names=('FOO', 'BAR')) + b = ('\nItems are not equal: There is a mismatch\n FOO: array([ ' + '1.00001, 2.00002, 3.00003])\n BAR: array([ 1.00002, 2.00003, ' + '3.00004])') + self.assertEqual(a, b) + + def test_build_err_msg_custom_precision(self): + x = np.array([1.000000001, 2.00002, 3.00003]) + y = np.array([1.000000002, 2.00003, 3.00004]) + err_msg = 'There is a mismatch' + + a = build_err_msg([x, y], err_msg, precision=10) + b = ('\nItems are not equal: There is a mismatch\n ACTUAL: array([ ' + '1.000000001, 2.00002 , 3.00003 ])\n DESIRED: array([ ' + '1.000000002, 2.00003 , 3.00004 ])') + self.assertEqual(a, b) + class TestEqual(TestArrayEqual): def setUp(self): self._assert_func = assert_equal |