示例#1
0
    def render(self, io: Union[IO, Output], simple: bool = False) -> None:
        if simple:
            io.write_line("")
            io.write_line("<error>{}</error>".format(str(self._exception)))
            return

        return self._render_exception(io, self._exception)
示例#2
0
    def _render_line(
        self, io, line, new_line=False, indent=0
    ):  # type: (IO, str, bool, int) -> None
        if new_line:
            io.write_line("")

        io.write_line("{}{}".format(indent * " ", line))
示例#3
0
    def _render_line(self,
                     io: Union[IO, Output],
                     line: str,
                     new_line: bool = False,
                     indent: int = 2) -> None:
        if new_line:
            io.write_line("")

        io.write_line("{}{}".format(indent * " ", line))
示例#4
0
    def _render_traceback(self, io, tb):  # type: (IO, ...) -> None
        frames = []
        while tb:
            frames.append(self._format_traceback_frame(io, tb))

            tb = tb.tb_next

        io.write_line("<b>Traceback (most recent call last):</b>")
        io.write_line("".join(traceback.format_list(frames)))
示例#5
0
    def render(self, io, simple=False):  # type: (IO, bool) -> None
        if simple:
            io.write_line("<error>{}</error>".format(str(self._exception)))
            return

        if not PY36:
            return self._render_legacy(io)

        return self._render_exception(io, self._exception)
示例#6
0
    def _render_exception(self, io: Union[IO, Output],
                          exception: Exception) -> None:
        from crashtest.inspector import Inspector

        inspector = Inspector(exception)
        if not inspector.frames:
            return

        if inspector.has_previous_exception():
            self._render_exception(io, inspector.previous_exception)
            io.write_line("")
            io.write_line(
                "The following error occurred when trying to handle this error:"
            )
            io.write_line("")

        self._render_trace(io, inspector.frames)

        self._render_line(io,
                          "<error>{}</error>".format(inspector.exception_name),
                          True)
        io.write_line("")
        exception_message = (Formatter().format(
            inspector.exception_message).replace("\n", "\n  "))
        self._render_line(io, "<b>{}</b>".format(exception_message))

        current_frame = inspector.frames[-1]
        self._render_snippet(io, current_frame)

        self._render_solution(io, inspector)
示例#7
0
    def _render_legacy(self, io):
        if hasattr(self._exception, "__traceback__"):
            tb = self._exception.__traceback__
        else:
            tb = self._exc_info[2]

        title = "\n<error>{}</error>\n\n<b>{}</b>".format(
            self._exception.__class__.__name__, str(self._exception))

        io.write_line(title)

        if io.is_verbose():
            io.write_line("")
            self._render_traceback(io, tb)
示例#8
0
    def _render_exception(self, io, exception):
        from crashtest.inspector import Inspector

        inspector = Inspector(exception)
        if not inspector.frames:
            return

        self._render_trace(io, inspector.frames)

        self._render_line(io,
                          "<error>{}</error>".format(inspector.exception_name),
                          True)
        io.write_line("")
        exception_message = io.remove_format(
            inspector.exception_message).replace("\n", "\n  ")
        self._render_line(io, "<b>{}</b>".format(exception_message))

        current_frame = inspector.frames[-1]
        self._render_snippet(io, current_frame)

        self._render_solution(io, inspector)