Commit 8bfe0f75 authored by Lucas Felix's avatar Lucas Felix
Browse files

Add __str__ to PrettyTraceback to test output without colors

parent 75c609cb
......@@ -96,7 +96,7 @@ class PrettyTraceback:
]
def __init__(self, exc_type, exc_value, tb):
self._timestamp = datetime.now()
self._datetime = datetime.now()
self._exc_type = exc_type
self._exc_value = exc_value
self._locals_capture_exc = ""
......@@ -124,20 +124,25 @@ class PrettyTraceback:
return True
return False
def __str__(self):
return "".join([t[-1] for t in self._format()])
def print_formatted(self, disable_blacklist=False):
header = [
(
"class:pygments.generic.heading",
self._timestamp.strftime("--- %d/%m/%Y %H:%M:%S ---\n"),
)
]
print_formatted_text(
self._format(disable_blacklist),
style=BlissRepl()._current_style,
file=sys.stderr,
)
def _format(self, disable_blacklist=False):
timestamp = self._datetime.strftime("%d/%m/%Y %H:%M:%S")
header = [("class:pygments.generic.heading", f"--- {timestamp} ---\n")]
if self._locals_capture_exc:
msg = (
"Can't display local variables along stack trace, error occured during recovery:\n"
f"{self._locals_capture_exc}\n\n"
)
header.append((Token.Comment.Preproc, indent(msg, "* ")))
msg = "Can't display local variables along stack trace, "
msg += "error occured during recovery:\n"
msg += self._locals_capture_exc + "\n"
header.append(("class:pygments.comment.preproc", indent(msg, "* ")))
# Stack trace formatting
stack = []
......@@ -182,10 +187,7 @@ class PrettyTraceback:
for arg in self._exc_value.args:
footer.append(("class:pygments.name.exception", str(arg) + "\n"))
fmt_text = FormattedText(header + stack + footer)
print_formatted_text(
fmt_text, style=BlissRepl()._current_style, file=sys.stderr
)
return FormattedText(header + stack + footer)
class ErrorReport(ErrorReportInterface):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment