annotate Lib/test/test_sys_settrace.py @ 78069:a8aa77458e12 3.2

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