当前位置: 首页>>代码示例>>Python>>正文


Python traceback.StackSummary方法代码示例

本文整理汇总了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)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_traceback.py

示例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)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_traceback.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_traceback.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_traceback.py

示例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") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_traceback.py

示例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") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_traceback.py

示例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()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_traceback.py

示例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()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_traceback.py

示例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'}) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_traceback.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_traceback.py

示例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()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:test_traceback.py

示例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)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:16,代码来源:test_traceback.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:16,代码来源:test_traceback.py

示例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) 
开发者ID:Skyscanner,项目名称:aiotask-context,代码行数:8,代码来源:test_context.py

示例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 
开发者ID:pschanely,项目名称:CrossHair,代码行数:7,代码来源:core.py


注:本文中的traceback.StackSummary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。