def test_capture(): stack = backtrace.capture() assert isinstance(stack, list) assert len(stack) >= 1 for frame in stack: assert isinstance(frame, dict) assert set(frame.keys()) == {"file", "line", "function"} assert isinstance(frame["file"], str) assert isinstance(frame["line"], int) assert isinstance(frame["function"], str) assert stack[0]["file"] == format_py_filename(__file__)
def test_traceback_contains_file_line_function(): traceback = backtrace.capture() for frame in traceback: assert set(frame) == {"file", "line", "function"}
def test_traceback_contains_inner_frame_first(): traceback = backtrace.capture() # Consider removing the frame corresponding to the capture() call? # On Python 2, __file__ points to the compiled bytecode, not the source. assert traceback[0]["file"] == backtrace.__file__.replace(".pyc", ".py") assert traceback[1]["file"] == __file__.replace(".pyc", ".py")
def test_traceback_returns_correct_types(): traceback = backtrace.capture() for frame in traceback: assert isinstance(frame["file"], str) assert isinstance(frame["line"], int) assert isinstance(frame["function"], str)
def capture_backtrace(self): self.tag("stack", backtrace.capture())
def capture_recursive_bottom(limit): if limit <= 1: return backtrace.capture() else: return capture_recursive_bottom(limit - 1)