@ -48,6 +48,31 @@ class TestErrors(unittest.TestCase):
self . assertEqual ( e . message , self . unicode_message )
self . assertEqual ( e . message , self . unicode_message )
self . assertEqual ( e . __repr__ ( ) , self . unicode_message )
self . assertEqual ( e . __repr__ ( ) , self . unicode_message )
@patch.object ( AnsibleError , ' _get_error_lines_from_file ' )
def test_error_with_kv ( self , mock_method ) :
''' This tests a task with both YAML and k=v syntax
- lineinfile : line = foo path = bar
line : foo
An accurate error message and position indicator are expected .
_get_error_lines_from_file ( ) returns ( target_line , prev_line )
'''
self . obj . ansible_pos = ( ' foo.yml ' , 2 , 1 )
mock_method . return_value = [ ' line: foo \n ' , ' - lineinfile: line=foo path=bar \n ' ]
e = AnsibleError ( self . message , self . obj )
self . assertEqual (
e . message ,
( " This is the error message \n \n The error appears to be in ' foo.yml ' : line 1, column 19, but may \n be elsewhere in the "
" file depending on the exact syntax problem. \n \n The offending line appears to be: \n \n - lineinfile: line=foo path=bar \n "
" ^ here \n \n "
" There appears to be both ' k=v ' shorthand syntax and YAML in this task. Only one syntax may be used. \n " )
)
@patch.object ( AnsibleError , ' _get_error_lines_from_file ' )
@patch.object ( AnsibleError , ' _get_error_lines_from_file ' )
def test_error_with_object ( self , mock_method ) :
def test_error_with_object ( self , mock_method ) :
self . obj . ansible_pos = ( ' foo.yml ' , 1 , 1 )
self . obj . ansible_pos = ( ' foo.yml ' , 1 , 1 )
@ -57,7 +82,7 @@ class TestErrors(unittest.TestCase):
self . assertEqual (
self . assertEqual (
e . message ,
e . message ,
( " This is the error message \n \n The error appears to have been in ' foo.yml ' : line 1, column 1, but may \n be elsewhere in the file depending on the "
( " This is the error message \n \n The error appears to be in ' foo.yml ' : line 1, column 1, but may \n be elsewhere in the file depending on the "
" exact syntax problem. \n \n The offending line appears to be: \n \n \n this is line 1 \n ^ here \n " )
" exact syntax problem. \n \n The offending line appears to be: \n \n \n this is line 1 \n ^ here \n " )
)
)
@ -71,7 +96,7 @@ class TestErrors(unittest.TestCase):
e = AnsibleError ( self . message , self . obj )
e = AnsibleError ( self . message , self . obj )
self . assertEqual (
self . assertEqual (
e . message ,
e . message ,
( " This is the error message \n \n The error appears to have been in ' foo.yml ' : line 1, column 1, but may \n be elsewhere in the file depending on "
( " This is the error message \n \n The error appears to be in ' foo.yml ' : line 1, column 1, but may \n be elsewhere in the file depending on "
" the exact syntax problem. \n \n The offending line appears to be: \n \n \n this is line 1 \n ^ here \n " )
" the exact syntax problem. \n \n The offending line appears to be: \n \n \n this is line 1 \n ^ here \n " )
)
)
@ -80,7 +105,7 @@ class TestErrors(unittest.TestCase):
e = AnsibleError ( self . message , self . obj )
e = AnsibleError ( self . message , self . obj )
self . assertEqual (
self . assertEqual (
e . message ,
e . message ,
( " This is the error message \n \n The error appears to have been in ' foo.yml ' : line 2, column 1, but may \n be elsewhere in the file depending on "
( " This is the error message \n \n The error appears to be in ' foo.yml ' : line 2, column 1, but may \n be elsewhere in the file depending on "
" the exact syntax problem. \n \n (specified line no longer in file, maybe it changed?) " )
" the exact syntax problem. \n \n (specified line no longer in file, maybe it changed?) " )
)
)
@ -93,7 +118,7 @@ class TestErrors(unittest.TestCase):
e = AnsibleError ( self . unicode_message , self . obj )
e = AnsibleError ( self . unicode_message , self . obj )
self . assertEqual (
self . assertEqual (
e . message ,
e . message ,
( " This is an error with \xf0 \x9f \x98 \xa8 in it \n \n The error appears to have been in ' foo.yml ' : line 1, column 1, but may \n be elsewhere in the "
( " This is an error with \xf0 \x9f \x98 \xa8 in it \n \n The error appears to be in ' foo.yml ' : line 1, column 1, but may \n be elsewhere in the "
" file depending on the exact syntax problem. \n \n The offending line appears to be: \n \n \n this line has unicode \xf0 \x9f \x98 \xa8 in it! \n ^ "
" file depending on the exact syntax problem. \n \n The offending line appears to be: \n \n \n this line has unicode \xf0 \x9f \x98 \xa8 in it! \n ^ "
" here \n " )
" here \n " )
)
)