From 0d2a9d3f53a8067264770cfb124941ef139d5596 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Tue, 19 Jan 2016 12:09:04 -0500 Subject: [PATCH] Relocate use of ERROR to display class, to avoid doubling up --- lib/ansible/errors/__init__.py | 4 ++-- lib/ansible/utils/display.py | 2 +- test/units/errors/test_errors.py | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/ansible/errors/__init__.py b/lib/ansible/errors/__init__.py index ffe6c9013d..faf7c33416 100644 --- a/lib/ansible/errors/__init__.py +++ b/lib/ansible/errors/__init__.py @@ -54,9 +54,9 @@ class AnsibleError(Exception): if obj and isinstance(obj, AnsibleBaseYAMLObject): extended_error = self._get_extended_error() if extended_error: - self.message = 'ERROR! %s\n\n%s' % (to_str(message), to_str(extended_error)) + self.message = '%s\n\n%s' % (to_str(message), to_str(extended_error)) else: - self.message = 'ERROR! %s' % to_str(message) + self.message = '%s' % to_str(message) def __str__(self): return self.message diff --git a/lib/ansible/utils/display.py b/lib/ansible/utils/display.py index 41b527a112..341af04c65 100644 --- a/lib/ansible/utils/display.py +++ b/lib/ansible/utils/display.py @@ -256,7 +256,7 @@ class Display: wrapped = textwrap.wrap(new_msg, self.columns) new_msg = u"\n".join(wrapped) + u"\n" else: - new_msg = msg + new_msg = u"ERROR! " + msg if new_msg not in self._errors: self.display(new_msg, color='red', stderr=True) self._errors[new_msg] = 1 diff --git a/test/units/errors/test_errors.py b/test/units/errors/test_errors.py index 4c09c0089b..4480bf01df 100644 --- a/test/units/errors/test_errors.py +++ b/test/units/errors/test_errors.py @@ -40,13 +40,13 @@ class TestErrors(unittest.TestCase): def test_basic_error(self): e = AnsibleError(self.message) - self.assertEqual(e.message, 'ERROR! ' + self.message) - self.assertEqual(e.__repr__(), 'ERROR! ' + self.message) + self.assertEqual(e.message, self.message) + self.assertEqual(e.__repr__(), self.message) def test_basic_unicode_error(self): e = AnsibleError(self.unicode_message) - self.assertEqual(e.message, 'ERROR! ' + self.unicode_message) - self.assertEqual(e.__repr__(), 'ERROR! ' + self.unicode_message) + self.assertEqual(e.message, self.unicode_message) + self.assertEqual(e.__repr__(), self.unicode_message) @patch.object(AnsibleError, '_get_error_lines_from_file') def test_error_with_object(self, mock_method): @@ -55,7 +55,7 @@ class TestErrors(unittest.TestCase): mock_method.return_value = ('this is line 1\n', '') e = AnsibleError(self.message, self.obj) - self.assertEqual(e.message, "ERROR! This is the error message\n\nThe error appears to have been in 'foo.yml': line 1, column 1, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\nthis is line 1\n^ here\n") + self.assertEqual(e.message, "This is the error message\n\nThe error appears to have been in 'foo.yml': line 1, column 1, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\nthis is line 1\n^ here\n") def test_get_error_lines_from_file(self): m = mock_open() @@ -65,12 +65,12 @@ class TestErrors(unittest.TestCase): # this line will be found in the file self.obj.ansible_pos = ('foo.yml', 1, 1) e = AnsibleError(self.message, self.obj) - self.assertEqual(e.message, "ERROR! This is the error message\n\nThe error appears to have been in 'foo.yml': line 1, column 1, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\nthis is line 1\n^ here\n") + self.assertEqual(e.message, "This is the error message\n\nThe error appears to have been in 'foo.yml': line 1, column 1, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\nthis is line 1\n^ here\n") # this line will not be found, as it is out of the index range self.obj.ansible_pos = ('foo.yml', 2, 1) e = AnsibleError(self.message, self.obj) - self.assertEqual(e.message, "ERROR! This is the error message\n\nThe error appears to have been in 'foo.yml': line 2, column 1, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\n(specified line no longer in file, maybe it changed?)") + self.assertEqual(e.message, "This is the error message\n\nThe error appears to have been in 'foo.yml': line 2, column 1, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\n(specified line no longer in file, maybe it changed?)") m = mock_open() m.return_value.readlines.return_value = ['this line has unicode \xf0\x9f\x98\xa8 in it!\n'] @@ -79,5 +79,5 @@ class TestErrors(unittest.TestCase): # this line will be found in the file self.obj.ansible_pos = ('foo.yml', 1, 1) e = AnsibleError(self.unicode_message, self.obj) - self.assertEqual(e.message, "ERROR! This is an error with \xf0\x9f\x98\xa8 in it\n\nThe error appears to have been in 'foo.yml': line 1, column 1, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\nthis line has unicode \xf0\x9f\x98\xa8 in it!\n^ here\n") + self.assertEqual(e.message, "This is an error with \xf0\x9f\x98\xa8 in it\n\nThe error appears to have been in 'foo.yml': line 1, column 1, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\nthis line has unicode \xf0\x9f\x98\xa8 in it!\n^ here\n")