summaryrefslogtreecommitdiff
path: root/test/units/errors
diff options
context:
space:
mode:
authorJames Cammarata <jimi@sngx.net>2015-10-08 10:04:15 -0400
committerJames Cammarata <jimi@sngx.net>2015-10-08 10:04:15 -0400
commitde792ba3c2e76fb537069f2ea0174645a7d19a89 (patch)
tree6bfcaac557b75222bc6920d7e3098a23a09788fa /test/units/errors
parent5a0f5f1254f8a94194d389d1993f5a0e41a44255 (diff)
downloadansible-de792ba3c2e76fb537069f2ea0174645a7d19a89.tar.gz
Improve handling of unicode errors
Fixes #12669
Diffstat (limited to 'test/units/errors')
-rw-r--r--test/units/errors/test_errors.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/units/errors/test_errors.py b/test/units/errors/test_errors.py
index 3993ea5061..4c09c0089b 100644
--- a/test/units/errors/test_errors.py
+++ b/test/units/errors/test_errors.py
@@ -31,6 +31,7 @@ class TestErrors(unittest.TestCase):
def setUp(self):
self.message = 'This is the error message'
+ self.unicode_message = 'This is an error with \xf0\x9f\x98\xa8 in it'
self.obj = AnsibleBaseYAMLObject()
@@ -42,6 +43,11 @@ class TestErrors(unittest.TestCase):
self.assertEqual(e.message, 'ERROR! ' + self.message)
self.assertEqual(e.__repr__(), 'ERROR! ' + 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)
+
@patch.object(AnsibleError, '_get_error_lines_from_file')
def test_error_with_object(self, mock_method):
self.obj.ansible_pos = ('foo.yml', 1, 1)
@@ -66,3 +72,12 @@ class TestErrors(unittest.TestCase):
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?)")
+ m = mock_open()
+ m.return_value.readlines.return_value = ['this line has unicode \xf0\x9f\x98\xa8 in it!\n']
+
+ with patch('{0}.open'.format(BUILTINS), m):
+ # 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")
+