<s> import sys <EOL> try : <EOL> from cStringIO import StringIO <EOL> except : <EOL> from io import StringIO <EOL> from boltons . tbutils import ( TracebackInfo , <EOL> ExceptionInfo , <EOL> ParsedException , <EOL> print_exception , <EOL> fix_print_exception , <EOL> ContextualCallpoint , <EOL> ContextualExceptionInfo ) <EOL> def test_parsed_exc ( ) : <EOL> FAKE_TB_STR = u"""<STR_LIT>""" <EOL> parsed_tb = ParsedException . from_string ( FAKE_TB_STR ) <EOL> print ( parsed_tb ) <EOL> assert parsed_tb . exc_type == '<STR_LIT>' <EOL> assert parsed_tb . exc_msg == "<STR_LIT>" <EOL> assert parsed_tb . frames == [ { '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT:2>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' } ] <EOL> def test_exception_info ( ) : <EOL> builtin_exc_hook = sys . excepthook <EOL> fix_print_exception ( ) <EOL> tbi_str = '<STR_LIT>' <EOL> def test ( ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> fake_stderr1 = StringIO ( ) <EOL> fake_stderr2 = StringIO ( ) <EOL> sys . stderr = fake_stderr1 <EOL> try : <EOL> test ( ) <EOL> except : <EOL> _ , _ , exc_traceback = sys . exc_info ( ) <EOL> tbi = TracebackInfo . from_traceback ( exc_traceback ) <EOL> exc_info = ExceptionInfo . from_exc_info ( * sys . exc_info ( ) ) <EOL> exc_info2 = ExceptionInfo . from_current ( ) <EOL> tbi_str = str ( tbi ) <EOL> print_exception ( * sys . exc_info ( ) , file = fake_stderr2 ) <EOL> new_exc_hook_res = fake_stderr2 . getvalue ( ) <EOL> builtin_exc_hook ( * sys . exc_info ( ) ) <EOL> builtin_exc_hook_res = fake_stderr1 . getvalue ( ) <EOL> finally : <EOL> sys . stderr = sys . __stderr__ <EOL> single_frame_str = tbi . frames [ - <NUM_LIT:1> ] . tb_frame_str ( ) <EOL> assert '<STR_LIT>' in single_frame_str <EOL> assert '<STR_LIT>' in single_frame_str <EOL> assert len ( tbi_str . splitlines ( ) ) == <NUM_LIT:5> <EOL> assert '<STR_LIT>' in tbi_str <EOL> assert '<STR_LIT>' in new_exc_hook_res <EOL> assert "<STR_LIT>" in new_exc_hook_res <EOL> assert len ( new_exc_hook_res ) > len ( tbi_str ) <EOL> assert new_exc_hook_res == builtin_exc_hook_res <EOL> def test_contextual ( ) : <EOL> def func1 ( ) : <EOL> return func2 ( ) <EOL> def func2 ( ) : <EOL> x = <NUM_LIT:5> <EOL> return func3 ( ) <EOL> def func3 ( ) : <EOL> return ContextualCallpoint . from_current ( level = <NUM_LIT:2> ) <EOL> callpoint = func1 ( ) <EOL> assert callpoint . func_name == '<STR_LIT>' <EOL> line = str ( callpoint . line ) <EOL> assert line . startswith ( '<STR_LIT:U+0020>' ) <EOL> assert line . strip ( ) == '<STR_LIT>' <EOL> assert '<STR_LIT>' in repr ( callpoint ) <EOL> def func_a ( ) : <EOL> a = <NUM_LIT:1> <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def func_b ( ) : <EOL> b = <NUM_LIT:2> <EOL> return func_a ( ) <EOL> def func_c ( ) : <EOL> c = <NUM_LIT:3> <EOL> return func_b ( ) <EOL> try : <EOL> func_c ( ) <EOL> except Exception as e : <EOL> ctx_ei = ContextualExceptionInfo . from_current ( ) <EOL> ctx_ei_str = ctx_ei . get_formatted ( ) <EOL> ctx_ei_lines = ctx_ei_str . splitlines ( ) <EOL> assert ctx_ei_lines [ - <NUM_LIT:1> ] == '<STR_LIT>' <EOL> assert ctx_ei_lines [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> assert len ( ctx_ei_lines ) == <NUM_LIT:10> <EOL> assert "<STR_LIT>" in ctx_ei_str <EOL> assert ctx_ei . tb_info . frames [ <NUM_LIT:2> ] . local_reprs [ '<STR_LIT:b>' ] == '<STR_LIT:2>' </s>
