• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python code.FormattedExcinfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_traceback_short_no_source

    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,代码行数:26,代码来源:test_excinfo.py


示例2: test_repr_tracebackentry_lines

    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,代码行数:29,代码来源:test_excinfo.py


示例3: test_repr_local

 def test_repr_local(self):
     p = FormattedExcinfo(showlocals=True)
     loc = {'y': 5, 'z': 7, 'x': 3, '@x': 2, '__builtins__': {}}
     reprlocals = p.repr_locals(loc)
     assert reprlocals.lines
     assert reprlocals.lines[0] == '__builtins__ = <builtins>'
     assert reprlocals.lines[1] == 'x          = 3'
     assert reprlocals.lines[2] == 'y          = 5'
     assert reprlocals.lines[3] == 'z          = 7'
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:9,代码来源:test_excinfo.py


示例4: test_repr_source_not_existing

 def test_repr_source_not_existing(self):
     pr = FormattedExcinfo()
     co = compile("raise ValueError()", "", "exec")
     try:
         exec (co)
     except ValueError:
         excinfo = py.code.ExceptionInfo()
     repr = pr.repr_excinfo(excinfo)
     assert repr.reprtraceback.reprentries[1].lines[0] == ">   ???"
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:9,代码来源:test_excinfo.py


示例5: test_repr_source

 def test_repr_source(self):
     pr = FormattedExcinfo()
     source = py.code.Source("""
         def f(x):
             pass
     """).strip()
     pr.flow_marker = "|"
     lines = pr.get_source(source, 0)
     assert len(lines) == 2
     assert lines[0] == "|   def f(x):"
     assert lines[1] == "        pass"
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:11,代码来源:test_excinfo.py


示例6: test_repr_source_failing_fullsource

    def test_repr_source_failing_fullsource(self):
        pr = FormattedExcinfo()

        class FakeCode(object):
            class raw:
                co_filename = '?'
            path = '?'
            firstlineno = 5

            def fullsource(self):
                return None
            fullsource = property(fullsource)

        class FakeFrame(object):
            code = FakeCode()
            f_locals = {}
            f_globals = {}

        class FakeTracebackEntry(py.code.Traceback.Entry):
            def __init__(self, tb):
                self.lineno = 5+3

            @property
            def frame(self):
                return FakeFrame()

        class Traceback(py.code.Traceback):
            Entry = FakeTracebackEntry

        class FakeExcinfo(py.code.ExceptionInfo):
            typename = "Foo"
            def __init__(self):
                pass

            def exconly(self, tryshort):
                return "EXC"
            def errisinstance(self, cls):
                return False

        excinfo = FakeExcinfo()
        class FakeRawTB(object):
            tb_next = None
        tb = FakeRawTB()
        excinfo.traceback = Traceback(tb)

        fail = IOError()
        repr = pr.repr_excinfo(excinfo)
        assert repr.reprtraceback.reprentries[0].lines[0] == ">   ???"

        fail = py.error.ENOENT
        repr = pr.repr_excinfo(excinfo)
        assert repr.reprtraceback.reprentries[0].lines[0] == ">   ???"
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:52,代码来源:test_excinfo.py


示例7: test_repr_traceback_tbfilter

 def test_repr_traceback_tbfilter(self, importasmod):
     mod = importasmod("""
         def f(x):
             raise ValueError(x)
         def entry():
             f(0)
     """)
     excinfo = py.test.raises(ValueError, mod.entry)
     p = FormattedExcinfo(tbfilter=True)
     reprtb = p.repr_traceback(excinfo)
     assert len(reprtb.reprentries) == 2
     p = FormattedExcinfo(tbfilter=False)
     reprtb = p.repr_traceback(excinfo)
     assert len(reprtb.reprentries) == 3
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:14,代码来源:test_excinfo.py


示例8: test_repr_traceback_with_invalid_cwd

    def test_repr_traceback_with_invalid_cwd(self, importasmod, monkeypatch):
        mod = importasmod("""
            def f(x):
                raise ValueError(x)
            def entry():
                f(0)
        """)
        excinfo = py.test.raises(ValueError, mod.entry)

        p = FormattedExcinfo()
        def raiseos():
            raise OSError(2)
        monkeypatch.setattr(py.std.os, 'getcwd', raiseos)
        assert p._makepath(__file__) == __file__
        reprtb = p.repr_traceback(excinfo)
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:15,代码来源:test_excinfo.py


示例9: test_tb_entry_AssertionError

    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,代码行数:16,代码来源:test_excinfo.py


示例10: test_repr_traceback_recursion

    def test_repr_traceback_recursion(self, importasmod):
        mod = importasmod("""
            def rec2(x):
                return rec1(x+1)
            def rec1(x):
                return rec2(x-1)
            def entry():
                rec1(42)
        """)
        excinfo = py.test.raises(RuntimeError, mod.entry)

        for style in ("short", "long", "no"):
            p = FormattedExcinfo(style="short")
            reprtb = p.repr_traceback(excinfo)
            assert reprtb.extraline == "!!! Recursion detected (same locals & position)"
            assert str(reprtb)
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:16,代码来源:test_excinfo.py


示例11: test_repr_tracebackentry_no

    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,代码行数:16,代码来源:test_excinfo.py


示例12: test_repr_source_excinfo

 def test_repr_source_excinfo(self):
     """ check if indentation is right """
     pr = FormattedExcinfo()
     excinfo = self.excinfo_from_exec("""
             def f():
                 assert 0
             f()
     """)
     pr = FormattedExcinfo()
     source = pr._getentrysource(excinfo.traceback[-1])
     lines = pr.get_source(source, 1, excinfo)
     assert lines == [
         '    def f():',
         '>       assert 0',
         'E       assert 0'
     ]
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:16,代码来源:test_excinfo.py


示例13: test_repr_traceback_and_excinfo

    def test_repr_traceback_and_excinfo(self, importasmod):
        mod = importasmod("""
            def f(x):
                raise ValueError(x)
            def entry():
                f(0)
        """)
        excinfo = py.test.raises(ValueError, mod.entry)

        for style in ("long", "short"):
            p = FormattedExcinfo(style=style)
            reprtb = p.repr_traceback(excinfo)
            assert len(reprtb.reprentries) == 2
            assert reprtb.style == style
            assert not reprtb.extraline
            repr = p.repr_excinfo(excinfo)
            assert repr.reprtraceback
            assert len(repr.reprtraceback.reprentries) == len(reprtb.reprentries)
            assert repr.reprcrash.path.endswith("mod.py")
            assert repr.reprcrash.message == "ValueError: 0"
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:20,代码来源:test_excinfo.py


示例14: test_repr_tracebackentry_lines_var_kw_args

    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,代码行数:20,代码来源:test_excinfo.py


示例15: test_repr_tracebackentry_short

    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,代码行数:24,代码来源:test_excinfo.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python builtin.print_函数代码示例发布时间:2022-05-25
下一篇:
Python pxssh.pxssh函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap