#NEWLINE# def test_excepts( ) : #NEWLINE# #INDENT# assert ( excepts . __name__ == 'excepts' ) #NEWLINE# assert excepts . __doc__ . startswith ( 'A wrapper around a function to catch exceptions and\n    dispatch to a handler.\n' ) #NEWLINE# def idx( a ) : #NEWLINE# #INDENT# 'idx docstring\n        ' #NEWLINE# return [ 1 , 2 ] . index ( a ) #NEWLINE# #UNINDENT# def handler( e ) : #NEWLINE# #INDENT# 'handler docstring\n        ' #NEWLINE# assert isinstance ( e , ValueError ) #NEWLINE# return ( - 1 ) #NEWLINE# #UNINDENT# excepting = excepts ( ValueError , idx , handler ) #NEWLINE# assert ( excepting ( 1 ) == 0 ) #NEWLINE# assert ( excepting ( 2 ) == 1 ) #NEWLINE# assert ( excepting ( 3 ) == ( - 1 ) ) #NEWLINE# assert ( excepting . __name__ == 'idx_excepting_ValueError' ) #NEWLINE# assert ( 'idx docstring' in excepting . __doc__ ) #NEWLINE# assert ( 'ValueError' in excepting . __doc__ ) #NEWLINE# assert ( 'handler docstring' in excepting . __doc__ ) #NEWLINE# def getzero( a ) : #NEWLINE# #INDENT# 'getzero docstring\n        ' #NEWLINE# return a [ 0 ] #NEWLINE# #UNINDENT# excepting = excepts ( ( IndexError , KeyError ) , getzero ) #NEWLINE# assert ( excepting ( [ ] ) is None ) #NEWLINE# assert ( excepting ( [ 1 ] ) == 1 ) #NEWLINE# assert ( excepting ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) is None ) #NEWLINE# assert ( excepting ( { #NEWLINE# #INDENT# 0 : 1 , #NEWLINE# #UNINDENT# } ) == 1 ) #NEWLINE# assert ( excepting . __name__ == 'getzero_excepting_IndexError_or_KeyError' ) #NEWLINE# assert ( 'getzero docstring' in excepting . __doc__ ) #NEWLINE# assert ( 'return_none' in excepting . __doc__ ) #NEWLINE# assert ( 'Returns None' in excepting . __doc__ ) #NEWLINE# def raise_( a ) : #NEWLINE# #INDENT# 'A function that raises an instance of the exception type given.\n        ' #NEWLINE# raise a ( ) #NEWLINE# #UNINDENT# excepting = excepts ( ( ValueError , KeyError ) , raise_ ) #NEWLINE# assert ( excepting ( ValueError ) is None ) #NEWLINE# assert ( excepting ( KeyError ) is None ) #NEWLINE# assert raises ( TypeError , ( lambda : excepting ( TypeError ) ) ) #NEWLINE# assert raises ( NotImplementedError , ( lambda : excepting ( NotImplementedError ) ) ) #NEWLINE# excepting = excepts ( object ( ) , object ( ) , object ( ) ) #NEWLINE# assert ( excepting . __name__ == 'excepting' ) #NEWLINE# assert ( excepting . __doc__ == excepts . __doc__ )