Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_sys_settrace.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 67be12ab8948 |
| children | 8c2635afbfe1 |
| rev | line source |
|---|---|
|
63269
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
1 # Testing the line trace facility. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
2 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
3 from test import test_support |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
4 import unittest |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
5 import sys |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
6 import difflib |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
7 import gc |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
8 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
9 # A very basic example. If this fails, we're in deep trouble. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
10 def basic(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
11 return 1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
12 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
13 basic.events = [(0, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
14 (1, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
15 (1, 'return')] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
16 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
17 # Many of the tests below are tricky because they involve pass statements. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
18 # If there is implicit control flow around a pass statement (in an except |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
19 # clause or else caluse) under what conditions do you set a line number |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
20 # following that clause? |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
21 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
22 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
23 # The entire "while 0:" statement is optimized away. No code |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
24 # exists for it, so the line numbers skip directly from "del x" |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
25 # to "x = 1". |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
26 def arigo_example(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
27 x = 1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
28 del x |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
29 while 0: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
30 pass |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
31 x = 1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
32 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
33 arigo_example.events = [(0, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
34 (1, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
35 (2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
36 (5, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
37 (5, 'return')] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
38 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
39 # check that lines consisting of just one instruction get traced: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
40 def one_instr_line(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
41 x = 1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
42 del x |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
43 x = 1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
44 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
45 one_instr_line.events = [(0, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
46 (1, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
47 (2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
48 (3, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
49 (3, 'return')] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
50 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
51 def no_pop_tops(): # 0 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
52 x = 1 # 1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
53 for a in range(2): # 2 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
54 if a: # 3 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
55 x = 1 # 4 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
56 else: # 5 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
57 x = 1 # 6 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
58 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
59 no_pop_tops.events = [(0, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
60 (1, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
61 (2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
62 (3, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
63 (6, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
64 (2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
65 (3, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
66 (4, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
67 (2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
68 (2, 'return')] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
69 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
70 def no_pop_blocks(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
71 y = 1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
72 while not y: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
73 bla |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
74 x = 1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
75 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
76 no_pop_blocks.events = [(0, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
77 (1, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
78 (2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
79 (4, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
80 (4, 'return')] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
81 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
82 def called(): # line -3 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
83 x = 1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
84 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
85 def call(): # line 0 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
86 called() |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
87 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
88 call.events = [(0, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
89 (1, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
90 (-3, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
91 (-2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
92 (-2, 'return'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
93 (1, 'return')] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
94 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
95 def raises(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
96 raise Exception |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
97 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
98 def test_raise(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
99 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
100 raises() |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
101 except Exception, exc: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
102 x = 1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
103 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
104 test_raise.events = [(0, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
105 (1, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
106 (2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
107 (-3, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
108 (-2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
109 (-2, 'exception'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
110 (-2, 'return'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
111 (2, 'exception'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
112 (3, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
113 (4, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
114 (4, 'return')] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
115 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
116 def _settrace_and_return(tracefunc): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
117 sys.settrace(tracefunc) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
118 sys._getframe().f_back.f_trace = tracefunc |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
119 def settrace_and_return(tracefunc): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
120 _settrace_and_return(tracefunc) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
121 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
122 settrace_and_return.events = [(1, 'return')] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
123 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
124 def _settrace_and_raise(tracefunc): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
125 sys.settrace(tracefunc) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
126 sys._getframe().f_back.f_trace = tracefunc |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
127 raise RuntimeError |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
128 def settrace_and_raise(tracefunc): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
129 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
130 _settrace_and_raise(tracefunc) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
131 except RuntimeError, exc: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
132 pass |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
133 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
134 settrace_and_raise.events = [(2, 'exception'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
135 (3, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
136 (4, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
137 (4, 'return')] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
138 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
139 # implicit return example |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
140 # This test is interesting because of the else: pass |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
141 # part of the code. The code generate for the true |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
142 # part of the if contains a jump past the else branch. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
143 # The compiler then generates an implicit "return None" |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
144 # Internally, the compiler visits the pass statement |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
145 # and stores its line number for use on the next instruction. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
146 # The next instruction is the implicit return None. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
147 def ireturn_example(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
148 a = 5 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
149 b = 5 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
150 if a == b: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
151 b = a+1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
152 else: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
153 pass |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
154 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
155 ireturn_example.events = [(0, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
156 (1, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
157 (2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
158 (3, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
159 (4, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
160 (6, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
161 (6, 'return')] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
162 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
163 # Tight loop with while(1) example (SF #765624) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
164 def tightloop_example(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
165 items = range(0, 3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
166 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
167 i = 0 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
168 while 1: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
169 b = items[i]; i+=1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
170 except IndexError: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
171 pass |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
172 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
173 tightloop_example.events = [(0, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
174 (1, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
175 (2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
176 (3, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
177 (4, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
178 (5, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
179 (5, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
180 (5, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
181 (5, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
182 (5, 'exception'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
183 (6, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
184 (7, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
185 (7, 'return')] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
186 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
187 def tighterloop_example(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
188 items = range(1, 4) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
189 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
190 i = 0 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
191 while 1: i = items[i] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
192 except IndexError: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
193 pass |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
194 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
195 tighterloop_example.events = [(0, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
196 (1, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
197 (2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
198 (3, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
199 (4, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
200 (4, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
201 (4, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
202 (4, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
203 (4, 'exception'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
204 (5, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
205 (6, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
206 (6, 'return')] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
207 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
208 def generator_function(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
209 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
210 yield True |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
211 "continued" |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
212 finally: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
213 "finally" |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
214 def generator_example(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
215 # any() will leave the generator before its end |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
216 x = any(generator_function()) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
217 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
218 # the following lines were not traced |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
219 for x in range(10): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
220 y = x |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
221 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
222 generator_example.events = ([(0, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
223 (2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
224 (-6, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
225 (-5, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
226 (-4, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
227 (-4, 'return'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
228 (-4, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
229 (-4, 'exception'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
230 (-1, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
231 (-1, 'return')] + |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
232 [(5, 'line'), (6, 'line')] * 10 + |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
233 [(5, 'line'), (5, 'return')]) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
234 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
235 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
236 class Tracer: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
237 def __init__(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
238 self.events = [] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
239 def trace(self, frame, event, arg): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
240 self.events.append((frame.f_lineno, event)) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
241 return self.trace |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
242 def traceWithGenexp(self, frame, event, arg): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
243 (o for o in [1]) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
244 self.events.append((frame.f_lineno, event)) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
245 return self.trace |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
246 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
247 class TraceTestCase(unittest.TestCase): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
248 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
249 # Disable gc collection when tracing, otherwise the |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
250 # deallocators may be traced as well. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
251 def setUp(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
252 self.using_gc = gc.isenabled() |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
253 gc.disable() |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
254 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
255 def tearDown(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
256 if self.using_gc: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
257 gc.enable() |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
258 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
259 def compare_events(self, line_offset, events, expected_events): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
260 events = [(l - line_offset, e) for (l, e) in events] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
261 if events != expected_events: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
262 self.fail( |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
263 "events did not match expectation:\n" + |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
264 "\n".join(difflib.ndiff([str(x) for x in expected_events], |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
265 [str(x) for x in events]))) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
266 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
267 def run_and_compare(self, func, events): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
268 tracer = Tracer() |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
269 sys.settrace(tracer.trace) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
270 func() |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
271 sys.settrace(None) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
272 self.compare_events(func.func_code.co_firstlineno, |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
273 tracer.events, events) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
274 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
275 def run_test(self, func): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
276 self.run_and_compare(func, func.events) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
277 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
278 def run_test2(self, func): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
279 tracer = Tracer() |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
280 func(tracer.trace) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
281 sys.settrace(None) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
282 self.compare_events(func.func_code.co_firstlineno, |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
283 tracer.events, func.events) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
284 |
|
72707
16c4137a413c
Enable the only tests for sys.gettrace
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
63269
diff
changeset
|
285 def test_set_and_retrieve_none(self): |
|
63269
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
286 sys.settrace(None) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
287 assert sys.gettrace() is None |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
288 |
|
72707
16c4137a413c
Enable the only tests for sys.gettrace
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
63269
diff
changeset
|
289 def test_set_and_retrieve_func(self): |
|
63269
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
290 def fn(*args): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
291 pass |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
292 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
293 sys.settrace(fn) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
294 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
295 assert sys.gettrace() is fn |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
296 finally: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
297 sys.settrace(None) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
298 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
299 def test_01_basic(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
300 self.run_test(basic) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
301 def test_02_arigo(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
302 self.run_test(arigo_example) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
303 def test_03_one_instr(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
304 self.run_test(one_instr_line) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
305 def test_04_no_pop_blocks(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
306 self.run_test(no_pop_blocks) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
307 def test_05_no_pop_tops(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
308 self.run_test(no_pop_tops) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
309 def test_06_call(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
310 self.run_test(call) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
311 def test_07_raise(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
312 self.run_test(test_raise) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
313 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
314 def test_08_settrace_and_return(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
315 self.run_test2(settrace_and_return) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
316 def test_09_settrace_and_raise(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
317 self.run_test2(settrace_and_raise) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
318 def test_10_ireturn(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
319 self.run_test(ireturn_example) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
320 def test_11_tightloop(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
321 self.run_test(tightloop_example) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
322 def test_12_tighterloop(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
323 self.run_test(tighterloop_example) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
324 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
325 def test_13_genexp(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
326 self.run_test(generator_example) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
327 # issue1265: if the trace function contains a generator, |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
328 # and if the traced function contains another generator |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
329 # that is not completely exhausted, the trace stopped. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
330 # Worse: the 'finally' clause was not invoked. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
331 tracer = Tracer() |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
332 sys.settrace(tracer.traceWithGenexp) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
333 generator_example() |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
334 sys.settrace(None) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
335 self.compare_events(generator_example.__code__.co_firstlineno, |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
336 tracer.events, generator_example.events) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
337 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
338 def test_14_onliner_if(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
339 def onliners(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
340 if True: False |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
341 else: True |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
342 return 0 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
343 self.run_and_compare( |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
344 onliners, |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
345 [(0, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
346 (1, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
347 (3, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
348 (3, 'return')]) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
349 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
350 def test_15_loops(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
351 # issue1750076: "while" expression is skipped by debugger |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
352 def for_example(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
353 for x in range(2): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
354 pass |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
355 self.run_and_compare( |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
356 for_example, |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
357 [(0, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
358 (1, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
359 (2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
360 (1, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
361 (2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
362 (1, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
363 (1, 'return')]) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
364 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
365 def while_example(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
366 # While expression should be traced on every loop |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
367 x = 2 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
368 while x > 0: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
369 x -= 1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
370 self.run_and_compare( |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
371 while_example, |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
372 [(0, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
373 (2, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
374 (3, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
375 (4, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
376 (3, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
377 (4, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
378 (3, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
379 (3, 'return')]) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
380 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
381 def test_16_blank_lines(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
382 exec("def f():\n" + "\n" * 256 + " pass") |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
383 self.run_and_compare( |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
384 f, |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
385 [(0, 'call'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
386 (257, 'line'), |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
387 (257, 'return')]) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
388 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
389 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
390 class RaisingTraceFuncTestCase(unittest.TestCase): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
391 def trace(self, frame, event, arg): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
392 """A trace function that raises an exception in response to a |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
393 specific trace event.""" |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
394 if event == self.raiseOnEvent: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
395 raise ValueError # just something that isn't RuntimeError |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
396 else: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
397 return self.trace |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
398 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
399 def f(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
400 """The function to trace; raises an exception if that's the case |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
401 we're testing, so that the 'exception' trace event fires.""" |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
402 if self.raiseOnEvent == 'exception': |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
403 x = 0 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
404 y = 1 // x |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
405 else: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
406 return 1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
407 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
408 def run_test_for_event(self, event): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
409 """Tests that an exception raised in response to the given event is |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
410 handled OK.""" |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
411 self.raiseOnEvent = event |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
412 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
413 for i in xrange(sys.getrecursionlimit() + 1): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
414 sys.settrace(self.trace) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
415 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
416 self.f() |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
417 except ValueError: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
418 pass |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
419 else: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
420 self.fail("exception not thrown!") |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
421 except RuntimeError: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
422 self.fail("recursion counter not reset") |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
423 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
424 # Test the handling of exceptions raised by each kind of trace event. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
425 def test_call(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
426 self.run_test_for_event('call') |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
427 def test_line(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
428 self.run_test_for_event('line') |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
429 def test_return(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
430 self.run_test_for_event('return') |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
431 def test_exception(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
432 self.run_test_for_event('exception') |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
433 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
434 def test_trash_stack(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
435 def f(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
436 for i in range(5): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
437 print i # line tracing will raise an exception at this line |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
438 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
439 def g(frame, why, extra): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
440 if (why == 'line' and |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
441 frame.f_lineno == f.func_code.co_firstlineno + 2): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
442 raise RuntimeError, "i am crashing" |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
443 return g |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
444 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
445 sys.settrace(g) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
446 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
447 f() |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
448 except RuntimeError: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
449 # the test is really that this doesn't segfault: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
450 import gc |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
451 gc.collect() |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
452 else: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
453 self.fail("exception not propagated") |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
454 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
455 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
456 # 'Jump' tests: assigning to frame.f_lineno within a trace function |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
457 # moves the execution position - it's how debuggers implement a Jump |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
458 # command (aka. "Set next statement"). |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
459 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
460 class JumpTracer: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
461 """Defines a trace function that jumps from one place to another, |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
462 with the source and destination lines of the jump being defined by |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
463 the 'jump' property of the function under test.""" |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
464 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
465 def __init__(self, function): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
466 self.function = function |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
467 self.jumpFrom = function.jump[0] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
468 self.jumpTo = function.jump[1] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
469 self.done = False |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
470 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
471 def trace(self, frame, event, arg): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
472 if not self.done and frame.f_code == self.function.func_code: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
473 firstLine = frame.f_code.co_firstlineno |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
474 if event == 'line' and frame.f_lineno == firstLine + self.jumpFrom: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
475 # Cope with non-integer self.jumpTo (because of |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
476 # no_jump_to_non_integers below). |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
477 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
478 frame.f_lineno = firstLine + self.jumpTo |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
479 except TypeError: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
480 frame.f_lineno = self.jumpTo |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
481 self.done = True |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
482 return self.trace |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
483 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
484 # The first set of 'jump' tests are for things that are allowed: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
485 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
486 def jump_simple_forwards(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
487 output.append(1) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
488 output.append(2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
489 output.append(3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
490 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
491 jump_simple_forwards.jump = (1, 3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
492 jump_simple_forwards.output = [3] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
493 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
494 def jump_simple_backwards(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
495 output.append(1) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
496 output.append(2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
497 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
498 jump_simple_backwards.jump = (2, 1) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
499 jump_simple_backwards.output = [1, 1, 2] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
500 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
501 def jump_out_of_block_forwards(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
502 for i in 1, 2: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
503 output.append(2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
504 for j in [3]: # Also tests jumping over a block |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
505 output.append(4) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
506 output.append(5) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
507 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
508 jump_out_of_block_forwards.jump = (3, 5) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
509 jump_out_of_block_forwards.output = [2, 5] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
510 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
511 def jump_out_of_block_backwards(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
512 output.append(1) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
513 for i in [1]: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
514 output.append(3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
515 for j in [2]: # Also tests jumping over a block |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
516 output.append(5) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
517 output.append(6) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
518 output.append(7) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
519 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
520 jump_out_of_block_backwards.jump = (6, 1) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
521 jump_out_of_block_backwards.output = [1, 3, 5, 1, 3, 5, 6, 7] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
522 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
523 def jump_to_codeless_line(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
524 output.append(1) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
525 # Jumping to this line should skip to the next one. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
526 output.append(3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
527 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
528 jump_to_codeless_line.jump = (1, 2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
529 jump_to_codeless_line.output = [3] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
530 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
531 def jump_to_same_line(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
532 output.append(1) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
533 output.append(2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
534 output.append(3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
535 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
536 jump_to_same_line.jump = (2, 2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
537 jump_to_same_line.output = [1, 2, 3] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
538 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
539 # Tests jumping within a finally block, and over one. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
540 def jump_in_nested_finally(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
541 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
542 output.append(2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
543 finally: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
544 output.append(4) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
545 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
546 output.append(6) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
547 finally: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
548 output.append(8) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
549 output.append(9) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
550 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
551 jump_in_nested_finally.jump = (4, 9) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
552 jump_in_nested_finally.output = [2, 9] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
553 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
554 # The second set of 'jump' tests are for things that are not allowed: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
555 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
556 def no_jump_too_far_forwards(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
557 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
558 output.append(2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
559 output.append(3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
560 except ValueError, e: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
561 output.append('after' in str(e)) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
562 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
563 no_jump_too_far_forwards.jump = (3, 6) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
564 no_jump_too_far_forwards.output = [2, True] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
565 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
566 def no_jump_too_far_backwards(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
567 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
568 output.append(2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
569 output.append(3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
570 except ValueError, e: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
571 output.append('before' in str(e)) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
572 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
573 no_jump_too_far_backwards.jump = (3, -1) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
574 no_jump_too_far_backwards.output = [2, True] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
575 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
576 # Test each kind of 'except' line. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
577 def no_jump_to_except_1(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
578 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
579 output.append(2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
580 except: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
581 e = sys.exc_info()[1] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
582 output.append('except' in str(e)) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
583 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
584 no_jump_to_except_1.jump = (2, 3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
585 no_jump_to_except_1.output = [True] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
586 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
587 def no_jump_to_except_2(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
588 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
589 output.append(2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
590 except ValueError: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
591 e = sys.exc_info()[1] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
592 output.append('except' in str(e)) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
593 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
594 no_jump_to_except_2.jump = (2, 3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
595 no_jump_to_except_2.output = [True] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
596 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
597 def no_jump_to_except_3(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
598 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
599 output.append(2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
600 except ValueError, e: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
601 output.append('except' in str(e)) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
602 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
603 no_jump_to_except_3.jump = (2, 3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
604 no_jump_to_except_3.output = [True] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
605 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
606 def no_jump_to_except_4(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
607 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
608 output.append(2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
609 except (ValueError, RuntimeError), e: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
610 output.append('except' in str(e)) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
611 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
612 no_jump_to_except_4.jump = (2, 3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
613 no_jump_to_except_4.output = [True] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
614 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
615 def no_jump_forwards_into_block(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
616 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
617 output.append(2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
618 for i in 1, 2: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
619 output.append(4) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
620 except ValueError, e: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
621 output.append('into' in str(e)) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
622 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
623 no_jump_forwards_into_block.jump = (2, 4) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
624 no_jump_forwards_into_block.output = [True] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
625 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
626 def no_jump_backwards_into_block(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
627 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
628 for i in 1, 2: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
629 output.append(3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
630 output.append(4) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
631 except ValueError, e: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
632 output.append('into' in str(e)) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
633 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
634 no_jump_backwards_into_block.jump = (4, 3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
635 no_jump_backwards_into_block.output = [3, 3, True] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
636 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
637 def no_jump_into_finally_block(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
638 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
639 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
640 output.append(3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
641 x = 1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
642 finally: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
643 output.append(6) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
644 except ValueError, e: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
645 output.append('finally' in str(e)) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
646 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
647 no_jump_into_finally_block.jump = (4, 6) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
648 no_jump_into_finally_block.output = [3, 6, True] # The 'finally' still runs |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
649 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
650 def no_jump_out_of_finally_block(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
651 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
652 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
653 output.append(3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
654 finally: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
655 output.append(5) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
656 output.append(6) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
657 except ValueError, e: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
658 output.append('finally' in str(e)) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
659 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
660 no_jump_out_of_finally_block.jump = (5, 1) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
661 no_jump_out_of_finally_block.output = [3, True] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
662 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
663 # This verifies the line-numbers-must-be-integers rule. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
664 def no_jump_to_non_integers(output): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
665 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
666 output.append(2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
667 except ValueError, e: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
668 output.append('integer' in str(e)) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
669 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
670 no_jump_to_non_integers.jump = (2, "Spam") |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
671 no_jump_to_non_integers.output = [True] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
672 |
|
76395
67be12ab8948
SETUP_WITH acts like SETUP_FINALLY for the purposes of setting f_lineno (closes #14612)
Benjamin Peterson <benjamin@python.org>
parents:
72707
diff
changeset
|
673 def jump_across_with(output): |
|
67be12ab8948
SETUP_WITH acts like SETUP_FINALLY for the purposes of setting f_lineno (closes #14612)
Benjamin Peterson <benjamin@python.org>
parents:
72707
diff
changeset
|
674 with open(test_support.TESTFN, "wb") as fp: |
|
67be12ab8948
SETUP_WITH acts like SETUP_FINALLY for the purposes of setting f_lineno (closes #14612)
Benjamin Peterson <benjamin@python.org>
parents:
72707
diff
changeset
|
675 pass |
|
67be12ab8948
SETUP_WITH acts like SETUP_FINALLY for the purposes of setting f_lineno (closes #14612)
Benjamin Peterson <benjamin@python.org>
parents:
72707
diff
changeset
|
676 with open(test_support.TESTFN, "wb") as fp: |
|
67be12ab8948
SETUP_WITH acts like SETUP_FINALLY for the purposes of setting f_lineno (closes #14612)
Benjamin Peterson <benjamin@python.org>
parents:
72707
diff
changeset
|
677 pass |
|
67be12ab8948
SETUP_WITH acts like SETUP_FINALLY for the purposes of setting f_lineno (closes #14612)
Benjamin Peterson <benjamin@python.org>
parents:
72707
diff
changeset
|
678 jump_across_with.jump = (1, 3) |
|
67be12ab8948
SETUP_WITH acts like SETUP_FINALLY for the purposes of setting f_lineno (closes #14612)
Benjamin Peterson <benjamin@python.org>
parents:
72707
diff
changeset
|
679 jump_across_with.output = [] |
|
67be12ab8948
SETUP_WITH acts like SETUP_FINALLY for the purposes of setting f_lineno (closes #14612)
Benjamin Peterson <benjamin@python.org>
parents:
72707
diff
changeset
|
680 |
|
63269
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
681 # This verifies that you can't set f_lineno via _getframe or similar |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
682 # trickery. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
683 def no_jump_without_trace_function(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
684 try: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
685 previous_frame = sys._getframe().f_back |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
686 previous_frame.f_lineno = previous_frame.f_lineno |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
687 except ValueError, e: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
688 # This is the exception we wanted; make sure the error message |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
689 # talks about trace functions. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
690 if 'trace' not in str(e): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
691 raise |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
692 else: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
693 # Something's wrong - the expected exception wasn't raised. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
694 raise RuntimeError, "Trace-function-less jump failed to fail" |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
695 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
696 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
697 class JumpTestCase(unittest.TestCase): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
698 def compare_jump_output(self, expected, received): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
699 if received != expected: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
700 self.fail( "Outputs don't match:\n" + |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
701 "Expected: " + repr(expected) + "\n" + |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
702 "Received: " + repr(received)) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
703 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
704 def run_test(self, func): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
705 tracer = JumpTracer(func) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
706 sys.settrace(tracer.trace) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
707 output = [] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
708 func(output) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
709 sys.settrace(None) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
710 self.compare_jump_output(func.output, output) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
711 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
712 def test_01_jump_simple_forwards(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
713 self.run_test(jump_simple_forwards) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
714 def test_02_jump_simple_backwards(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
715 self.run_test(jump_simple_backwards) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
716 def test_03_jump_out_of_block_forwards(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
717 self.run_test(jump_out_of_block_forwards) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
718 def test_04_jump_out_of_block_backwards(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
719 self.run_test(jump_out_of_block_backwards) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
720 def test_05_jump_to_codeless_line(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
721 self.run_test(jump_to_codeless_line) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
722 def test_06_jump_to_same_line(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
723 self.run_test(jump_to_same_line) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
724 def test_07_jump_in_nested_finally(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
725 self.run_test(jump_in_nested_finally) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
726 def test_08_no_jump_too_far_forwards(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
727 self.run_test(no_jump_too_far_forwards) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
728 def test_09_no_jump_too_far_backwards(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
729 self.run_test(no_jump_too_far_backwards) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
730 def test_10_no_jump_to_except_1(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
731 self.run_test(no_jump_to_except_1) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
732 def test_11_no_jump_to_except_2(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
733 self.run_test(no_jump_to_except_2) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
734 def test_12_no_jump_to_except_3(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
735 self.run_test(no_jump_to_except_3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
736 def test_13_no_jump_to_except_4(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
737 self.run_test(no_jump_to_except_4) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
738 def test_14_no_jump_forwards_into_block(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
739 self.run_test(no_jump_forwards_into_block) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
740 def test_15_no_jump_backwards_into_block(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
741 self.run_test(no_jump_backwards_into_block) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
742 def test_16_no_jump_into_finally_block(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
743 self.run_test(no_jump_into_finally_block) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
744 def test_17_no_jump_out_of_finally_block(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
745 self.run_test(no_jump_out_of_finally_block) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
746 def test_18_no_jump_to_non_integers(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
747 self.run_test(no_jump_to_non_integers) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
748 def test_19_no_jump_without_trace_function(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
749 no_jump_without_trace_function() |
|
76395
67be12ab8948
SETUP_WITH acts like SETUP_FINALLY for the purposes of setting f_lineno (closes #14612)
Benjamin Peterson <benjamin@python.org>
parents:
72707
diff
changeset
|
750 def test_jump_across_with(self): |
|
67be12ab8948
SETUP_WITH acts like SETUP_FINALLY for the purposes of setting f_lineno (closes #14612)
Benjamin Peterson <benjamin@python.org>
parents:
72707
diff
changeset
|
751 self.addCleanup(test_support.unlink, test_support.TESTFN) |
|
67be12ab8948
SETUP_WITH acts like SETUP_FINALLY for the purposes of setting f_lineno (closes #14612)
Benjamin Peterson <benjamin@python.org>
parents:
72707
diff
changeset
|
752 self.run_test(jump_across_with) |
|
63269
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
753 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
754 def test_20_large_function(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
755 d = {} |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
756 exec("""def f(output): # line 0 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
757 x = 0 # line 1 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
758 y = 1 # line 2 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
759 ''' # line 3 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
760 %s # lines 4-1004 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
761 ''' # line 1005 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
762 x += 1 # line 1006 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
763 output.append(x) # line 1007 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
764 return""" % ('\n' * 1000,), d) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
765 f = d['f'] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
766 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
767 f.jump = (2, 1007) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
768 f.output = [0] |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
769 self.run_test(f) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
770 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
771 def test_jump_to_firstlineno(self): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
772 # This tests that PDB can jump back to the first line in a |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
773 # file. See issue #1689458. It can only be triggered in a |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
774 # function call if the function is defined on a single line. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
775 code = compile(""" |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
776 # Comments don't count. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
777 output.append(2) # firstlineno is here. |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
778 output.append(3) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
779 output.append(4) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
780 """, "<fake module>", "exec") |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
781 class fake_function: |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
782 func_code = code |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
783 jump = (2, 0) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
784 tracer = JumpTracer(fake_function) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
785 sys.settrace(tracer.trace) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
786 namespace = {"output": []} |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
787 exec code in namespace |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
788 sys.settrace(None) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
789 self.compare_jump_output([2, 3, 2, 3, 4], namespace["output"]) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
790 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
791 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
792 def test_main(): |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
793 test_support.run_unittest( |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
794 TraceTestCase, |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
795 RaisingTraceFuncTestCase, |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
796 JumpTestCase |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
797 ) |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
798 |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
799 if __name__ == "__main__": |
|
ea3b535136e7
Fix merge of r83140 again.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
800 test_main() |
