#NEWLINE# @ library . register ( 'testem' ) #NEWLINE# def testem_violation( data ) : #NEWLINE# #INDENT# 'Testem violation\n\n    :param data: task data\n    :type data: dict\n    :returns: dict\n    ' #NEWLINE# lines = data [ 'raw' ] . split ( '\n' ) #NEWLINE# runs = [ ] #NEWLINE# tests = 0 #NEWLINE# pass_ = 0 #NEWLINE# fail = 0 #NEWLINE# not_ok = False #NEWLINE# for line in lines : #NEWLINE# #INDENT# ok_match = re . match ( '^(.*ok) (\\d*) (.*) - (.*)$' , line ) #NEWLINE# if ok_match : #NEWLINE# #INDENT# runs . append ( ( ok_match . groups ( ) + ( [ ] , ) ) ) #NEWLINE# if ( ok_match . groups ( ) [ 0 ] == 'not ok' ) : #NEWLINE# #INDENT# not_ok = True #NEWLINE# #UNINDENT# #UNINDENT# if ( not len ( line ) ) : #NEWLINE# #INDENT# not_ok = False #NEWLINE# #UNINDENT# if ( not_ok and ( line . find ( '        ' ) == 0 ) ) : #NEWLINE# #INDENT# runs [ ( - 1 ) ] [ ( - 1 ) ] . append ( line [ 8 : ] ) #NEWLINE# #UNINDENT# if ( line . find ( '# tests' ) == 0 ) : #NEWLINE# #INDENT# tests = int ( line . split ( ' ' ) [ ( - 1 ) ] ) #NEWLINE# #UNINDENT# if ( line . find ( '# pass' ) == 0 ) : #NEWLINE# #INDENT# pass_ = int ( line . split ( ' ' ) [ ( - 1 ) ] ) #NEWLINE# #UNINDENT# if ( line . find ( '# fail' ) == 0 ) : #NEWLINE# #INDENT# fail = int ( line . split ( ' ' ) [ ( - 1 ) ] ) #NEWLINE# #UNINDENT# #UNINDENT# data [ 'status' ] = ( STATUS_SUCCESS if ( fail == 0 ) else STATUS_FAILED ) #NEWLINE# data [ 'preview' ] = render_to_string ( 'violations/testem/preview.html' , { #NEWLINE# #INDENT# 'tests' : tests , #NEWLINE# 'pass' : pass_ , #NEWLINE# 'fail' : fail , #NEWLINE# #UNINDENT# } ) #NEWLINE# data [ 'prepared' ] = render_to_string ( 'violations/testem/prepared.html' , { #NEWLINE# #INDENT# 'tests' : tests , #NEWLINE# 'pass' : pass_ , #NEWLINE# 'fail' : fail , #NEWLINE# 'runs' : runs , #NEWLINE# #UNINDENT# } ) #NEWLINE# data [ 'plot' ] = { #NEWLINE# #INDENT# 'tests' : tests , #NEWLINE# 'pass' : pass_ , #NEWLINE# 'fail' : fail , #NEWLINE# #UNINDENT# } #NEWLINE# data [ 'success_percent' ] = ( ( ( pass_ * 100 ) / tests ) if lines else 100 ) #NEWLINE# return data