本文整理汇总了Python中traceback.FrameSummary方法的典型用法代码示例。如果您正苦于以下问题:Python traceback.FrameSummary方法的具体用法?Python traceback.FrameSummary怎么用?Python traceback.FrameSummary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类traceback
的用法示例。
在下文中一共展示了traceback.FrameSummary方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: format_exception
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import FrameSummary [as 别名]
def format_exception(
exp: BaseException, tb: Optional[List[traceback.FrameSummary]] = None
) -> str:
"""Formats an exception traceback as a string, similar to the Python interpreter."""
if tb is None:
tb = traceback.extract_tb(exp.__traceback__)
# Replace absolute paths with relative paths
cwd = os.getcwd()
for frame in tb:
if cwd in frame.filename:
frame.filename = os.path.relpath(frame.filename)
stack = "".join(traceback.format_list(tb))
msg = str(exp)
if msg:
msg = ": " + msg
return f"Traceback (most recent call last):\n{stack}{type(exp).__name__}{msg}"
示例2: __init__
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import FrameSummary [as 别名]
def __init__(self, thread, calling_filename, calling_line_number, call_stack):
self.thread = thread
self.file_name = calling_filename
self.line_number = calling_line_number
self.call_stack: List[traceback.FrameSummary] = call_stack
self.time = time.time()
示例3: getTextFromFile
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import FrameSummary [as 别名]
def getTextFromFile(block_id: str, stack_pos: traceback.FrameSummary):
""" get the text which corresponds to the block_id (e.g. which figure) at the given position sepcified by stack_pos. """
block_id = lineToId(block_id)
block = None
if not stack_pos.filename.endswith('.py') and not stack_pos.filename.startswith("<ipython-input-"):
raise RuntimeError("pylustrator must used in a python file (*.py) or a jupyter notebook; not a shell session.")
with open(stack_pos.filename, 'r', encoding="utf-8") as fp1:
for lineno, line in enumerate(fp1, start=1):
# if we are currently reading a pylustrator block
if block is not None:
# add the line to the block
block.add(line)
# and see if we have found the end
if line.strip().startswith("#% end:"):
block.end()
# if there is a new pylustrator block
elif line.strip().startswith("#% start:"):
block = Block(line)
# if we are currently reading a block, continue with the next line
if block is not None and not block.finished:
continue
if block is not None and block.finished:
if block.id == block_id:
return block
block = None
return []
示例4: test_basics
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import FrameSummary [as 别名]
def test_basics(self):
linecache.clearcache()
linecache.lazycache("f", globals())
f = traceback.FrameSummary("f", 1, "dummy")
self.assertEqual(f,
("f", 1, "dummy", '"""Test cases for traceback module"""'))
self.assertEqual(tuple(f),
("f", 1, "dummy", '"""Test cases for traceback module"""'))
self.assertEqual(f, traceback.FrameSummary("f", 1, "dummy"))
self.assertEqual(f, tuple(f))
# Since tuple.__eq__ doesn't support FrameSummary, the equality
# operator fallbacks to FrameSummary.__eq__.
self.assertEqual(tuple(f), f)
self.assertIsNone(f.locals)
示例5: test_lazy_lines
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import FrameSummary [as 别名]
def test_lazy_lines(self):
linecache.clearcache()
f = traceback.FrameSummary("f", 1, "dummy", lookup_line=False)
self.assertEqual(None, f._line)
linecache.lazycache("f", globals())
self.assertEqual(
'"""Test cases for traceback module"""',
f.line)
示例6: test_explicit_line
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import FrameSummary [as 别名]
def test_explicit_line(self):
f = traceback.FrameSummary("f", 1, "dummy", line="line")
self.assertEqual("line", f.line)