Пример #1
0
    def assembled_report(reportdict):
        from _pytest._code.code import (
            ReprEntry,
            ReprEntryNative,
            ReprExceptionInfo,
            ReprFileLocation,
            ReprFuncArgs,
            ReprLocals,
            ReprTraceback,
        )

        if reportdict["longrepr"]:
            if ("reprcrash" in reportdict["longrepr"]
                    and "reprtraceback" in reportdict["longrepr"]):

                reprtraceback = reportdict["longrepr"]["reprtraceback"]
                reprcrash = reportdict["longrepr"]["reprcrash"]

                unserialized_entries = []
                reprentry = None
                for entry_data in reprtraceback["reprentries"]:
                    data = entry_data["data"]
                    entry_type = entry_data["type"]
                    if entry_type == "ReprEntry":
                        reprfuncargs = None
                        reprfileloc = None
                        reprlocals = None
                        if data["reprfuncargs"]:
                            reprfuncargs = ReprFuncArgs(**data["reprfuncargs"])
                        if data["reprfileloc"]:
                            reprfileloc = ReprFileLocation(
                                **data["reprfileloc"])
                        if data["reprlocals"]:
                            reprlocals = ReprLocals(
                                data["reprlocals"]["lines"])

                        reprentry = ReprEntry(
                            lines=data["lines"],
                            reprfuncargs=reprfuncargs,
                            reprlocals=reprlocals,
                            filelocrepr=reprfileloc,
                            style=data["style"],
                        )
                    elif entry_type == "ReprEntryNative":
                        reprentry = ReprEntryNative(data["lines"])
                    else:
                        report_unserialization_failure(entry_type, name,
                                                       reportdict)
                    unserialized_entries.append(reprentry)
                reprtraceback["reprentries"] = unserialized_entries

                exception_info = ReprExceptionInfo(
                    reprtraceback=ReprTraceback(**reprtraceback),
                    reprcrash=ReprFileLocation(**reprcrash),
                )

                for section in reportdict["longrepr"]["sections"]:
                    exception_info.addsection(*section)
                reportdict["longrepr"] = exception_info
        return reportdict
Пример #2
0
    def _from_json(cls, reportdict):
        """
        This was originally the serialize_report() function from xdist (ca03269).

        Factory method that returns either a TestReport or CollectReport, depending on the calling
        class. It's the callers responsibility to know which class to pass here.

        Experimental method.
        """
        if reportdict["longrepr"]:
            if ("reprcrash" in reportdict["longrepr"]
                    and "reprtraceback" in reportdict["longrepr"]):

                reprtraceback = reportdict["longrepr"]["reprtraceback"]
                reprcrash = reportdict["longrepr"]["reprcrash"]

                unserialized_entries = []
                reprentry = None
                for entry_data in reprtraceback["reprentries"]:
                    data = entry_data["data"]
                    entry_type = entry_data["type"]
                    if entry_type == "ReprEntry":
                        reprfuncargs = None
                        reprfileloc = None
                        reprlocals = None
                        if data["reprfuncargs"]:
                            reprfuncargs = ReprFuncArgs(**data["reprfuncargs"])
                        if data["reprfileloc"]:
                            reprfileloc = ReprFileLocation(
                                **data["reprfileloc"])
                        if data["reprlocals"]:
                            reprlocals = ReprLocals(
                                data["reprlocals"]["lines"])

                        reprentry = ReprEntry(
                            lines=data["lines"],
                            reprfuncargs=reprfuncargs,
                            reprlocals=reprlocals,
                            filelocrepr=reprfileloc,
                            style=data["style"],
                        )
                    elif entry_type == "ReprEntryNative":
                        reprentry = ReprEntryNative(data["lines"])
                    else:
                        _report_unserialization_failure(
                            entry_type, cls, reportdict)
                    unserialized_entries.append(reprentry)
                reprtraceback["reprentries"] = unserialized_entries

                exception_info = ReprExceptionInfo(
                    reprtraceback=ReprTraceback(**reprtraceback),
                    reprcrash=ReprFileLocation(**reprcrash),
                )

                for section in reportdict["longrepr"]["sections"]:
                    exception_info.addsection(*section)
                reportdict["longrepr"] = exception_info

        return cls(**reportdict)
Пример #3
0
    def assembled_report(reportdict):
        from _pytest._code.code import (
            ReprEntry,
            ReprEntryNative,
            ReprExceptionInfo,
            ReprFileLocation,
            ReprFuncArgs,
            ReprLocals,
            ReprTraceback
        )
        if reportdict['longrepr']:
            if 'reprcrash' in reportdict['longrepr'] and 'reprtraceback' in reportdict['longrepr']:

                reprtraceback = reportdict['longrepr']['reprtraceback']
                reprcrash = reportdict['longrepr']['reprcrash']

                unserialized_entries = []
                reprentry = None
                for entry_data in reprtraceback['reprentries']:
                    data = entry_data['data']
                    entry_type = entry_data['type']
                    if entry_type == 'ReprEntry':
                        reprfuncargs = None
                        reprfileloc = None
                        reprlocals = None
                        if data['reprfuncargs']:
                            reprfuncargs = ReprFuncArgs(
                                **data['reprfuncargs'])
                        if data['reprfileloc']:
                            reprfileloc = ReprFileLocation(
                                **data['reprfileloc'])
                        if data['reprlocals']:
                            reprlocals = ReprLocals(
                                data['reprlocals']['lines'])

                        reprentry = ReprEntry(
                            lines=data['lines'],
                            reprfuncargs=reprfuncargs,
                            reprlocals=reprlocals,
                            filelocrepr=reprfileloc,
                            style=data['style']
                        )
                    elif entry_type == 'ReprEntryNative':
                        reprentry = ReprEntryNative(data['lines'])
                    else:
                        report_unserialization_failure(
                            entry_type, name, reportdict)
                    unserialized_entries.append(reprentry)
                reprtraceback['reprentries'] = unserialized_entries

                exception_info = ReprExceptionInfo(
                    reprtraceback=ReprTraceback(**reprtraceback),
                    reprcrash=ReprFileLocation(**reprcrash),
                )

                for section in reportdict['longrepr']['sections']:
                    exception_info.addsection(*section)
                reportdict['longrepr'] = exception_info
        return reportdict
Пример #4
0
    def _from_json(cls, reportdict):
        """
        This was originally the serialize_report() function from xdist (ca03269).

        Factory method that returns either a TestReport or CollectReport, depending on the calling
        class. It's the callers responsibility to know which class to pass here.

        Experimental method.
        """
        if reportdict["longrepr"]:
            if (
                "reprcrash" in reportdict["longrepr"]
                and "reprtraceback" in reportdict["longrepr"]
            ):

                reprtraceback = reportdict["longrepr"]["reprtraceback"]
                reprcrash = reportdict["longrepr"]["reprcrash"]

                unserialized_entries = []
                reprentry = None
                for entry_data in reprtraceback["reprentries"]:
                    data = entry_data["data"]
                    entry_type = entry_data["type"]
                    if entry_type == "ReprEntry":
                        reprfuncargs = None
                        reprfileloc = None
                        reprlocals = None
                        if data["reprfuncargs"]:
                            reprfuncargs = ReprFuncArgs(**data["reprfuncargs"])
                        if data["reprfileloc"]:
                            reprfileloc = ReprFileLocation(**data["reprfileloc"])
                        if data["reprlocals"]:
                            reprlocals = ReprLocals(data["reprlocals"]["lines"])

                        reprentry = ReprEntry(
                            lines=data["lines"],
                            reprfuncargs=reprfuncargs,
                            reprlocals=reprlocals,
                            filelocrepr=reprfileloc,
                            style=data["style"],
                        )
                    elif entry_type == "ReprEntryNative":
                        reprentry = ReprEntryNative(data["lines"])
                    else:
                        _report_unserialization_failure(entry_type, cls, reportdict)
                    unserialized_entries.append(reprentry)
                reprtraceback["reprentries"] = unserialized_entries

                exception_info = ReprExceptionInfo(
                    reprtraceback=ReprTraceback(**reprtraceback),
                    reprcrash=ReprFileLocation(**reprcrash),
                )

                for section in reportdict["longrepr"]["sections"]:
                    exception_info.addsection(*section)
                reportdict["longrepr"] = exception_info

        return cls(**reportdict)
Пример #5
0
    def assembled_report(reportdict):
        from _pytest._code.code import (ReprEntry, ReprExceptionInfo,
                                        ReprFileLocation, ReprFuncArgs,
                                        ReprLocals, ReprTraceback)
        if reportdict['longrepr']:
            if 'reprcrash' and 'reprtraceback' in reportdict['longrepr']:

                reprtraceback = reportdict['longrepr']['reprtraceback']
                reprcrash = reportdict['longrepr']['reprcrash']

                unserialized_entries = []
                for entry in reprtraceback['reprentries']:
                    reprfuncargs, reprfileloc, reprlocals = None, None, None
                    if entry['reprfuncargs']:
                        reprfuncargs = ReprFuncArgs(**entry['reprfuncargs'])
                    if entry['reprfileloc']:
                        reprfileloc = ReprFileLocation(**entry['reprfileloc'])
                    if entry['reprlocals']:
                        reprlocals = ReprLocals(entry['reprlocals']['lines'])

                    reprentry = ReprEntry(lines=entry['lines'],
                                          reprfuncargs=reprfuncargs,
                                          reprlocals=reprlocals,
                                          filelocrepr=reprfileloc,
                                          style=entry['style'])
                    unserialized_entries.append(reprentry)
                reprtraceback['reprentries'] = unserialized_entries

                exception_info = ReprExceptionInfo(
                    reprtraceback=ReprTraceback(**reprtraceback),
                    reprcrash=ReprFileLocation(**reprcrash),
                )

                for section in reportdict['longrepr']['sections']:
                    exception_info.addsection(*section)
                reportdict['longrepr'] = exception_info
        return reportdict
Пример #6
0
def _report_kwargs_from_json(reportdict: Dict[str, Any]) -> Dict[str, Any]:
    """Return **kwargs that can be used to construct a TestReport or
    CollectReport instance.

    This was originally the serialize_report() function from xdist (ca03269).
    """
    def deserialize_repr_entry(entry_data):
        data = entry_data["data"]
        entry_type = entry_data["type"]
        if entry_type == "ReprEntry":
            reprfuncargs = None
            reprfileloc = None
            reprlocals = None
            if data["reprfuncargs"]:
                reprfuncargs = ReprFuncArgs(**data["reprfuncargs"])
            if data["reprfileloc"]:
                reprfileloc = ReprFileLocation(**data["reprfileloc"])
            if data["reprlocals"]:
                reprlocals = ReprLocals(data["reprlocals"]["lines"])

            reprentry: Union[ReprEntry, ReprEntryNative] = ReprEntry(
                lines=data["lines"],
                reprfuncargs=reprfuncargs,
                reprlocals=reprlocals,
                reprfileloc=reprfileloc,
                style=data["style"],
            )
        elif entry_type == "ReprEntryNative":
            reprentry = ReprEntryNative(data["lines"])
        else:
            _report_unserialization_failure(entry_type, TestReport, reportdict)
        return reprentry

    def deserialize_repr_traceback(repr_traceback_dict):
        repr_traceback_dict["reprentries"] = [
            deserialize_repr_entry(x)
            for x in repr_traceback_dict["reprentries"]
        ]
        return ReprTraceback(**repr_traceback_dict)

    def deserialize_repr_crash(repr_crash_dict: Optional[Dict[str, Any]]):
        if repr_crash_dict is not None:
            return ReprFileLocation(**repr_crash_dict)
        else:
            return None

    if (reportdict["longrepr"] and "reprcrash" in reportdict["longrepr"]
            and "reprtraceback" in reportdict["longrepr"]):

        reprtraceback = deserialize_repr_traceback(
            reportdict["longrepr"]["reprtraceback"])
        reprcrash = deserialize_repr_crash(reportdict["longrepr"]["reprcrash"])
        if reportdict["longrepr"]["chain"]:
            chain = []
            for repr_traceback_data, repr_crash_data, description in reportdict[
                    "longrepr"]["chain"]:
                chain.append((
                    deserialize_repr_traceback(repr_traceback_data),
                    deserialize_repr_crash(repr_crash_data),
                    description,
                ))
            exception_info: Union[ExceptionChainRepr,
                                  ReprExceptionInfo] = ExceptionChainRepr(
                                      chain)
        else:
            exception_info = ReprExceptionInfo(reprtraceback, reprcrash)

        for section in reportdict["longrepr"]["sections"]:
            exception_info.addsection(*section)
        reportdict["longrepr"] = exception_info

    return reportdict