コード例 #1
0
ファイル: test_excinfo.py プロジェクト: neurobcn/plexnet
    def test_repr_tracebackentry_lines(self):
        mod = self.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])
        print reprtb

        # 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
コード例 #2
0
    def test_repr_tracebackentry_lines(self):
        mod = self.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])
        print reprtb

        # 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
コード例 #3
0
    def test_repr_tracebackentry_lines(self):
        mod = self.importasmod(
            """
            def func1(m, x, y, z):
                raise ValueError("hello\\nworld")
        """
        )
        excinfo = py.test.raises(ValueError, mod.func1, "m" * 90, 5, 13, "z" * 120)
        excinfo.traceback = excinfo.traceback.filter()
        entry = excinfo.traceback[-1]
        p = FormattedExcinfo(funcargs=True)
        reprfuncargs = p.repr_args(entry)
        assert reprfuncargs.args[0] == ("m", repr("m" * 90))
        assert reprfuncargs.args[1] == ("x", "5")
        assert reprfuncargs.args[2] == ("y", "13")
        assert reprfuncargs.args[3] == ("z", repr("z" * 120))

        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] == "m = " + repr("m" * 90)
        assert tw.lines[1] == "x = 5, y = 13"
        assert tw.lines[2] == "z = " + repr("z" * 120)
コード例 #4
0
ファイル: test_excinfo.py プロジェクト: mickg10/DARLAB
    def test_repr_tracebackentry_no(self):
        mod = self.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:] 
コード例 #5
0
ファイル: test_excinfo.py プロジェクト: neurobcn/plexnet
    def test_repr_tracebackentry_no(self):
        mod = self.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:]
コード例 #6
0
ファイル: test_excinfo.py プロジェクト: mickg10/DARLAB
    def test_repr_tracebackentry_short(self):
        mod = self.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] == '  File "%s", line 5, in entry' % basename 
        assert lines[1] == '    func1()' 

        # test last entry 
        p = FormattedExcinfo(style="short")
        reprtb = p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
        lines = reprtb.lines
        assert lines[0] == '  File "%s", line 3, in func1' % basename 
        assert lines[1] == '    raise ValueError("hello")'
        assert lines[2] == 'E   ValueError: hello'
コード例 #7
0
ファイル: test_excinfo.py プロジェクト: neurobcn/plexnet
    def test_repr_tracebackentry_short(self):
        mod = self.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] == '  File "%s", line 5, in entry' % basename
        assert lines[1] == '    func1()'

        # test last entry
        p = FormattedExcinfo(style="short")
        reprtb = p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
        lines = reprtb.lines
        assert lines[0] == '  File "%s", line 3, in func1' % basename
        assert lines[1] == '    raise ValueError("hello")'
        assert lines[2] == 'E   ValueError: hello'
コード例 #8
0
ファイル: test_excinfo.py プロジェクト: mickg10/DARLAB
 def test_tb_entry_AssertionError(self):
     # probably this test is a bit redundant 
     # as py/magic/testing/test_assertion.py
     # already tests correctness of
     # assertion-reinterpretation  logic 
     mod = self.importasmod("""
         def somefunc():
             x = 1
             assert x == 2
     """)
     py.magic.invoke(assertion=True)
     try:
         excinfo = py.test.raises(AssertionError, mod.somefunc)
     finally:
         py.magic.revoke(assertion=True)
         
     p = FormattedExcinfo()
     reprentry = p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
     lines = reprentry.lines
     assert lines[-1] == "E       assert 1 == 2"
コード例 #9
0
ファイル: test_excinfo.py プロジェクト: neurobcn/plexnet
    def test_tb_entry_AssertionError(self):
        # probably this test is a bit redundant
        # as py/magic/testing/test_assertion.py
        # already tests correctness of
        # assertion-reinterpretation  logic
        mod = self.importasmod("""
            def somefunc():
                x = 1
                assert x == 2
        """)
        py.magic.invoke(assertion=True)
        try:
            excinfo = py.test.raises(AssertionError, mod.somefunc)
        finally:
            py.magic.revoke(assertion=True)

        p = FormattedExcinfo()
        reprentry = p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
        lines = reprentry.lines
        assert lines[-1] == "E       assert 1 == 2"
コード例 #10
0
ファイル: test_excinfo.py プロジェクト: neurobcn/plexnet
    def test_repr_tracebackentry_lines(self):
        mod = self.importasmod("""
            def func1(m, x, y, z):
                raise ValueError("hello\\nworld")
        """)
        excinfo = py.test.raises(ValueError, mod.func1, "m" * 90, 5, 13,
                                 "z" * 120)
        excinfo.traceback = excinfo.traceback.filter()
        entry = excinfo.traceback[-1]
        p = FormattedExcinfo(funcargs=True)
        reprfuncargs = p.repr_args(entry)
        assert reprfuncargs.args[0] == ('m', repr("m" * 90))
        assert reprfuncargs.args[1] == ('x', '5')
        assert reprfuncargs.args[2] == ('y', '13')
        assert reprfuncargs.args[3] == ('z', repr("z" * 120))

        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] == "m = " + repr('m' * 90)
        assert tw.lines[1] == "x = 5, y = 13"
        assert tw.lines[2] == "z = " + repr('z' * 120)