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 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
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)
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
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
def value(self, name, what): from _pytest._code.code import (ReprEntry, ReprEntryNative, ReprExceptionInfo, ReprFileLocation, ReprFuncArgs, ReprLocals, ReprTraceback) if not isinstance(what, str): unserialized_entries = [] reprentry = None for entry_data in what.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) what.reprtraceback.reprentries = unserialized_entries return element_maker(self.name or name, self.namespace)(legalize_xml(unicodify(what)))