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


Python FormattedExcinfo.repr_traceback_entry方法代码示例

本文整理汇总了Python中py._code.code.FormattedExcinfo.repr_traceback_entry方法的典型用法代码示例。如果您正苦于以下问题:Python FormattedExcinfo.repr_traceback_entry方法的具体用法?Python FormattedExcinfo.repr_traceback_entry怎么用?Python FormattedExcinfo.repr_traceback_entry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在py._code.code.FormattedExcinfo的用法示例。


在下文中一共展示了FormattedExcinfo.repr_traceback_entry方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_repr_tracebackentry_lines

# 需要导入模块: from py._code.code import FormattedExcinfo [as 别名]
# 或者: from py._code.code.FormattedExcinfo import repr_traceback_entry [as 别名]
    def test_repr_tracebackentry_lines(self, importasmod):
        mod = importasmod("""
            def func1():
                raise ValueError("hello\\nworld")
        """)
        excinfo = py.test.raises(ValueError, mod.func1)
        excinfo.traceback = excinfo.traceback.filter()
        p = FormattedExcinfo()
        reprtb = p.repr_traceback_entry(excinfo.traceback[-1])

        # test as intermittent entry
        lines = reprtb.lines
        assert lines[0] == '    def func1():'
        assert lines[1] == '>       raise ValueError("hello\\nworld")'

        # test as last entry
        p = FormattedExcinfo(showlocals=True)
        repr_entry = p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
        lines = repr_entry.lines
        assert lines[0] == '    def func1():'
        assert lines[1] == '>       raise ValueError("hello\\nworld")'
        assert lines[2] == 'E       ValueError: hello'
        assert lines[3] == 'E       world'
        assert not lines[4:]

        loc = repr_entry.reprlocals is not None
        loc = repr_entry.reprfileloc
        assert loc.path == mod.__file__
        assert loc.lineno == 3
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:31,代码来源:test_excinfo.py

示例2: test_traceback_short_no_source

# 需要导入模块: from py._code.code import FormattedExcinfo [as 别名]
# 或者: from py._code.code.FormattedExcinfo import repr_traceback_entry [as 别名]
    def test_traceback_short_no_source(self, importasmod, monkeypatch):
        mod = importasmod("""
            def func1():
                raise ValueError("hello")
            def entry():
                func1()
        """)
        try:
            mod.entry()
        except ValueError:
            excinfo = py.code.ExceptionInfo()
        from py._code.code import Code
        monkeypatch.setattr(Code, 'path', 'bogus')
        excinfo.traceback[0].frame.code.path = "bogus"
        p = FormattedExcinfo(style="short")
        reprtb = p.repr_traceback_entry(excinfo.traceback[-2])
        lines = reprtb.lines
        last_p = FormattedExcinfo(style="short")
        last_reprtb = last_p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
        last_lines = last_reprtb.lines
        monkeypatch.undo()
        basename = py.path.local(mod.__file__).basename
        assert lines[0] == '    func1()'

        assert last_lines[0] == '    raise ValueError("hello")'
        assert last_lines[1] == 'E   ValueError: hello'
开发者ID:Coder206,项目名称:servo,代码行数:28,代码来源:test_excinfo.py

示例3: test_repr_tracebackentry_no

# 需要导入模块: from py._code.code import FormattedExcinfo [as 别名]
# 或者: from py._code.code.FormattedExcinfo import repr_traceback_entry [as 别名]
    def test_repr_tracebackentry_no(self, importasmod):
        mod = importasmod("""
            def func1():
                raise ValueError("hello")
            def entry():
                func1()
        """)
        excinfo = py.test.raises(ValueError, mod.entry)
        p = FormattedExcinfo(style="no")
        p.repr_traceback_entry(excinfo.traceback[-2])

        p = FormattedExcinfo(style="no")
        reprentry = p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
        lines = reprentry.lines
        assert lines[0] == 'E   ValueError: hello'
        assert not lines[1:]
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:18,代码来源:test_excinfo.py

示例4: test_repr_tracebackentry_short

# 需要导入模块: from py._code.code import FormattedExcinfo [as 别名]
# 或者: from py._code.code.FormattedExcinfo import repr_traceback_entry [as 别名]
    def test_repr_tracebackentry_short(self, importasmod):
        mod = importasmod("""
            def func1():
                raise ValueError("hello")
            def entry():
                func1()
        """)
        excinfo = py.test.raises(ValueError, mod.entry)
        p = FormattedExcinfo(style="short")
        reprtb = p.repr_traceback_entry(excinfo.traceback[-2])
        lines = reprtb.lines
        basename = py.path.local(mod.__file__).basename
        assert lines[0] == '>       func1()'
        assert basename in str(reprtb.reprfileloc.path)
        assert reprtb.reprfileloc.lineno == 5

        # test last entry
        p = FormattedExcinfo(style="short")
        reprtb = p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
        lines = reprtb.lines
        assert lines[0] == '>       raise ValueError("hello")'
        assert lines[1] == 'E       ValueError: hello'
        assert basename in str(reprtb.reprfileloc.path)
        assert reprtb.reprfileloc.lineno == 3
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:26,代码来源:test_excinfo.py

示例5: test_tb_entry_AssertionError

# 需要导入模块: from py._code.code import FormattedExcinfo [as 别名]
# 或者: from py._code.code.FormattedExcinfo import repr_traceback_entry [as 别名]
    def test_tb_entry_AssertionError(self, importasmod):
        # probably this test is a bit redundant
        # as py/magic/testing/test_assertion.py
        # already tests correctness of
        # assertion-reinterpretation  logic
        mod = importasmod("""
            def somefunc():
                x = 1
                assert x == 2
        """)
        excinfo = py.test.raises(AssertionError, mod.somefunc)

        p = FormattedExcinfo()
        reprentry = p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
        lines = reprentry.lines
        assert lines[-1] == "E       assert 1 == 2"
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:18,代码来源:test_excinfo.py

示例6: test_repr_tracebackentry_lines_var_kw_args

# 需要导入模块: from py._code.code import FormattedExcinfo [as 别名]
# 或者: from py._code.code.FormattedExcinfo import repr_traceback_entry [as 别名]
    def test_repr_tracebackentry_lines_var_kw_args(self, importasmod):
        mod = importasmod("""
            def func1(x, *y, **z):
                raise ValueError("hello\\nworld")
        """)
        excinfo = py.test.raises(ValueError, mod.func1, 'a', 'b', c='d')
        excinfo.traceback = excinfo.traceback.filter()
        entry = excinfo.traceback[-1]
        p = FormattedExcinfo(funcargs=True)
        reprfuncargs = p.repr_args(entry)
        assert reprfuncargs.args[0] == ('x', repr('a'))
        assert reprfuncargs.args[1] == ('y', repr(('b',)))
        assert reprfuncargs.args[2] == ('z', repr({'c': 'd'}))

        p = FormattedExcinfo(funcargs=True)
        repr_entry = p.repr_traceback_entry(entry)
        assert repr_entry.reprfuncargs.args == reprfuncargs.args
        tw = TWMock()
        repr_entry.toterminal(tw)
        assert tw.lines[0] == "x = 'a', y = ('b',), z = {'c': 'd'}"
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:22,代码来源:test_excinfo.py


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