#NEWLINE# def __new__( cls , name , bases , namespace , **kwargs ) : #NEWLINE# #INDENT# def generate_test( name , examples , expected_ ) : #NEWLINE# #INDENT# def test( self ) : #NEWLINE# #INDENT# if isinstance ( expected_ , ( str , tuple ) ) : #NEWLINE# #INDENT# expected = [ expected_ ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# expected = expected_ #NEWLINE# #UNINDENT# if ( not isinstance ( examples , list ) ) : #NEWLINE# #INDENT# examples_ = [ examples ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# examples_ = examples #NEWLINE# #UNINDENT# for ( example , exp ) in zip ( examples_ , expected ) : #NEWLINE# #INDENT# if ( isinstance ( example , tuple ) and ( example [ 0 ] == 'custom_exceptions' ) ) : #NEWLINE# #INDENT# ( custom_exceptions , example_ ) = ( example [ 1 ] , example [ 2 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# custom_exceptions = [ ] #NEWLINE# example_ = ( example if ( not isinstance ( example , list ) ) else example [ : ] ) #NEWLINE# #UNINDENT# if isinstance ( exp , str ) : #NEWLINE# #INDENT# self . assertEqual ( self . gen ( custom_exceptions , example_ ) , exp ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( exp [ 0 ] == 'raw' ) : #NEWLINE# #INDENT# self . assertEqual ( self . gen ( custom_exceptions , example_ ) , exp ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( imports , source ) = self . gen_with_imports ( custom_exceptions , example_ ) #NEWLINE# self . assertCountEqual ( imports , exp [ 0 ] ) #NEWLINE# self . assertEqual ( source , exp [ 1 ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return test #NEWLINE# #UNINDENT# types = list ( namespace . keys ( ) ) #NEWLINE# for name in types : #NEWLINE# #INDENT# exp = namespace [ name ] #NEWLINE# if ( name . startswith ( 'gen' ) or ( name [ 0 ] == '_' ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( name [ ( - 1 ) ] == '_' ) : #NEWLINE# #INDENT# name = name [ : ( - 1 ) ] #NEWLINE# #UNINDENT# examples = globals ( ) . get ( name . title ( ) . replace ( '_' , '' ) ) #NEWLINE# if examples : #NEWLINE# #INDENT# test_name = ( 'test_%s' % name ) #NEWLINE# namespace [ test_name ] = generate_test ( name , examples , exp ) #NEWLINE# #UNINDENT# #UNINDENT# if ( 'gen' not in namespace ) : #NEWLINE# #INDENT# namespace [ 'gen' ] = TestHelpers . gen #NEWLINE# #UNINDENT# if ( 'gen_with_imports' not in namespace ) : #NEWLINE# #INDENT# namespace [ 'gen_with_imports' ] = TestHelpers . gen_with_imports #NEWLINE# #UNINDENT# namespace [ 'maxDiff' ] = None #NEWLINE# return super ( ) . __new__ ( cls , name , bases , namespace )