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