예제 #1
0
파일: base.py 프로젝트: dcm/testplan
    def _merge_reports(self, test_report_lookup):
        """
        Merge report of MultiTest parts into test runner report.
        Return True if all parts are found and can be successfully merged.

        Format of test_report_lookup:
        {
            'report_uid_1': [
                (True, report_1_part_1), (True, report_1_part_2), ...
            ],
            'report_uid_2': [
                (True, report_2_part_1), (False, report_2_part_2), ...
            ],
            ...
        }
        """
        merge_result = True

        for uid, reports in test_report_lookup.items():
            count = reports[0][1].part[1]  # How many parts scheduled
            placeholder_report = self._result.test_report.get_by_uid(uid)
            reports.sort(key=lambda tup: tup[1].part[0])

            with placeholder_report.logged_exceptions():
                if len(reports) < count:
                    raise MergeError(
                        "Cannot merge parts for child report with "
                        "`uid`: {uid}, not all MultiTest parts "
                        "had been scheduled.".format(uid=uid)
                    )

                if any(
                    sibling_report.part[0] != idx
                    or sibling_report.part[1] != count
                    for idx, (run, sibling_report) in enumerate(reports)
                ):
                    raise ValueError(
                        "Cannot merge parts for child report with "
                        "`uid`: {uid}, invalid parameter of part "
                        "provided.".format(uid=uid)
                    )

            with placeholder_report.logged_exceptions():
                for run, sibling_report in reports:
                    if run and not isinstance(run, Exception):
                        placeholder_report.merge(sibling_report, strict=False)
                    else:
                        placeholder_report.status_override = Status.ERROR

            merge_result = (
                merge_result and placeholder_report.status != Status.ERROR
            )

        return merge_result
예제 #2
0
    def _merge_reports(self, test_report_lookup):
        """
        Merge report of MultiTest parts into test runner report.
        Return True if all parts are found and can be successfully merged.

        Format of test_report_lookup:
        {
            'report_uid_1': [
                (True, report_1_part_1), (True, report_1_part_2), ...
            ],
            'report_uid_2': [
                (True, report_2_part_1), (False, report_2_part_2), ...
            ],
            ...
        }
        """
        merge_result = True

        for uid, result in test_report_lookup.items():
            placeholder_report = self._result.test_report.get_by_uid(uid)
            num_of_parts = 0
            part_indexes = set()
            merged = False

            with placeholder_report.logged_exceptions():
                for run, report in result:
                    if num_of_parts and num_of_parts != report.part[1]:
                        raise ValueError(
                            "Cannot merge parts for child report with"
                            " `uid`: {uid}, invalid parameter of part"
                            " provided.".format(uid=uid))
                    elif report.part[0] in part_indexes:
                        raise ValueError(
                            "Cannot merge parts for child report with"
                            " `uid`: {uid}, duplicate MultiTest parts"
                            " had been scheduled.".format(uid=uid))
                    else:
                        part_indexes.add(report.part[0])
                        num_of_parts = report.part[1]

                    if run:
                        if isinstance(run, Exception):
                            raise run
                        else:
                            placeholder_report.merge(report, strict=False)
                    else:
                        raise MergeError(
                            "Cannot merge parts for child report with"
                            " `uid`: {uid}, at least one part (index:{part})"
                            " didn't run.".format(uid=uid,
                                                  part=report.part[0]))
                else:
                    if len(part_indexes) < num_of_parts:
                        raise MergeError(
                            "Cannot merge parts for child report with"
                            " `uid`: {uid}, not all MultiTest parts"
                            " had been scheduled.".format(uid=uid))
                merged = True

            # If fail to merge sibling reports, clear the placeholder report
            # but keep error logs, sibling reports will be appended at the end.
            if not merged:
                placeholder_report.entries = []
                placeholder_report._index = {}
                placeholder_report.status_override = Status.ERROR
                for _, report in result:
                    report.name = "{} - part({}/{})".format(
                        report.name, report.part[0], report.part[1])
                    report.uid = strings.uuid4()  # considered as error report
                    self._result.test_report.append(report)

            merge_result = (merge_result
                            and placeholder_report.status != Status.ERROR)

        return merge_result