#NEWLINE# def _trimFrames( self , frames ) : #NEWLINE# #INDENT# "\n        Trim frames to remove internal paths.\n\n        When a C{SynchronousTestCase} method fails synchronously, the stack\n        looks like this:\n         - [0]: C{SynchronousTestCase._run}\n         - [1]: C{util.runWithWarningsSuppressed}\n         - [2:-2]: code in the test method which failed\n         - [-1]: C{_synctest.fail}\n\n        When a C{TestCase} method fails synchronously, the stack looks like\n        this:\n         - [0]: C{defer.maybeDeferred}\n         - [1]: C{utils.runWithWarningsSuppressed}\n         - [2]: C{utils.runWithWarningsSuppressed}\n         - [3:-2]: code in the test method which failed\n         - [-1]: C{_synctest.fail}\n\n        When a method fails inside a C{Deferred} (i.e., when the test method\n        returns a C{Deferred}, and that C{Deferred}'s errback fires), the stack\n        captured inside the resulting C{Failure} looks like this:\n         - [0]: C{defer.Deferred._runCallbacks}\n         - [1:-2]: code in the testmethod which failed\n         - [-1]: C{_synctest.fail}\n\n        As a result, we want to trim either [maybeDeferred, runWWS, runWWS] or\n        [Deferred._runCallbacks] or [SynchronousTestCase._run, runWWS] from the\n        front, and trim the [unittest.fail] from the end.\n\n        There is also another case, when the test method is badly defined and\n        contains extra arguments.\n\n        If it doesn't recognize one of these cases, it just returns the\n        original frames.\n\n        @param frames: The C{list} of frames from the test failure.\n\n        @return: The C{list} of frames to display.\n        " #NEWLINE# newFrames = list ( frames ) #NEWLINE# if ( len ( frames ) < 2 ) : #NEWLINE# #INDENT# return newFrames #NEWLINE# #UNINDENT# firstMethod = newFrames [ 0 ] [ 0 ] #NEWLINE# firstFile = os . path . splitext ( os . path . basename ( newFrames [ 0 ] [ 1 ] ) ) [ 0 ] #NEWLINE# secondMethod = newFrames [ 1 ] [ 0 ] #NEWLINE# secondFile = os . path . splitext ( os . path . basename ( newFrames [ 1 ] [ 1 ] ) ) [ 0 ] #NEWLINE# syncCase = ( ( '_run' , '_synctest' ) , ( 'runWithWarningsSuppressed' , 'util' ) ) #NEWLINE# asyncCase = ( ( 'maybeDeferred' , 'defer' ) , ( 'runWithWarningsSuppressed' , 'utils' ) ) #NEWLINE# twoFrames = ( ( firstMethod , firstFile ) , ( secondMethod , secondFile ) ) #NEWLINE# if _PY3 : #NEWLINE# #INDENT# for frame in newFrames : #NEWLINE# #INDENT# frameFile = os . path . splitext ( os . path . basename ( frame [ 1 ] ) ) [ 0 ] #NEWLINE# if ( ( frameFile == 'compat' ) and ( frame [ 0 ] == 'reraise' ) ) : #NEWLINE# #INDENT# newFrames . pop ( newFrames . index ( frame ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( twoFrames == syncCase ) : #NEWLINE# #INDENT# newFrames = newFrames [ 2 : ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( twoFrames == asyncCase ) : #NEWLINE# #INDENT# newFrames = newFrames [ 3 : ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( firstMethod , firstFile ) == ( '_runCallbacks' , 'defer' ) ) : #NEWLINE# #INDENT# newFrames = newFrames [ 1 : ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not newFrames ) : #NEWLINE# #INDENT# return newFrames #NEWLINE# #UNINDENT# last = newFrames [ ( - 1 ) ] #NEWLINE# if ( last [ 0 ] . startswith ( 'fail' ) and ( os . path . splitext ( os . path . basename ( last [ 1 ] ) ) [ 0 ] == '_synctest' ) ) : #NEWLINE# #INDENT# newFrames = newFrames [ : ( - 1 ) ] #NEWLINE# #UNINDENT# return newFrames