File: test_traceback_jy.py

package info (click to toggle)
jython 2.5.3-16%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,772 kB
  • ctags: 106,434
  • sloc: python: 351,322; java: 216,349; xml: 1,584; sh: 330; perl: 114; ansic: 102; makefile: 45
file content (80 lines) | stat: -rw-r--r-- 2,236 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""Misc traceback tests

Made for Jython.
"""
import sys
import traceback
import unittest
from test import test_support

if test_support.is_jython:
    from java.awt import EventQueue
    from java.lang import Runnable

class TracebackTestCase(unittest.TestCase):

    def test_tb_across_threads(self):
        if not test_support.is_jython:
            return

        # http://bugs.jython.org/issue1533624
        class PyRunnable(Runnable):
            def run(self):
                raise TypeError('this is only a test')
        try:
            EventQueue.invokeAndWait(PyRunnable())
        except TypeError:
            self.assertEqual(tb_info(),
                             [('test_tb_across_threads',
                               'EventQueue.invokeAndWait(PyRunnable())'),
                              ('run',
                               "raise TypeError('this is only a test')")])
        else:
            self.fail('Expected TypeError')

    def test_reraise(self):
        def raiser():
            raise Exception(), None, tb
        try:
            # Jython previously added raiser's frame to the traceback
            raiser()
        except Exception:
            self.assertEqual(tb_info(),
                             [('test_reraise', 'raiser()'),
                              ('<module>', "raise Exception('foo')")])

        else:
            self.fail('Expected Exception')

    def test_extract_stack(self):
        # http://bugs.jython.org/issue437809
        traceback.extract_stack()

    def test_except_around_raising_call(self):
        """[ #452526 ] traceback lineno is the except line"""
        from test import except_in_raising_code
        try:
            except_in_raising_code.foo()
        except NameError:
            tb = sys.exc_info()[2]
            self.assertEquals(6, tb.tb_next.tb_lineno)
        else:
            self.fail("Should've raised a NameError")

try:
    raise Exception('foo')
except Exception:
    tb = sys.exc_info()[2]


def tb_info():
    # [2:] ignores filename/lineno
    return [info[2:] for info in traceback.extract_tb(sys.exc_info()[2])]


def test_main():
    test_support.run_unittest(TracebackTestCase)


if __name__ == '__main__':
    test_main()