def failed_build_tree(section, parent_node, level=0): """ Builds a tree for displaying items mimicking linux tree command. """ # max_len is calculated to align all the result values on the # right regardless of indentation from TreeNode. (80 char width) max_len = 66 - level * 4 # Determine if ran with harness or not if runtime.job: if section.type == 'Step': name = str_shortener('%s: %s' % (section.id, section.name), max_len) else: name = str_shortener(section.id, max_len) section_node = TreeNode( RESULT_ROW.format( name=name, # result = RESULT_COLOUR[str(section.result)].apply(str(section.result).upper()), result=str(section.result).upper(), max_len=max_len)) result = section.result.value sections = section.sections else: section_node = TreeNode( RESULT_ROW.format(name=str_shortener(section['name'], max_len), result=RESULT_COLOUR[str( section['result'])].apply( str(section['result']).upper()), max_len=max_len)) result = section['result'].value sections = section['sections'] # Determine if we're only looking to display failures or not parsed_args = _parse_args() if parsed_args['_display_only_failed']: if result not in ['passed']: parent_node.add_child(section_node) else: parent_node.add_child(section_node) # Recursive indentation for child_section in sections: if level < 2: failed_build_tree(child_section, section_node, level + 1) else: failed_build_tree(child_section, parent_node, level)
def generate_email_reports(): # Retrieve testsuite from ReportServer testsuite = runtime.details() summary_entries = [] detail_trees = [] # Parse run details from ReportServer into nice human-readable formats for task in testsuite.tasks: # New task tree task_tree = TreeNode('%s: %s' % (task.id, task.name)) for section in task.sections: # Add to summary summary_entries.append( TEST_RESULT_ROW.format(name=str_shortener( '%s: %s.%s' % (task.id, task.name, section.id), 70), result=str(section.result).upper(), max_len=70)) # Build task report tree failed_build_tree(section, task_tree) # Add task tree to details tree list detail_trees.append(task_tree) # Format details for email task_summary = '\n'.join(summary_entries) or\ 'Empty - did something go wrong?' task_details = '\n'.join(map(str, detail_trees)) or\ 'Empty - did something go wrong?' if str(task_details) == 'Task-1: unittests': task_details = ' %-70s%10s ' % ('ALL UNITTESTS', 'PASSED'.center(10)) # Add details to email contents if runtime.mail_report: runtime.mail_report.contents['Task Result Summary'] = task_summary runtime.mail_report.contents['Task Result Details'] = task_details