#NEWLINE# def gen_assertion( self , assertion_config ) : #NEWLINE# #INDENT# self . log . debug ( 'Generating assertion, config: %s' , assertion_config ) #NEWLINE# assertion_elements = [ ] #NEWLINE# if isinstance ( assertion_config , string_types ) : #NEWLINE# #INDENT# assertion_config = { #NEWLINE# #INDENT# 'contains' : [ assertion_config ] , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# for val in assertion_config [ 'contains' ] : #NEWLINE# #INDENT# regexp = assertion_config . get ( 'regexp' , True ) #NEWLINE# reverse = assertion_config . get ( 'not' , False ) #NEWLINE# subject = assertion_config . get ( 'subject' , 'body' ) #NEWLINE# if ( subject != 'body' ) : #NEWLINE# #INDENT# raise ValueError ( "Only 'body' subject supported " ) #NEWLINE# #UNINDENT# if regexp : #NEWLINE# #INDENT# assert_method = ( 'self.assertEqual' if reverse else 'self.assertNotEqual' ) #NEWLINE# assertion_elements . append ( self . gen_method_statement ( ( 're_pattern = re.compile("%s")' % val ) ) ) #NEWLINE# method = ( '%s(0, len(re.findall(re_pattern, body)))' % assert_method ) #NEWLINE# assertion_elements . append ( self . gen_method_statement ( method ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert_method = ( 'self.assertNotIn' if reverse else 'self.assertIn' ) #NEWLINE# assertion_elements . append ( self . gen_method_statement ( ( '%s("%s", body)' % ( assert_method , val ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# return assertion_elements