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


Python FormattedExcinfo.repr_excinfo方法代码示例

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


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

示例1: test_repr_source_failing_fullsource

# 需要导入模块: from py._code.code import FormattedExcinfo [as 别名]
# 或者: from py._code.code.FormattedExcinfo import repr_excinfo [as 别名]
    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,代码行数:54,代码来源:test_excinfo.py

示例2: test_repr_source_not_existing

# 需要导入模块: from py._code.code import FormattedExcinfo [as 别名]
# 或者: from py._code.code.FormattedExcinfo import repr_excinfo [as 别名]
 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,代码行数:11,代码来源:test_excinfo.py

示例3: test_repr_traceback_and_excinfo

# 需要导入模块: from py._code.code import FormattedExcinfo [as 别名]
# 或者: from py._code.code.FormattedExcinfo import repr_excinfo [as 别名]
    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,代码行数:22,代码来源:test_excinfo.py


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