#NEWLINE# def assertRaises( self , func , args , kwargs , expected_exception , expected_message ) : #NEWLINE# #INDENT# '\n        Assert that the expected exception is raised when calling a\n        function, and that the right error message is included with\n        that exception.\n\n        Arguments:\n          func -- the function to call\n          args -- positional arguments to `func`\n          kwargs -- keyword arguments to `func`\n          expected_exception -- exception that should be raised\n          expected_message -- expected exception message (or pattern\n            if a compiled regex object)\n\n        Returns the exception raised for further testing.\n        ' #NEWLINE# if ( args is None ) : #NEWLINE# #INDENT# args = ( ) #NEWLINE# #UNINDENT# if ( kwargs is None ) : #NEWLINE# #INDENT# kwargs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# func ( * args , ** kwargs ) #NEWLINE# #UNINDENT# except expected_exception as err : #NEWLINE# #INDENT# actual_message = str ( err ) #NEWLINE# if isinstance ( expected_message , retype ) : #NEWLINE# #INDENT# self . assertTrue ( expected_message . search ( actual_message ) , ( "expected exception message pattern:\n/%s/\nactual exception message:\n'''%s'''\n" % ( expected_message . pattern , actual_message ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . assertEqual ( actual_message , expected_message , ( "expected exception message:\n'''%s'''\nactual exception message:\n'''%s'''\n" % ( expected_message , actual_message ) ) ) #NEWLINE# #UNINDENT# return err #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . fail ( ( 'expected exception %(expected_exception)s not raised\ncalled %(func)r\nwith args %(args)r\nand kwargs %(kwargs)r\n' % locals ( ) ) )