2015-04-19 07:13:33 +00:00
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from boltons.tbutils import ParsedException
|
|
|
|
|
|
|
|
|
|
|
|
def test_normal_tb():
|
|
|
|
tb = '''\
|
|
|
|
Traceback (most recent call last):
|
|
|
|
File "<string>", line 2, in _some_function
|
|
|
|
return some_other_function(1)
|
|
|
|
File "myfile.py", line 3, in some_other_function
|
|
|
|
return foo(bar, baz)
|
|
|
|
MyException: ExceptionValue
|
|
|
|
'''
|
|
|
|
parsed = ParsedException.from_string(tb)
|
|
|
|
assert parsed.exc_type == 'MyException'
|
2015-04-20 20:52:53 +00:00
|
|
|
assert parsed.exc_msg == 'ExceptionValue'
|
2015-04-19 07:13:33 +00:00
|
|
|
assert parsed.frames == [
|
|
|
|
{
|
|
|
|
'source_line': 'return some_other_function(1)',
|
|
|
|
'filepath': '<string>',
|
|
|
|
'lineno': '2',
|
|
|
|
'funcname': '_some_function'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'source_line': 'return foo(bar, baz)',
|
|
|
|
'filepath': 'myfile.py',
|
|
|
|
'lineno': '3',
|
|
|
|
'funcname': 'some_other_function',
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def test_eval_tb():
|
|
|
|
tb = '''\
|
|
|
|
Traceback (most recent call last):
|
|
|
|
File "<string>", line 2, in _some_function
|
|
|
|
File "myfile.py", line 3, in some_other_function
|
|
|
|
return foo(bar, baz)
|
|
|
|
MyException: ExceptionValue
|
|
|
|
'''
|
|
|
|
parsed = ParsedException.from_string(tb)
|
|
|
|
assert parsed.exc_type == 'MyException'
|
2015-04-19 07:30:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_last_line_is_eval_like():
|
|
|
|
tb = '''\
|
|
|
|
Traceback (most recent call last):
|
|
|
|
File "<string>", line 2, in _some_function
|
|
|
|
MyException: ExceptionValue
|
|
|
|
'''
|
|
|
|
parsed = ParsedException.from_string(tb)
|
|
|
|
assert parsed.exc_type == 'MyException'
|
2015-04-20 20:52:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_multiline_exception_message():
|
|
|
|
tb = '''\
|
|
|
|
Traceback (most recent call last):
|
|
|
|
File "<string>", line 2, in _some_function
|
|
|
|
return some_other_function(1)
|
|
|
|
File "myfile.py", line 3, in some_other_function
|
|
|
|
return foo(bar, baz)
|
|
|
|
MyException: ExceptionValue that
|
|
|
|
spans two lines
|
|
|
|
'''
|
|
|
|
parsed = ParsedException.from_string(tb)
|
2015-04-20 20:52:53 +00:00
|
|
|
assert parsed.exc_msg == 'ExceptionValue that\nspans two lines'
|