Beispiel #1
0
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)
Beispiel #2
0
    def log_summary(self):
        log.root.setLevel(0)
        if self.section_details:
            log.info(banner("Unittest results"))
            log.info(' %-70s%10s ' %
                     ('SECTIONS/TESTCASES', 'RESULT'.center(10)))
            log.info('-' * 80)

            report = TreeNode('.')
            for section in self.section_details:
                failed_build_tree(section, report)

            if str(report) == '.':
                log.info(' %-70s%10s ' %
                         ('ALL UNITTESTS', 'PASSED'.center(10)))
            else:
                log.info(str(report))

            log.info(banner("Summary"))
            for k in sorted(self.summary.keys()):

                log.info(' {name:<58}{num:>20} '.format(
                    name='Number of {}'.format(k.upper()),
                    num=self.summary[k]))
            log.info(' {name:<58}{num:>20} '.format(name='Total Number',
                                                    num=self.summary.total))
            log.info(' {name:<58}{num:>19.1f}% '.format(
                name='Success Rate', num=self.summary.success_rate))
            log.info('-' * 80)
            if glo_values.missingCount > 0:
                log.info(' {name:<58}{num:>20} '.format(
                    name='Total Parsers Missing Unittests',
                    num=glo_values.missingCount))
                log.info('-' * 80)

                if glo_values.missingParsers:
                    log.info("\n".join(glo_values.missingParsers),
                             extra={'colour': 'yellow'})
                    log.info('-' * 80)

            log.info(' {name:<58}{num:>20} '.format(
                name='Total Passing Unittests', num=glo_values.parserPassed))
            log.info(' {name:<58}{num:>20} '.format(
                name='Total Failed Unittests', num=glo_values.parserFailed))
            log.info(' {name:<58}{num:>20} '.format(
                name='Total Errored Unittests', num=glo_values.parserErrored))
            log.info(' {name:<58}{num:>20} '.format(
                name='Total Unittests', num=glo_values.parserTotal))
            log.info('-' * 80)

            if (hasattr(glo_values, '_class_exists')
                    and not glo_values._class_exists):
                parsed_args = _parse_args()
                log.info(f'`{parsed_args["_class"]}` does not exist',
                         extra={'colour': 'yellow'})
                log.info('-' * 80)

        else:
            log.info(banner('No Results To Show'))
Beispiel #3
0
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