#NEWLINE# def _filterwarnings( filters , quiet = False ) : #NEWLINE# #INDENT# "Catch the warnings, then check if all the expected\n    warnings have been raised and re-raise unexpected warnings.\n    If 'quiet' is True, only re-raise the unexpected warnings.\n    " #NEWLINE# frame = sys . _getframe ( 2 ) #NEWLINE# registry = frame . f_globals . get ( '__warningregistry__' ) #NEWLINE# if registry : #NEWLINE# #INDENT# if utils . PY3 : #NEWLINE# #INDENT# registry . clear ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for i in range ( len ( registry ) ) : #NEWLINE# #INDENT# registry . pop ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# with warnings . catch_warnings ( record = True ) as w : #NEWLINE# #INDENT# sys . modules [ 'warnings' ] . simplefilter ( 'always' ) #NEWLINE# ( yield WarningsRecorder ( w ) ) #NEWLINE# #UNINDENT# reraise = list ( w ) #NEWLINE# missing = [ ] #NEWLINE# for ( msg , cat ) in filters : #NEWLINE# #INDENT# seen = False #NEWLINE# for w in reraise [ : ] : #NEWLINE# #INDENT# warning = w . message #NEWLINE# if ( re . match ( msg , str ( warning ) , re . I ) and issubclass ( warning . __class__ , cat ) ) : #NEWLINE# #INDENT# seen = True #NEWLINE# reraise . remove ( w ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( not seen ) and ( not quiet ) ) : #NEWLINE# #INDENT# missing . append ( ( msg , cat . __name__ ) ) #NEWLINE# #UNINDENT# #UNINDENT# if reraise : #NEWLINE# #INDENT# raise AssertionError ( ( 'unhandled warning %s' % reraise [ 0 ] ) ) #NEWLINE# #UNINDENT# if missing : #NEWLINE# #INDENT# raise AssertionError ( ( 'filter (%r, %s) did not catch any warning' % missing [ 0 ] ) )