Пример #1
0
    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] == ">   ???"
Пример #2
0
    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] == ">   ???"
Пример #3
0
 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] == ">   ???"
Пример #4
0
 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] == ">   ???"
Пример #5
0
    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"
Пример #6
0
    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"