本文整理汇总了Python中traceback.StackSummary方法的典型用法代码示例。如果您正苦于以下问题:Python traceback.StackSummary方法的具体用法?Python traceback.StackSummary怎么用?Python traceback.StackSummary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类traceback
的用法示例。
在下文中一共展示了traceback.StackSummary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cause
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import StackSummary [as 别名]
def test_cause(self):
try:
try:
1/0
finally:
exc_info_context = sys.exc_info()
exc_context = traceback.TracebackException(*exc_info_context)
cause = Exception("cause")
raise Exception("uh oh") from cause
except Exception:
exc_info = sys.exc_info()
exc = traceback.TracebackException(*exc_info)
expected_stack = traceback.StackSummary.extract(
traceback.walk_tb(exc_info[2]))
exc_cause = traceback.TracebackException(Exception, cause, None)
self.assertEqual(exc_cause, exc.__cause__)
self.assertEqual(exc_context, exc.__context__)
self.assertEqual(True, exc.__suppress_context__)
self.assertEqual(expected_stack, exc.stack)
self.assertEqual(exc_info[0], exc.exc_type)
self.assertEqual(str(exc_info[1]), str(exc))
示例2: test_context
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import StackSummary [as 别名]
def test_context(self):
try:
try:
1/0
finally:
exc_info_context = sys.exc_info()
exc_context = traceback.TracebackException(*exc_info_context)
raise Exception("uh oh")
except Exception:
exc_info = sys.exc_info()
exc = traceback.TracebackException(*exc_info)
expected_stack = traceback.StackSummary.extract(
traceback.walk_tb(exc_info[2]))
self.assertEqual(None, exc.__cause__)
self.assertEqual(exc_context, exc.__context__)
self.assertEqual(False, exc.__suppress_context__)
self.assertEqual(expected_stack, exc.stack)
self.assertEqual(exc_info[0], exc.exc_type)
self.assertEqual(str(exc_info[1]), str(exc))
示例3: test_extract_stack
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import StackSummary [as 别名]
def test_extract_stack(self):
s = traceback.StackSummary.extract(traceback.walk_stack(None))
self.assertIsInstance(s, traceback.StackSummary)
示例4: test_extract_stack_limit
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import StackSummary [as 别名]
def test_extract_stack_limit(self):
s = traceback.StackSummary.extract(traceback.walk_stack(None), limit=5)
self.assertEqual(len(s), 5)
示例5: test_extract_stack_lookup_lines
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import StackSummary [as 别名]
def test_extract_stack_lookup_lines(self):
linecache.clearcache()
linecache.updatecache('/foo.py', globals())
c = test_code('/foo.py', 'method')
f = test_frame(c, None, None)
s = traceback.StackSummary.extract(iter([(f, 6)]), lookup_lines=True)
linecache.clearcache()
self.assertEqual(s[0].line, "import sys")
示例6: test_extract_stackup_deferred_lookup_lines
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import StackSummary [as 别名]
def test_extract_stackup_deferred_lookup_lines(self):
linecache.clearcache()
c = test_code('/foo.py', 'method')
f = test_frame(c, None, None)
s = traceback.StackSummary.extract(iter([(f, 6)]), lookup_lines=False)
self.assertEqual({}, linecache.cache)
linecache.updatecache('/foo.py', globals())
self.assertEqual(s[0].line, "import sys")
示例7: test_from_list
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import StackSummary [as 别名]
def test_from_list(self):
s = traceback.StackSummary.from_list([('foo.py', 1, 'fred', 'line')])
self.assertEqual(
[' File "foo.py", line 1, in fred\n line\n'],
s.format())
示例8: test_format_smoke
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import StackSummary [as 别名]
def test_format_smoke(self):
# For detailed tests see the format_list tests, which consume the same
# code.
s = traceback.StackSummary.from_list([('foo.py', 1, 'fred', 'line')])
self.assertEqual(
[' File "foo.py", line 1, in fred\n line\n'],
s.format())
示例9: test_locals
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import StackSummary [as 别名]
def test_locals(self):
linecache.updatecache('/foo.py', globals())
c = test_code('/foo.py', 'method')
f = test_frame(c, globals(), {'something': 1})
s = traceback.StackSummary.extract(iter([(f, 6)]), capture_locals=True)
self.assertEqual(s[0].locals, {'something': '1'})
示例10: test_no_locals
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import StackSummary [as 别名]
def test_no_locals(self):
linecache.updatecache('/foo.py', globals())
c = test_code('/foo.py', 'method')
f = test_frame(c, globals(), {'something': 1})
s = traceback.StackSummary.extract(iter([(f, 6)]))
self.assertEqual(s[0].locals, None)
示例11: test_format_locals
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import StackSummary [as 别名]
def test_format_locals(self):
def some_inner(k, v):
a = 1
b = 2
return traceback.StackSummary.extract(
traceback.walk_stack(None), capture_locals=True, limit=1)
s = some_inner(3, 4)
self.assertEqual(
[' File "%s", line %d, in some_inner\n'
' traceback.walk_stack(None), capture_locals=True, limit=1)\n'
' a = 1\n'
' b = 2\n'
' k = 3\n'
' v = 4\n' % (__file__, some_inner.__code__.co_firstlineno + 4)
], s.format())
示例12: test_smoke
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import StackSummary [as 别名]
def test_smoke(self):
try:
1/0
except Exception:
exc_info = sys.exc_info()
exc = traceback.TracebackException(*exc_info)
expected_stack = traceback.StackSummary.extract(
traceback.walk_tb(exc_info[2]))
self.assertEqual(None, exc.__cause__)
self.assertEqual(None, exc.__context__)
self.assertEqual(False, exc.__suppress_context__)
self.assertEqual(expected_stack, exc.stack)
self.assertEqual(exc_info[0], exc.exc_type)
self.assertEqual(str(exc_info[1]), str(exc))
示例13: test_limit
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import StackSummary [as 别名]
def test_limit(self):
def recurse(n):
if n:
recurse(n-1)
else:
1/0
try:
recurse(10)
except Exception:
exc_info = sys.exc_info()
exc = traceback.TracebackException(*exc_info, limit=5)
expected_stack = traceback.StackSummary.extract(
traceback.walk_tb(exc_info[2]), limit=5)
self.assertEqual(expected_stack, exc.stack)
示例14: test_sets_traceback
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import StackSummary [as 别名]
def test_sets_traceback(self, event_loop):
event_loop.set_debug(True)
task = context.task_factory(event_loop, dummy())
task.cancel()
assert isinstance(task._source_traceback, traceback.StackSummary)
示例15: exception_line_in_file
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import StackSummary [as 别名]
def exception_line_in_file(frames: traceback.StackSummary, filename: str) -> Optional[int]:
for frame in reversed(frames):
if samefile(frame.filename, filename):
return frame.lineno
return None