<s> from test import test_support <EOL> import unittest <EOL> import sys <EOL> import difflib <EOL> def basic ( ) : <EOL> return <NUM_LIT:1> <EOL> basic . events = [ ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) ] <EOL> def arigo_example ( ) : <EOL> x = <NUM_LIT:1> <EOL> del x <EOL> while <NUM_LIT:0> : <EOL> pass <EOL> x = <NUM_LIT:1> <EOL> arigo_example . events = [ ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:5> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:5> , '<STR_LIT>' ) ] <EOL> def one_instr_line ( ) : <EOL> x = <NUM_LIT:1> <EOL> del x <EOL> x = <NUM_LIT:1> <EOL> one_instr_line . events = [ ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) ] <EOL> def no_pop_tops ( ) : <EOL> x = <NUM_LIT:1> <EOL> for a in range ( <NUM_LIT:2> ) : <EOL> if a : <EOL> x = <NUM_LIT:1> <EOL> else : <EOL> x = <NUM_LIT:1> <EOL> no_pop_tops . events = [ ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:6> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) ] <EOL> def no_pop_blocks ( ) : <EOL> y = <NUM_LIT:1> <EOL> while not y : <EOL> bla <EOL> x = <NUM_LIT:1> <EOL> no_pop_blocks . events = [ ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) ] <EOL> def called ( ) : <EOL> x = <NUM_LIT:1> <EOL> def call ( ) : <EOL> called ( ) <EOL> call . events = [ ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( - <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( - <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( - <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) ] <EOL> def raises ( ) : <EOL> raise Exception <EOL> def test_raise ( ) : <EOL> try : <EOL> raises ( ) <EOL> except Exception , exc : <EOL> x = <NUM_LIT:1> <EOL> test_raise . events = [ ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( - <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( - <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( - <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( - <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) ] <EOL> def _settrace_and_return ( tracefunc ) : <EOL> sys . settrace ( tracefunc ) <EOL> sys . _getframe ( ) . f_back . f_trace = tracefunc <EOL> def settrace_and_return ( tracefunc ) : <EOL> _settrace_and_return ( tracefunc ) <EOL> settrace_and_return . events = [ ( <NUM_LIT:1> , '<STR_LIT>' ) ] <EOL> def _settrace_and_raise ( tracefunc ) : <EOL> sys . settrace ( tracefunc ) <EOL> sys . _getframe ( ) . f_back . f_trace = tracefunc <EOL> raise RuntimeError <EOL> def settrace_and_raise ( tracefunc ) : <EOL> try : <EOL> _settrace_and_raise ( tracefunc ) <EOL> except RuntimeError , exc : <EOL> pass <EOL> settrace_and_raise . events = [ ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) ] <EOL> def ireturn_example ( ) : <EOL> a = <NUM_LIT:5> <EOL> b = <NUM_LIT:5> <EOL> if a == b : <EOL> b = a + <NUM_LIT:1> <EOL> else : <EOL> pass <EOL> ireturn_example . events = [ ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:6> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:6> , '<STR_LIT>' ) ] <EOL> def tightloop_example ( ) : <EOL> items = range ( <NUM_LIT:0> , <NUM_LIT:3> ) <EOL> try : <EOL> i = <NUM_LIT:0> <EOL> while <NUM_LIT:1> : <EOL> b = items [ i ] ; i += <NUM_LIT:1> <EOL> except IndexError : <EOL> pass <EOL> tightloop_example . events = [ ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:5> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:5> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:5> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:5> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:5> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:6> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:7> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:7> , '<STR_LIT>' ) ] <EOL> def tighterloop_example ( ) : <EOL> items = range ( <NUM_LIT:1> , <NUM_LIT:4> ) <EOL> try : <EOL> i = <NUM_LIT:0> <EOL> while <NUM_LIT:1> : i = items [ i ] <EOL> except IndexError : <EOL> pass <EOL> tighterloop_example . events = [ ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:5> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:6> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:6> , '<STR_LIT>' ) ] <EOL> def generator_function ( ) : <EOL> try : <EOL> yield True <EOL> "<STR_LIT>" <EOL> finally : <EOL> x = "<STR_LIT>" <EOL> def generator_example ( ) : <EOL> gen = generator_function ( ) <EOL> x = any ( gen ) <EOL> gen . close ( ) <EOL> for x in range ( <NUM_LIT:10> ) : <EOL> y = x <EOL> generator_example . events = ( [ ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( - <NUM_LIT:6> , '<STR_LIT>' ) , <EOL> ( - <NUM_LIT:5> , '<STR_LIT>' ) , <EOL> ( - <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( - <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( - <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( - <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( - <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( - <NUM_LIT:1> , '<STR_LIT>' ) ] + <EOL> [ ( <NUM_LIT:7> , '<STR_LIT>' ) , ( <NUM_LIT:8> , '<STR_LIT>' ) ] * <NUM_LIT:10> + <EOL> [ ( <NUM_LIT:7> , '<STR_LIT>' ) , ( <NUM_LIT:7> , '<STR_LIT>' ) ] ) <EOL> class Tracer : <EOL> def __init__ ( self ) : <EOL> self . events = [ ] <EOL> def trace ( self , frame , event , arg ) : <EOL> self . events . append ( ( frame . f_lineno , event ) ) <EOL> return self . trace <EOL> def traceWithGenexp ( self , frame , event , arg ) : <EOL> ( o for o in [ <NUM_LIT:1> ] ) <EOL> self . events . append ( ( frame . f_lineno , event ) ) <EOL> return self . trace <EOL> class TraceTestCase ( unittest . TestCase ) : <EOL> def compare_events ( self , line_offset , events , expected_events ) : <EOL> events = [ ( l - line_offset , e ) for ( l , e ) in events ] <EOL> if events != expected_events : <EOL> self . fail ( <EOL> "<STR_LIT>" + <EOL> "<STR_LIT:\n>" . join ( difflib . ndiff ( [ str ( x ) for x in expected_events ] , <EOL> [ str ( x ) for x in events ] ) ) ) <EOL> def run_and_compare ( self , func , events ) : <EOL> tracer = Tracer ( ) <EOL> sys . settrace ( tracer . trace ) <EOL> func ( ) <EOL> sys . settrace ( None ) <EOL> self . compare_events ( func . func_code . co_firstlineno , <EOL> tracer . events , events ) <EOL> def run_test ( self , func ) : <EOL> self . run_and_compare ( func , func . events ) <EOL> def run_test2 ( self , func ) : <EOL> tracer = Tracer ( ) <EOL> func ( tracer . trace ) <EOL> sys . settrace ( None ) <EOL> self . compare_events ( func . func_code . co_firstlineno , <EOL> tracer . events , func . events ) <EOL> def test_01_basic ( self ) : <EOL> self . run_test ( basic ) <EOL> def test_02_arigo ( self ) : <EOL> self . run_test ( arigo_example ) <EOL> def test_03_one_instr ( self ) : <EOL> self . run_test ( one_instr_line ) <EOL> def test_04_no_pop_blocks ( self ) : <EOL> self . run_test ( no_pop_blocks ) <EOL> def test_05_no_pop_tops ( self ) : <EOL> self . run_test ( no_pop_tops ) <EOL> def test_06_call ( self ) : <EOL> self . run_test ( call ) <EOL> def test_07_raise ( self ) : <EOL> self . run_test ( test_raise ) <EOL> def test_08_settrace_and_return ( self ) : <EOL> self . run_test2 ( settrace_and_return ) <EOL> def test_09_settrace_and_raise ( self ) : <EOL> self . run_test2 ( settrace_and_raise ) <EOL> def test_10_ireturn ( self ) : <EOL> self . run_test ( ireturn_example ) <EOL> def test_11_tightloop ( self ) : <EOL> self . run_test ( tightloop_example ) <EOL> def test_12_tighterloop ( self ) : <EOL> self . run_test ( tighterloop_example ) <EOL> def test_13_genexp ( self ) : <EOL> self . run_test ( generator_example ) <EOL> tracer = Tracer ( ) <EOL> sys . settrace ( tracer . traceWithGenexp ) <EOL> generator_example ( ) <EOL> sys . settrace ( None ) <EOL> self . compare_events ( generator_example . func_code . co_firstlineno , <EOL> tracer . events , generator_example . events ) <EOL> def test_14_onliner_if ( self ) : <EOL> def onliners ( ) : <EOL> if True : False <EOL> else : True <EOL> return <NUM_LIT:0> <EOL> self . run_and_compare ( <EOL> onliners , <EOL> [ ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) ] ) <EOL> def test_15_loops ( self ) : <EOL> def for_example ( ) : <EOL> for x in range ( <NUM_LIT:2> ) : <EOL> pass <EOL> self . run_and_compare ( <EOL> for_example , <EOL> [ ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) ] ) <EOL> def while_example ( ) : <EOL> x = <NUM_LIT:2> <EOL> while x > <NUM_LIT:0> : <EOL> x -= <NUM_LIT:1> <EOL> self . run_and_compare ( <EOL> while_example , <EOL> [ ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) ] ) <EOL> def test_16_blank_lines ( self ) : <EOL> exec ( "<STR_LIT>" + "<STR_LIT:\n>" * <NUM_LIT> + "<STR_LIT>" ) <EOL> self . run_and_compare ( <EOL> f , <EOL> [ ( <NUM_LIT:0> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT> , '<STR_LIT>' ) ] ) <EOL> class RaisingTraceFuncTestCase ( unittest . TestCase ) : <EOL> def trace ( self , frame , event , arg ) : <EOL> """<STR_LIT>""" <EOL> if event == self . raiseOnEvent : <EOL> raise ValueError <EOL> else : <EOL> return self . trace <EOL> def f ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . raiseOnEvent == '<STR_LIT>' : <EOL> x = <NUM_LIT:0> <EOL> y = <NUM_LIT:1> / x <EOL> else : <EOL> return <NUM_LIT:1> <EOL> def run_test_for_event ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . raiseOnEvent = event <EOL> try : <EOL> for i in xrange ( sys . getrecursionlimit ( ) + <NUM_LIT:1> ) : <EOL> sys . settrace ( self . trace ) <EOL> try : <EOL> self . f ( ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> except RuntimeError : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_call ( self ) : <EOL> self . run_test_for_event ( '<STR_LIT>' ) <EOL> def test_line ( self ) : <EOL> self . run_test_for_event ( '<STR_LIT>' ) <EOL> def test_return ( self ) : <EOL> self . run_test_for_event ( '<STR_LIT>' ) <EOL> def test_exception ( self ) : <EOL> self . run_test_for_event ( '<STR_LIT>' ) <EOL> def test_trash_stack ( self ) : <EOL> def f ( ) : <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> print i <EOL> def g ( frame , why , extra ) : <EOL> if ( why == '<STR_LIT>' and <EOL> frame . f_lineno == f . func_code . co_firstlineno + <NUM_LIT:2> ) : <EOL> raise RuntimeError , "<STR_LIT>" <EOL> return g <EOL> sys . settrace ( g ) <EOL> try : <EOL> f ( ) <EOL> except RuntimeError : <EOL> import gc <EOL> gc . collect ( ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> class JumpTracer : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , function ) : <EOL> self . function = function <EOL> self . jumpFrom = function . jump [ <NUM_LIT:0> ] <EOL> self . jumpTo = function . jump [ <NUM_LIT:1> ] <EOL> self . done = False <EOL> def trace ( self , frame , event , arg ) : <EOL> if not self . done and frame . f_code == self . function . func_code : <EOL> firstLine = frame . f_code . co_firstlineno <EOL> if frame . f_lineno == firstLine + self . jumpFrom : <EOL> try : <EOL> frame . f_lineno = firstLine + self . jumpTo <EOL> except TypeError : <EOL> frame . f_lineno = self . jumpTo <EOL> self . done = True <EOL> return self . trace <EOL> def jump_simple_forwards ( output ) : <EOL> output . append ( <NUM_LIT:1> ) <EOL> output . append ( <NUM_LIT:2> ) <EOL> output . append ( <NUM_LIT:3> ) <EOL> jump_simple_forwards . jump = ( <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> jump_simple_forwards . output = [ <NUM_LIT:3> ] <EOL> def jump_simple_backwards ( output ) : <EOL> output . append ( <NUM_LIT:1> ) <EOL> output . append ( <NUM_LIT:2> ) <EOL> jump_simple_backwards . jump = ( <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> jump_simple_backwards . output = [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> def jump_out_of_block_forwards ( output ) : <EOL> for i in <NUM_LIT:1> , <NUM_LIT:2> : <EOL> output . append ( <NUM_LIT:2> ) <EOL> for j in [ <NUM_LIT:3> ] : <EOL> output . append ( <NUM_LIT:4> ) <EOL> output . append ( <NUM_LIT:5> ) <EOL> jump_out_of_block_forwards . jump = ( <NUM_LIT:3> , <NUM_LIT:5> ) <EOL> jump_out_of_block_forwards . output = [ <NUM_LIT:2> , <NUM_LIT:5> ] <EOL> def jump_out_of_block_backwards ( output ) : <EOL> output . append ( <NUM_LIT:1> ) <EOL> for i in [ <NUM_LIT:1> ] : <EOL> output . append ( <NUM_LIT:3> ) <EOL> for j in [ <NUM_LIT:2> ] : <EOL> output . append ( <NUM_LIT:5> ) <EOL> output . append ( <NUM_LIT:6> ) <EOL> output . append ( <NUM_LIT:7> ) <EOL> jump_out_of_block_backwards . jump = ( <NUM_LIT:6> , <NUM_LIT:1> ) <EOL> jump_out_of_block_backwards . output = [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] <EOL> def jump_to_codeless_line ( output ) : <EOL> output . append ( <NUM_LIT:1> ) <EOL> output . append ( <NUM_LIT:3> ) <EOL> jump_to_codeless_line . jump = ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> jump_to_codeless_line . output = [ <NUM_LIT:3> ] <EOL> def jump_to_same_line ( output ) : <EOL> output . append ( <NUM_LIT:1> ) <EOL> output . append ( <NUM_LIT:2> ) <EOL> output . append ( <NUM_LIT:3> ) <EOL> jump_to_same_line . jump = ( <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> jump_to_same_line . output = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> def jump_in_nested_finally ( output ) : <EOL> try : <EOL> output . append ( <NUM_LIT:2> ) <EOL> finally : <EOL> output . append ( <NUM_LIT:4> ) <EOL> try : <EOL> output . append ( <NUM_LIT:6> ) <EOL> finally : <EOL> output . append ( <NUM_LIT:8> ) <EOL> output . append ( <NUM_LIT:9> ) <EOL> jump_in_nested_finally . jump = ( <NUM_LIT:4> , <NUM_LIT:9> ) <EOL> jump_in_nested_finally . output = [ <NUM_LIT:2> , <NUM_LIT:9> ] <EOL> def no_jump_too_far_forwards ( output ) : <EOL> try : <EOL> output . append ( <NUM_LIT:2> ) <EOL> output . append ( <NUM_LIT:3> ) <EOL> except ValueError , e : <EOL> output . append ( '<STR_LIT>' in str ( e ) ) <EOL> no_jump_too_far_forwards . jump = ( <NUM_LIT:3> , <NUM_LIT:6> ) <EOL> no_jump_too_far_forwards . output = [ <NUM_LIT:2> , True ] <EOL> def no_jump_too_far_backwards ( output ) : <EOL> try : <EOL> output . append ( <NUM_LIT:2> ) <EOL> output . append ( <NUM_LIT:3> ) <EOL> except ValueError , e : <EOL> output . append ( '<STR_LIT>' in str ( e ) ) <EOL> no_jump_too_far_backwards . jump = ( <NUM_LIT:3> , - <NUM_LIT:1> ) <EOL> no_jump_too_far_backwards . output = [ <NUM_LIT:2> , True ] <EOL> def no_jump_to_except_1 ( output ) : <EOL> try : <EOL> output . append ( <NUM_LIT:2> ) <EOL> except : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> output . append ( '<STR_LIT>' in str ( e ) ) <EOL> no_jump_to_except_1 . jump = ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> no_jump_to_except_1 . output = [ True ] <EOL> def no_jump_to_except_2 ( output ) : <EOL> try : <EOL> output . append ( <NUM_LIT:2> ) <EOL> except ValueError : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> output . append ( '<STR_LIT>' in str ( e ) ) <EOL> no_jump_to_except_2 . jump = ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> no_jump_to_except_2 . output = [ True ] <EOL> def no_jump_to_except_3 ( output ) : <EOL> try : <EOL> output . append ( <NUM_LIT:2> ) <EOL> except ValueError , e : <EOL> output . append ( '<STR_LIT>' in str ( e ) ) <EOL> no_jump_to_except_3 . jump = ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> no_jump_to_except_3 . output = [ True ] <EOL> def no_jump_to_except_4 ( output ) : <EOL> try : <EOL> output . append ( <NUM_LIT:2> ) <EOL> except ( ValueError , RuntimeError ) , e : <EOL> output . append ( '<STR_LIT>' in str ( e ) ) <EOL> no_jump_to_except_4 . jump = ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> no_jump_to_except_4 . output = [ True ] <EOL> def no_jump_forwards_into_block ( output ) : <EOL> try : <EOL> output . append ( <NUM_LIT:2> ) <EOL> for i in <NUM_LIT:1> , <NUM_LIT:2> : <EOL> output . append ( <NUM_LIT:4> ) <EOL> except ValueError , e : <EOL> output . append ( '<STR_LIT>' in str ( e ) ) <EOL> no_jump_forwards_into_block . jump = ( <NUM_LIT:2> , <NUM_LIT:4> ) <EOL> no_jump_forwards_into_block . output = [ True ] <EOL> def no_jump_backwards_into_block ( output ) : <EOL> try : <EOL> for i in <NUM_LIT:1> , <NUM_LIT:2> : <EOL> output . append ( <NUM_LIT:3> ) <EOL> output . append ( <NUM_LIT:4> ) <EOL> except ValueError , e : <EOL> output . append ( '<STR_LIT>' in str ( e ) ) <EOL> no_jump_backwards_into_block . jump = ( <NUM_LIT:4> , <NUM_LIT:3> ) <EOL> no_jump_backwards_into_block . output = [ <NUM_LIT:3> , <NUM_LIT:3> , True ] <EOL> def no_jump_into_finally_block ( output ) : <EOL> try : <EOL> try : <EOL> output . append ( <NUM_LIT:3> ) <EOL> x = <NUM_LIT:1> <EOL> finally : <EOL> output . append ( <NUM_LIT:6> ) <EOL> except ValueError , e : <EOL> output . append ( '<STR_LIT>' in str ( e ) ) <EOL> no_jump_into_finally_block . jump = ( <NUM_LIT:4> , <NUM_LIT:6> ) <EOL> no_jump_into_finally_block . output = [ <NUM_LIT:3> , <NUM_LIT:6> , True ] <EOL> def no_jump_out_of_finally_block ( output ) : <EOL> try : <EOL> try : <EOL> output . append ( <NUM_LIT:3> ) <EOL> finally : <EOL> output . append ( <NUM_LIT:5> ) <EOL> output . append ( <NUM_LIT:6> ) <EOL> except ValueError , e : <EOL> output . append ( '<STR_LIT>' in str ( e ) ) <EOL> no_jump_out_of_finally_block . jump = ( <NUM_LIT:5> , <NUM_LIT:1> ) <EOL> no_jump_out_of_finally_block . output = [ <NUM_LIT:3> , True ] <EOL> def no_jump_to_non_integers ( output ) : <EOL> try : <EOL> output . append ( <NUM_LIT:2> ) <EOL> except ValueError , e : <EOL> output . append ( '<STR_LIT>' in str ( e ) ) <EOL> no_jump_to_non_integers . jump = ( <NUM_LIT:2> , "<STR_LIT>" ) <EOL> no_jump_to_non_integers . output = [ True ] <EOL> def no_jump_without_trace_function ( ) : <EOL> try : <EOL> previous_frame = sys . _getframe ( ) . f_back <EOL> previous_frame . f_lineno = previous_frame . f_lineno <EOL> except ValueError , e : <EOL> if '<STR_LIT>' not in str ( e ) : <EOL> raise <EOL> else : <EOL> raise RuntimeError , "<STR_LIT>" <EOL> class JumpTestCase ( unittest . TestCase ) : <EOL> def compare_jump_output ( self , expected , received ) : <EOL> if received != expected : <EOL> self . fail ( "<STR_LIT>" + <EOL> "<STR_LIT>" + repr ( expected ) + "<STR_LIT:\n>" + <EOL> "<STR_LIT>" + repr ( received ) ) <EOL> def run_test ( self , func ) : <EOL> tracer = JumpTracer ( func ) <EOL> sys . settrace ( tracer . trace ) <EOL> output = [ ] <EOL> func ( output ) <EOL> sys . settrace ( None ) <EOL> self . compare_jump_output ( func . output , output ) <EOL> def test_01_jump_simple_forwards ( self ) : <EOL> self . run_test ( jump_simple_forwards ) <EOL> def test_02_jump_simple_backwards ( self ) : <EOL> self . run_test ( jump_simple_backwards ) <EOL> def test_03_jump_out_of_block_forwards ( self ) : <EOL> self . run_test ( jump_out_of_block_forwards ) <EOL> def test_04_jump_out_of_block_backwards ( self ) : <EOL> self . run_test ( jump_out_of_block_backwards ) <EOL> def test_05_jump_to_codeless_line ( self ) : <EOL> self . run_test ( jump_to_codeless_line ) <EOL> def test_06_jump_to_same_line ( self ) : <EOL> self . run_test ( jump_to_same_line ) <EOL> def test_07_jump_in_nested_finally ( self ) : <EOL> self . run_test ( jump_in_nested_finally ) <EOL> def test_08_no_jump_too_far_forwards ( self ) : <EOL> self . run_test ( no_jump_too_far_forwards ) <EOL> def test_09_no_jump_too_far_backwards ( self ) : <EOL> self . run_test ( no_jump_too_far_backwards ) <EOL> def test_10_no_jump_to_except_1 ( self ) : <EOL> self . run_test ( no_jump_to_except_1 ) <EOL> def test_11_no_jump_to_except_2 ( self ) : <EOL> self . run_test ( no_jump_to_except_2 ) <EOL> def test_12_no_jump_to_except_3 ( self ) : <EOL> self . run_test ( no_jump_to_except_3 ) <EOL> def test_13_no_jump_to_except_4 ( self ) : <EOL> self . run_test ( no_jump_to_except_4 ) <EOL> def test_14_no_jump_forwards_into_block ( self ) : <EOL> self . run_test ( no_jump_forwards_into_block ) <EOL> def test_15_no_jump_backwards_into_block ( self ) : <EOL> self . run_test ( no_jump_backwards_into_block ) <EOL> def test_16_no_jump_into_finally_block ( self ) : <EOL> self . run_test ( no_jump_into_finally_block ) <EOL> def test_17_no_jump_out_of_finally_block ( self ) : <EOL> self . run_test ( no_jump_out_of_finally_block ) <EOL> def test_18_no_jump_to_non_integers ( self ) : <EOL> self . run_test ( no_jump_to_non_integers ) <EOL> def test_19_no_jump_without_trace_function ( self ) : <EOL> no_jump_without_trace_function ( ) <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( <EOL> TraceTestCase , <EOL> RaisingTraceFuncTestCase , <EOL> JumpTestCase <EOL> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
