Adding a data parsing class for v2

This commit is contained in:
James Cammarata 2014-10-23 15:39:27 -05:00
parent c86851be2c
commit 7cb489eca3
12 changed files with 406 additions and 262 deletions

View file

@ -30,7 +30,7 @@ from ansible.compat.tests.mock import mock_open, patch
class TestErrors(unittest.TestCase):
def setUp(self):
self.message = 'this is the error message'
self.message = 'This is the error message'
self.obj = AnsibleBaseYAMLObject()
@ -42,18 +42,18 @@ class TestErrors(unittest.TestCase):
self.assertEqual(e.message, self.message)
self.assertEqual(e.__repr__(), self.message)
@patch.object(AnsibleError, '_get_line_from_file')
@patch.object(AnsibleError, '_get_error_lines_from_file')
def test_error_with_object(self, mock_method):
self.obj._data_source = 'foo.yml'
self.obj._line_number = 1
self.obj._column_number = 1
mock_method.return_value = 'this is line 1\n'
mock_method.return_value = ('this is line 1\n', '')
e = AnsibleError(self.message, self.obj)
self.assertEqual(e.message, 'this is the error message\nThe error occurred on line 1 of the file foo.yml:\nthis is line 1\n^')
self.assertEqual(e.message, "This is the error message\nThe error appears to have been in 'foo.yml': line 1, column 1,\nbut may actually be before there depending on the exact syntax problem.\n\nthis is line 1\n^\n")
def test_error_get_line_from_file(self):
def test_get_error_lines_from_file(self):
m = mock_open()
m.return_value.readlines.return_value = ['this is line 1\n']
@ -63,12 +63,12 @@ class TestErrors(unittest.TestCase):
self.obj._line_number = 1
self.obj._column_number = 1
e = AnsibleError(self.message, self.obj)
self.assertEqual(e.message, 'this is the error message\nThe error occurred on line 1 of the file foo.yml:\nthis is line 1\n^')
self.assertEqual(e.message, "This is the error message\nThe error appears to have been in 'foo.yml': line 1, column 1,\nbut may actually be before there depending on the exact syntax problem.\n\nthis is line 1\n^\n")
# this line will not be found, as it is out of the index range
self.obj._data_source = 'foo.yml'
self.obj._line_number = 2
self.obj._column_number = 1
e = AnsibleError(self.message, self.obj)
self.assertEqual(e.message, 'this is the error message\nThe error occurred on line 2 of the file foo.yml:\n\n(specified line no longer in file, maybe it changed?)')
self.assertEqual(e.message, "This is the error message\nThe error appears to have been in 'foo.yml': line 2, column 1,\nbut may actually be before there depending on the exact syntax problem.\n\n(specified line no longer in file, maybe it changed?)")