#NEWLINE# def test_partial_hooks( self ) : #NEWLINE# #INDENT# run_hook = [ ] #NEWLINE# class RootController ( object ) : #NEWLINE# #INDENT# @ expose ( ) #NEWLINE# def index( self , req , resp ) : #NEWLINE# #INDENT# run_hook . append ( 'inside' ) #NEWLINE# return 'Hello World!' #NEWLINE# #UNINDENT# @ expose ( ) #NEWLINE# def causeerror( self , req , resp ) : #NEWLINE# #INDENT# return [ ] [ 1 ] #NEWLINE# #UNINDENT# #UNINDENT# class ErrorHook ( PecanHook ) : #NEWLINE# #INDENT# def on_error( self , state , e ) : #NEWLINE# #INDENT# run_hook . append ( 'error' ) #NEWLINE# #UNINDENT# #UNINDENT# class OnRouteHook ( PecanHook ) : #NEWLINE# #INDENT# def on_route( self , state ) : #NEWLINE# #INDENT# run_hook . append ( 'on_route' ) #NEWLINE# #UNINDENT# #UNINDENT# app = TestApp ( Pecan ( RootController ( ) , hooks = [ ErrorHook ( ) , OnRouteHook ( ) ] , use_context_locals = False ) ) #NEWLINE# response = app . get ( '/' ) #NEWLINE# assert ( response . status_int == 200 ) #NEWLINE# assert ( response . body == b_ ( 'Hello World!' ) ) #NEWLINE# assert ( len ( run_hook ) == 2 ) #NEWLINE# assert ( run_hook [ 0 ] == 'on_route' ) #NEWLINE# assert ( run_hook [ 1 ] == 'inside' ) #NEWLINE# run_hook = [ ] #NEWLINE# try : #NEWLINE# #INDENT# response = app . get ( '/causeerror' ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# assert isinstance ( app , IndexError ) #NEWLINE# #UNINDENT# assert ( len ( run_hook ) == 2 ) #NEWLINE# assert ( run_hook [ 0 ] == 'on_route' ) #NEWLINE# assert ( run_hook [ 1 ] == 'error' )