<s> import py <EOL> from py . __ . code . excinfo import FormattedExcinfo , ReprExceptionInfo <EOL> class TWMock : <EOL> def __init__ ( self ) : <EOL> self . lines = [ ] <EOL> def sep ( self , sep , line = None ) : <EOL> self . lines . append ( ( sep , line ) ) <EOL> def line ( self , line , ** kw ) : <EOL> self . lines . append ( line ) <EOL> def markup ( self , text , ** kw ) : <EOL> return text <EOL> fullwidth = <NUM_LIT> <EOL> def test_excinfo_simple ( ) : <EOL> try : <EOL> raise ValueError <EOL> except ValueError : <EOL> info = py . code . ExceptionInfo ( ) <EOL> assert info . type == ValueError <EOL> def test_excinfo_getstatement ( ) : <EOL> def g ( ) : <EOL> raise ValueError <EOL> def f ( ) : <EOL> g ( ) <EOL> try : <EOL> f ( ) <EOL> except ValueError : <EOL> excinfo = py . code . ExceptionInfo ( ) <EOL> linenumbers = [ f . func_code . co_firstlineno - <NUM_LIT:1> + <NUM_LIT:3> , <EOL> f . func_code . co_firstlineno - <NUM_LIT:1> + <NUM_LIT:1> , <EOL> g . func_code . co_firstlineno - <NUM_LIT:1> + <NUM_LIT:1> , ] <EOL> l = list ( excinfo . traceback ) <EOL> foundlinenumbers = [ x . lineno for x in l ] <EOL> print l [ <NUM_LIT:0> ] . frame . statement <EOL> assert foundlinenumbers == linenumbers <EOL> def f ( ) : <EOL> raise ValueError <EOL> def g ( ) : <EOL> __tracebackhide__ = True <EOL> f ( ) <EOL> def h ( ) : <EOL> g ( ) <EOL> class TestTraceback_f_g_h : <EOL> def setup_method ( self , method ) : <EOL> try : <EOL> h ( ) <EOL> except ValueError : <EOL> self . excinfo = py . code . ExceptionInfo ( ) <EOL> def test_traceback_entries ( self ) : <EOL> tb = self . excinfo . traceback <EOL> entries = list ( tb ) <EOL> assert len ( tb ) == <NUM_LIT:4> <EOL> assert len ( entries ) == <NUM_LIT:4> <EOL> names = [ '<STR_LIT:f>' , '<STR_LIT:g>' , '<STR_LIT:h>' ] <EOL> for entry in entries : <EOL> try : <EOL> names . remove ( entry . frame . code . name ) <EOL> except ValueError : <EOL> pass <EOL> assert not names <EOL> def test_traceback_entry_getsource ( self ) : <EOL> tb = self . excinfo . traceback <EOL> s = str ( tb [ - <NUM_LIT:1> ] . getsource ( ) ) <EOL> assert s . startswith ( "<STR_LIT>" ) <EOL> assert s . endswith ( "<STR_LIT>" ) <EOL> def test_traceback_entry_getsource_in_construct ( self ) : <EOL> source = py . code . Source ( """<STR_LIT>""" ) <EOL> try : <EOL> exec source . compile ( ) <EOL> except NameError : <EOL> tb = py . code . ExceptionInfo ( ) . traceback <EOL> print tb [ - <NUM_LIT:1> ] . getsource ( ) <EOL> s = str ( tb [ - <NUM_LIT:1> ] . getsource ( ) ) <EOL> assert s . startswith ( "<STR_LIT>" ) <EOL> assert s . endswith ( "<STR_LIT>" ) <EOL> def test_traceback_cut ( self ) : <EOL> co = py . code . Code ( f ) <EOL> path , firstlineno = co . path , co . firstlineno <EOL> traceback = self . excinfo . traceback <EOL> newtraceback = traceback . cut ( path = path , firstlineno = firstlineno ) <EOL> assert len ( newtraceback ) == <NUM_LIT:1> <EOL> newtraceback = traceback . cut ( path = path , lineno = firstlineno + <NUM_LIT:2> ) <EOL> assert len ( newtraceback ) == <NUM_LIT:1> <EOL> def test_traceback_cut_excludepath ( self , testdir ) : <EOL> p = testdir . makepyfile ( "<STR_LIT>" ) <EOL> excinfo = py . test . raises ( ValueError , "<STR_LIT>" ) <EOL> print excinfo . traceback <EOL> pydir = py . path . local ( py . __file__ ) . dirpath ( ) <EOL> newtraceback = excinfo . traceback . cut ( excludepath = pydir ) <EOL> assert len ( newtraceback ) == <NUM_LIT:1> <EOL> assert newtraceback [ <NUM_LIT:0> ] . frame . code . path == p <EOL> def test_traceback_filter ( self ) : <EOL> traceback = self . excinfo . traceback <EOL> ntraceback = traceback . filter ( ) <EOL> assert len ( ntraceback ) == len ( traceback ) - <NUM_LIT:1> <EOL> def test_traceback_recursion_index ( self ) : <EOL> def f ( n ) : <EOL> if n < <NUM_LIT:10> : <EOL> n += <NUM_LIT:1> <EOL> f ( n ) <EOL> excinfo = py . test . raises ( RuntimeError , f , <NUM_LIT:8> ) <EOL> traceback = excinfo . traceback <EOL> recindex = traceback . recursionindex ( ) <EOL> assert recindex == <NUM_LIT:3> <EOL> def test_traceback_no_recursion_index ( self ) : <EOL> def do_stuff ( ) : <EOL> raise RuntimeError <EOL> def reraise_me ( ) : <EOL> import sys <EOL> exc , val , tb = sys . exc_info ( ) <EOL> raise exc , val , tb <EOL> def f ( n ) : <EOL> try : <EOL> do_stuff ( ) <EOL> except : <EOL> reraise_me ( ) <EOL> excinfo = py . test . raises ( RuntimeError , f , <NUM_LIT:8> ) <EOL> traceback = excinfo . traceback <EOL> recindex = traceback . recursionindex ( ) <EOL> assert recindex is None <EOL> def test_traceback_getcrashentry ( self ) : <EOL> def i ( ) : <EOL> __tracebackhide__ = True <EOL> raise ValueError <EOL> def h ( ) : <EOL> i ( ) <EOL> def g ( ) : <EOL> __tracebackhide__ = True <EOL> h ( ) <EOL> def f ( ) : <EOL> g ( ) <EOL> excinfo = py . test . raises ( ValueError , f ) <EOL> tb = excinfo . traceback <EOL> entry = tb . getcrashentry ( ) <EOL> co = py . code . Code ( h ) <EOL> assert entry . frame . code . path == co . path <EOL> assert entry . lineno == co . firstlineno + <NUM_LIT:1> <EOL> assert entry . frame . code . name == '<STR_LIT:h>' <EOL> def test_traceback_getcrashentry_empty ( self ) : <EOL> def g ( ) : <EOL> __tracebackhide__ = True <EOL> raise ValueError <EOL> def f ( ) : <EOL> __tracebackhide__ = True <EOL> g ( ) <EOL> excinfo = py . test . raises ( ValueError , f ) <EOL> tb = excinfo . traceback <EOL> entry = tb . getcrashentry ( ) <EOL> co = py . code . Code ( g ) <EOL> assert entry . frame . code . path == co . path <EOL> assert entry . lineno == co . firstlineno + <NUM_LIT:2> <EOL> assert entry . frame . code . name == '<STR_LIT:g>' <EOL> def hello ( x ) : <EOL> x + <NUM_LIT:5> <EOL> def test_tbentry_reinterpret ( ) : <EOL> try : <EOL> hello ( "<STR_LIT:hello>" ) <EOL> except TypeError : <EOL> excinfo = py . code . ExceptionInfo ( ) <EOL> tbentry = excinfo . traceback [ - <NUM_LIT:1> ] <EOL> msg = tbentry . reinterpret ( ) <EOL> assert msg . startswith ( "<STR_LIT>" ) <EOL> def test_excinfo_exconly ( ) : <EOL> excinfo = py . test . raises ( ValueError , h ) <EOL> assert excinfo . exconly ( ) . startswith ( '<STR_LIT>' ) <EOL> excinfo = py . test . raises ( ValueError , <EOL> "<STR_LIT>" ) <EOL> msg = excinfo . exconly ( tryshort = True ) <EOL> assert msg . startswith ( '<STR_LIT>' ) <EOL> assert msg . endswith ( "<STR_LIT>" ) <EOL> def test_excinfo_repr ( ) : <EOL> excinfo = py . test . raises ( ValueError , h ) <EOL> s = repr ( excinfo ) <EOL> assert s == "<STR_LIT>" <EOL> def test_excinfo_str ( ) : <EOL> excinfo = py . test . raises ( ValueError , h ) <EOL> s = str ( excinfo ) <EOL> print s <EOL> assert s . startswith ( __file__ [ : - <NUM_LIT:1> ] ) <EOL> assert s . endswith ( "<STR_LIT>" ) <EOL> assert len ( s . split ( "<STR_LIT::>" ) ) >= <NUM_LIT:3> <EOL> def test_excinfo_errisinstance ( ) : <EOL> excinfo = py . test . raises ( ValueError , h ) <EOL> assert excinfo . errisinstance ( ValueError ) <EOL> def test_excinfo_no_sourcecode ( ) : <EOL> try : <EOL> exec "<STR_LIT>" <EOL> except ValueError : <EOL> excinfo = py . code . ExceptionInfo ( ) <EOL> s = str ( excinfo . traceback [ - <NUM_LIT:1> ] ) <EOL> if py . std . sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:5> ) : <EOL> assert s == "<STR_LIT>" <EOL> else : <EOL> assert s == "<STR_LIT>" <EOL> def test_entrysource_Queue_example ( ) : <EOL> import Queue <EOL> try : <EOL> Queue . Queue ( ) . get ( timeout = <NUM_LIT> ) <EOL> except Queue . Empty : <EOL> excinfo = py . code . ExceptionInfo ( ) <EOL> entry = excinfo . traceback [ - <NUM_LIT:1> ] <EOL> source = entry . getsource ( ) <EOL> assert source is not None <EOL> s = str ( source ) . strip ( ) <EOL> assert s . startswith ( "<STR_LIT>" ) <EOL> def test_codepath_Queue_example ( ) : <EOL> import Queue <EOL> try : <EOL> Queue . Queue ( ) . get ( timeout = <NUM_LIT> ) <EOL> except Queue . Empty : <EOL> excinfo = py . code . ExceptionInfo ( ) <EOL> entry = excinfo . traceback [ - <NUM_LIT:1> ] <EOL> path = entry . path <EOL> assert isinstance ( path , py . path . local ) <EOL> assert path . basename == "<STR_LIT>" <EOL> assert path . check ( ) <EOL> class TestFormattedExcinfo : <EOL> def setup_method ( self , method ) : <EOL> self . tmpdir = py . test . ensuretemp ( "<STR_LIT>" % ( <EOL> self . __class__ . __name__ , method . __name__ ) ) <EOL> def importasmod ( self , source ) : <EOL> source = py . code . Source ( source ) <EOL> modpath = self . tmpdir . join ( "<STR_LIT>" ) <EOL> self . tmpdir . ensure ( "<STR_LIT>" ) <EOL> modpath . write ( source ) <EOL> return modpath . pyimport ( ) <EOL> def excinfo_from_exec ( self , source ) : <EOL> source = py . code . Source ( source ) . strip ( ) <EOL> try : <EOL> exec source . compile ( ) <EOL> except KeyboardInterrupt : <EOL> raise <EOL> except : <EOL> return py . code . ExceptionInfo ( ) <EOL> assert <NUM_LIT:0> , "<STR_LIT>" <EOL> def test_repr_source ( self ) : <EOL> pr = FormattedExcinfo ( ) <EOL> source = py . code . Source ( """<STR_LIT>""" ) . strip ( ) <EOL> pr . flow_marker = "<STR_LIT:|>" <EOL> lines = pr . get_source ( source , <NUM_LIT:0> ) <EOL> assert len ( lines ) == <NUM_LIT:2> <EOL> assert lines [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> assert lines [ <NUM_LIT:1> ] == "<STR_LIT>" <EOL> def test_repr_source_excinfo ( self ) : <EOL> """<STR_LIT>""" <EOL> pr = FormattedExcinfo ( ) <EOL> excinfo = self . excinfo_from_exec ( """<STR_LIT>""" ) <EOL> pr = FormattedExcinfo ( ) <EOL> source = pr . _getentrysource ( excinfo . traceback [ - <NUM_LIT:1> ] ) <EOL> lines = pr . get_source ( source , <NUM_LIT:1> , excinfo ) <EOL> print lines <EOL> assert lines == [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> def test_repr_source_not_existing ( self ) : <EOL> pr = FormattedExcinfo ( ) <EOL> co = compile ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> try : <EOL> exec co <EOL> except ValueError : <EOL> excinfo = py . code . ExceptionInfo ( ) <EOL> repr = pr . repr_excinfo ( excinfo ) <EOL> assert repr . reprtraceback . reprentries [ <NUM_LIT:1> ] . lines [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> def test_repr_many_line_source_not_existing ( self ) : <EOL> pr = FormattedExcinfo ( ) <EOL> co = compile ( """<STR_LIT>""" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> try : <EOL> exec co <EOL> except ValueError : <EOL> excinfo = py . code . ExceptionInfo ( ) <EOL> repr = pr . repr_excinfo ( excinfo ) <EOL> assert repr . reprtraceback . reprentries [ <NUM_LIT:1> ] . lines [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> def test_repr_source_failing_fullsource ( self ) : <EOL> pr = FormattedExcinfo ( ) <EOL> class FakeCode ( object ) : <EOL> path = '<STR_LIT:?>' <EOL> firstlineno = <NUM_LIT:5> <EOL> def fullsource ( self ) : <EOL> return None <EOL> fullsource = property ( fullsource ) <EOL> class FakeFrame ( object ) : <EOL> code = FakeCode ( ) <EOL> f_locals = { } <EOL> class FakeTracebackEntry ( py . code . Traceback . Entry ) : <EOL> def __init__ ( self , tb ) : <EOL> self . frame = FakeFrame ( ) <EOL> self . lineno = <NUM_LIT:5> + <NUM_LIT:3> <EOL> class Traceback ( py . code . Traceback ) : <EOL> Entry = FakeTracebackEntry <EOL> class FakeExcinfo ( py . code . ExceptionInfo ) : <EOL> typename = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> pass <EOL> def exconly ( self , tryshort ) : <EOL> return "<STR_LIT>" <EOL> def errisinstance ( self , cls ) : <EOL> return False <EOL> excinfo = FakeExcinfo ( ) <EOL> class FakeRawTB ( object ) : <EOL> tb_next = None <EOL> tb = FakeRawTB ( ) <EOL> excinfo . traceback = Traceback ( tb ) <EOL> fail = IOError ( ) <EOL> repr = pr . repr_excinfo ( excinfo ) <EOL> assert repr . reprtraceback . reprentries [ <NUM_LIT:0> ] . lines [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> fail = py . error . ENOENT <EOL> repr = pr . repr_excinfo ( excinfo ) <EOL> assert repr . reprtraceback . reprentries [ <NUM_LIT:0> ] . lines [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> def test_repr_local ( self ) : <EOL> p = FormattedExcinfo ( showlocals = True ) <EOL> loc = { '<STR_LIT:y>' : <NUM_LIT:5> , '<STR_LIT:z>' : <NUM_LIT:7> , '<STR_LIT:x>' : <NUM_LIT:3> , '<STR_LIT>' : __builtins__ } <EOL> reprlocals = p . repr_locals ( loc ) <EOL> assert reprlocals . lines <EOL> print reprlocals . lines <EOL> assert reprlocals . lines [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> assert reprlocals . lines [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> assert reprlocals . lines [ <NUM_LIT:2> ] == '<STR_LIT>' <EOL> assert reprlocals . lines [ <NUM_LIT:3> ] == '<STR_LIT>' <EOL> def test_repr_tracebackentry_lines ( self ) : <EOL> mod = self . importasmod ( """<STR_LIT>""" ) <EOL> excinfo = py . test . raises ( ValueError , mod . func1 ) <EOL> excinfo . traceback = excinfo . traceback . filter ( ) <EOL> p = FormattedExcinfo ( ) <EOL> reprtb = p . repr_traceback_entry ( excinfo . traceback [ - <NUM_LIT:1> ] ) <EOL> print reprtb <EOL> lines = reprtb . lines <EOL> assert lines [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> assert lines [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> p = FormattedExcinfo ( showlocals = True ) <EOL> repr_entry = p . repr_traceback_entry ( excinfo . traceback [ - <NUM_LIT:1> ] , excinfo ) <EOL> lines = repr_entry . lines <EOL> assert lines [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> assert lines [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> assert lines [ <NUM_LIT:2> ] == '<STR_LIT>' <EOL> assert lines [ <NUM_LIT:3> ] == '<STR_LIT>' <EOL> assert not lines [ <NUM_LIT:4> : ] <EOL> loc = repr_entry . reprlocals is not None <EOL> loc = repr_entry . reprfileloc <EOL> assert loc . path == mod . __file__ <EOL> assert loc . lineno == <NUM_LIT:3> <EOL> def test_repr_tracebackentry_lines ( self ) : <EOL> mod = self . importasmod ( """<STR_LIT>""" ) <EOL> excinfo = py . test . raises ( ValueError , mod . func1 , "<STR_LIT:m>" * <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , "<STR_LIT:z>" * <NUM_LIT> ) <EOL> excinfo . traceback = excinfo . traceback . filter ( ) <EOL> entry = excinfo . traceback [ - <NUM_LIT:1> ] <EOL> p = FormattedExcinfo ( funcargs = True ) <EOL> reprfuncargs = p . repr_args ( entry ) <EOL> assert reprfuncargs . args [ <NUM_LIT:0> ] == ( '<STR_LIT:m>' , repr ( "<STR_LIT:m>" * <NUM_LIT> ) ) <EOL> assert reprfuncargs . args [ <NUM_LIT:1> ] == ( '<STR_LIT:x>' , '<STR_LIT:5>' ) <EOL> assert reprfuncargs . args [ <NUM_LIT:2> ] == ( '<STR_LIT:y>' , '<STR_LIT>' ) <EOL> assert reprfuncargs . args [ <NUM_LIT:3> ] == ( '<STR_LIT:z>' , repr ( "<STR_LIT:z>" * <NUM_LIT> ) ) <EOL> p = FormattedExcinfo ( funcargs = True ) <EOL> repr_entry = p . repr_traceback_entry ( entry ) <EOL> assert repr_entry . reprfuncargs . args == reprfuncargs . args <EOL> tw = TWMock ( ) <EOL> repr_entry . toterminal ( tw ) <EOL> assert tw . lines [ <NUM_LIT:0> ] == "<STR_LIT>" + repr ( '<STR_LIT:m>' * <NUM_LIT> ) <EOL> assert tw . lines [ <NUM_LIT:1> ] == "<STR_LIT>" <EOL> assert tw . lines [ <NUM_LIT:2> ] == "<STR_LIT>" + repr ( '<STR_LIT:z>' * <NUM_LIT> ) <EOL> def test_repr_tracebackentry_short ( self ) : <EOL> mod = self . importasmod ( """<STR_LIT>""" ) <EOL> excinfo = py . test . raises ( ValueError , mod . entry ) <EOL> p = FormattedExcinfo ( style = "<STR_LIT>" ) <EOL> reprtb = p . repr_traceback_entry ( excinfo . traceback [ - <NUM_LIT:2> ] ) <EOL> lines = reprtb . lines <EOL> basename = py . path . local ( mod . __file__ ) . basename <EOL> assert lines [ <NUM_LIT:0> ] == '<STR_LIT>' % basename <EOL> assert lines [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> p = FormattedExcinfo ( style = "<STR_LIT>" ) <EOL> reprtb = p . repr_traceback_entry ( excinfo . traceback [ - <NUM_LIT:1> ] , excinfo ) <EOL> lines = reprtb . lines <EOL> assert lines [ <NUM_LIT:0> ] == '<STR_LIT>' % basename <EOL> assert lines [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> assert lines [ <NUM_LIT:2> ] == '<STR_LIT>' <EOL> def test_repr_tracebackentry_no ( self ) : <EOL> mod = self . importasmod ( """<STR_LIT>""" ) <EOL> excinfo = py . test . raises ( ValueError , mod . entry ) <EOL> p = FormattedExcinfo ( style = "<STR_LIT>" ) <EOL> p . repr_traceback_entry ( excinfo . traceback [ - <NUM_LIT:2> ] ) <EOL> p = FormattedExcinfo ( style = "<STR_LIT>" ) <EOL> reprentry = p . repr_traceback_entry ( excinfo . traceback [ - <NUM_LIT:1> ] , excinfo ) <EOL> lines = reprentry . lines <EOL> assert lines [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> assert not lines [ <NUM_LIT:1> : ] <EOL> def test_repr_traceback_tbfilter ( self ) : <EOL> mod = self . importasmod ( """<STR_LIT>""" ) <EOL> excinfo = py . test . raises ( ValueError , mod . entry ) <EOL> p = FormattedExcinfo ( tbfilter = True ) <EOL> reprtb = p . repr_traceback ( excinfo ) <EOL> assert len ( reprtb . reprentries ) == <NUM_LIT:2> <EOL> p = FormattedExcinfo ( tbfilter = False ) <EOL> reprtb = p . repr_traceback ( excinfo ) <EOL> assert len ( reprtb . reprentries ) == <NUM_LIT:3> <EOL> def test_repr_traceback_and_excinfo ( self ) : <EOL> mod = self . importasmod ( """<STR_LIT>""" ) <EOL> excinfo = py . test . raises ( ValueError , mod . entry ) <EOL> for style in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> p = FormattedExcinfo ( style = style ) <EOL> reprtb = p . repr_traceback ( excinfo ) <EOL> assert len ( reprtb . reprentries ) == <NUM_LIT:2> <EOL> assert reprtb . style == style <EOL> assert not reprtb . extraline <EOL> repr = p . repr_excinfo ( excinfo ) <EOL> assert repr . reprtraceback <EOL> assert len ( repr . reprtraceback . reprentries ) == len ( reprtb . reprentries ) <EOL> assert repr . reprcrash . path . endswith ( "<STR_LIT>" ) <EOL> assert repr . reprcrash . message == "<STR_LIT>" <EOL> def test_repr_excinfo_addouterr ( self ) : <EOL> mod = self . importasmod ( """<STR_LIT>""" ) <EOL> excinfo = py . test . raises ( ValueError , mod . entry ) <EOL> repr = excinfo . getrepr ( ) <EOL> repr . addsection ( "<STR_LIT:title>" , "<STR_LIT:content>" ) <EOL> twmock = TWMock ( ) <EOL> repr . toterminal ( twmock ) <EOL> assert twmock . lines [ - <NUM_LIT:1> ] == "<STR_LIT:content>" <EOL> assert twmock . lines [ - <NUM_LIT:2> ] == ( "<STR_LIT:->" , "<STR_LIT:title>" ) <EOL> def test_repr_excinfo_reprcrash ( self ) : <EOL> mod = self . importasmod ( """<STR_LIT>""" ) <EOL> excinfo = py . test . raises ( ValueError , mod . entry ) <EOL> repr = excinfo . getrepr ( ) <EOL> assert repr . reprcrash . path . endswith ( "<STR_LIT>" ) <EOL> assert repr . reprcrash . lineno == <NUM_LIT:3> <EOL> assert repr . reprcrash . message == "<STR_LIT>" <EOL> assert str ( repr . reprcrash ) . endswith ( "<STR_LIT>" ) <EOL> def test_repr_traceback_recursion ( self ) : <EOL> mod = self . importasmod ( """<STR_LIT>""" ) <EOL> excinfo = py . test . raises ( RuntimeError , mod . entry ) <EOL> for style in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> p = FormattedExcinfo ( style = "<STR_LIT>" ) <EOL> reprtb = p . repr_traceback ( excinfo ) <EOL> assert reprtb . extraline == "<STR_LIT>" <EOL> assert str ( reprtb ) <EOL> def test_tb_entry_AssertionError ( self ) : <EOL> mod = self . importasmod ( """<STR_LIT>""" ) <EOL> py . magic . invoke ( assertion = True ) <EOL> try : <EOL> excinfo = py . test . raises ( AssertionError , mod . somefunc ) <EOL> finally : <EOL> py . magic . revoke ( assertion = True ) <EOL> p = FormattedExcinfo ( ) <EOL> reprentry = p . repr_traceback_entry ( excinfo . traceback [ - <NUM_LIT:1> ] , excinfo ) <EOL> lines = reprentry . lines <EOL> assert lines [ - <NUM_LIT:1> ] == "<STR_LIT>" <EOL> def test_reprexcinfo_getrepr ( self ) : <EOL> mod = self . importasmod ( """<STR_LIT>""" ) <EOL> excinfo = py . test . raises ( ValueError , mod . entry ) <EOL> for style in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> for showlocals in ( True , False ) : <EOL> repr = excinfo . getrepr ( style = style , showlocals = showlocals ) <EOL> assert isinstance ( repr , ReprExceptionInfo ) <EOL> assert repr . reprtraceback . style == style <EOL> def test_toterminal_long ( self ) : <EOL> mod = self . importasmod ( """<STR_LIT>""" ) <EOL> excinfo = py . test . raises ( ValueError , mod . f ) <EOL> excinfo . traceback = excinfo . traceback . filter ( ) <EOL> repr = excinfo . getrepr ( ) <EOL> tw = TWMock ( ) <EOL> repr . toterminal ( tw ) <EOL> assert tw . lines [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> tw . lines . pop ( <NUM_LIT:0> ) <EOL> assert tw . lines [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> assert tw . lines [ <NUM_LIT:1> ] == "<STR_LIT>" <EOL> assert tw . lines [ <NUM_LIT:2> ] == "<STR_LIT>" <EOL> assert tw . lines [ <NUM_LIT:3> ] . endswith ( "<STR_LIT>" ) <EOL> assert tw . lines [ <NUM_LIT:4> ] == ( "<STR_LIT>" , None ) <EOL> assert tw . lines [ <NUM_LIT:5> ] == "<STR_LIT>" <EOL> assert tw . lines [ <NUM_LIT:6> ] == "<STR_LIT>" <EOL> assert tw . lines [ <NUM_LIT:7> ] == "<STR_LIT>" <EOL> assert tw . lines [ <NUM_LIT:8> ] == "<STR_LIT>" <EOL> assert tw . lines [ <NUM_LIT:9> ] == "<STR_LIT>" <EOL> assert tw . lines [ <NUM_LIT:10> ] . endswith ( "<STR_LIT>" ) <EOL> def test_toterminal_long_filenames ( self ) : <EOL> mod = self . importasmod ( """<STR_LIT>""" ) <EOL> excinfo = py . test . raises ( ValueError , mod . f ) <EOL> tw = TWMock ( ) <EOL> path = py . path . local ( mod . __file__ ) <EOL> old = path . dirpath ( ) . chdir ( ) <EOL> try : <EOL> repr = excinfo . getrepr ( abspath = False ) <EOL> repr . toterminal ( tw ) <EOL> line = tw . lines [ - <NUM_LIT:1> ] <EOL> x = py . path . local ( ) . bestrelpath ( path ) <EOL> if len ( x ) < len ( str ( path ) ) : <EOL> assert line == "<STR_LIT>" <EOL> repr = excinfo . getrepr ( abspath = True ) <EOL> repr . toterminal ( tw ) <EOL> line = tw . lines [ - <NUM_LIT:1> ] <EOL> assert line == "<STR_LIT>" % ( path , ) <EOL> finally : <EOL> old . chdir ( ) <EOL> def test_format_excinfo ( self ) : <EOL> mod = self . importasmod ( """<STR_LIT>""" ) <EOL> excinfo = py . test . raises ( ValueError , mod . f ) <EOL> def format_and_str ( kw ) : <EOL> tw = py . io . TerminalWriter ( stringio = True ) <EOL> repr = excinfo . getrepr ( ** kw ) <EOL> repr . toterminal ( tw ) <EOL> assert tw . stringio . getvalue ( ) <EOL> for combo in self . allcombos ( ) : <EOL> yield format_and_str , combo <EOL> def allcombos ( self ) : <EOL> for style in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> for showlocals in ( True , False ) : <EOL> for tbfilter in ( True , False ) : <EOL> for funcargs in ( True , False ) : <EOL> kw = { '<STR_LIT>' : style , <EOL> '<STR_LIT>' : showlocals , <EOL> '<STR_LIT>' : funcargs , <EOL> '<STR_LIT>' : tbfilter <EOL> } <EOL> yield kw </s>
