1- #!/usr/bin/env python3
1+ """
2+ Functional test of debugger "step" command.
3+ """
24import unittest
5+ from test .functional .fn_helper import compare_output , strarray_setup
6+
37import tracer
4- from fn_helper import strarray_setup , compare_output
58
69
710class TestStep (unittest .TestCase ):
@@ -11,51 +14,48 @@ def test_step_same_level(self):
1114 return
1215
1316 # See that we can step with parameter which is the same as 'step 1'
14- cmds = [' step' , ' continue' ]
17+ cmds = [" step" , " continue" ]
1518 d = strarray_setup (cmds )
1619 d .core .start ()
1720 ##############################
1821 x = 5 # NOQA
1922 y = 6 # NOQA
2023 ##############################
2124 d .core .stop ()
22- out = ['-- x = 5' ,
23- '-- y = 6\n ' ]
25+ out = ["-- x = 5" , "-- y = 6\n " ]
2426 compare_output (self , out , d , cmds )
2527 return
2628
27- @unittest .skip ("Need to fix" )
2829 def test_step_computed_valued (self ):
2930 # See that we can step with a computed count value
30- cmds = [' step 5-3' , ' continue' ]
31+ cmds = [" step 5-3" , " continue" ]
3132 d = strarray_setup (cmds )
3233 d .core .start ()
3334 ##############################
3435 x = 5
3536 y = 6
3637 z = 7
3738 ##############################
38- d .core .stop (options = {'remove' : True })
39- out = ['-- x = 5' ,
40- '-- z = 7' ]
41- compare_output (self , out , d , cmds )
39+ d .core .stop (options = {"remove" : True })
40+ out = ["-- x = 5" , "-- z = 7" ]
41+ compare_output (self , out , d )
4242
4343 # Test step>
44- cmds = [' step>' , ' continue' ]
44+ cmds = [" step>" , " continue" ]
4545 d = strarray_setup (cmds )
4646 d .core .start ()
4747 ##############################
4848 x = 5
4949
5050 def foo ():
5151 return
52+
5253 y = 6 # NOQA
5354 foo ()
5455 ##############################
55- d .core .stop (options = {'remove' : True })
56- out = ['-- x = 5' ,
57- '-> def foo():' ]
58- compare_output (self , out , d , cmds )
56+ d .core .stop (options = {"remove" : True })
57+ out = ["-- x = 5" , "-> def foo():" ]
58+ compare_output (self , out , d )
5959
6060 # # Test step!
6161 # cmds = ['step!', 'continue']
@@ -72,20 +72,21 @@ def foo():
7272 # d.core.stop(options={'remove': True})
7373 # out = ['-- x = 5',
7474 # '!! z = 1/0\n']
75- # compare_output(self, out, d, cmds )
75+ # compare_output(self, out, d)
7676
7777 # Test "step" with sets of events. Part 1
78- cmds = ['step call exception' ,
79- 'step call exception' , 'continue' ]
78+ cmds = ["step call exception" , "step call exception" , "continue" ]
8079 d = strarray_setup (cmds )
8180 d .core .start ()
8281 ##############################
8382 x = 5 # NOQA
8483 try :
84+
8585 def foo1 ():
8686 y = 2 # NOQA
8787 raise Exception
8888 return
89+
8990 foo1 ()
9091 except :
9192 pass
@@ -118,80 +119,94 @@ def foo1():
118119 # out = ['-- x = 5',
119120 # '-> def foo2():',
120121 # '!! raise Exception']
121- # compare_output(self, out, d, cmds )
122+ # compare_output(self, out, d)
122123
123124 return
124125
125- @unittest .skip ("Need to fix" )
126126 def test_step_between_fn (self ):
127-
128127 # Step into and out of a function
129128 def sqr (x ):
130129 return x * x
130+
131131 for cmds , out , eventset in (
132- (['step' , 'step' , 'continue' ],
133- ['-- x = sqr(4) # NOQA' ,
134- '-- return x * x' ,
135- '-- y = 5 # NOQA' ],
136- frozenset (('line' ,))),
137- (['step' , 'step' , 'step' , 'step' , 'continue' ],
138- ['-- d.core.start()' ,
139- '-- x = sqr(4) # NOQA' ,
140- '-> def sqr(x):' ,
141- '-- return x * x' ,
142- '<- return x * x' ],
143- tracer .ALL_EVENTS ), ):
132+ (
133+ ["step" , "step" , "continue" ],
134+ ["-- x = sqr(4) # NOQA" , "-- return x * x" , "-- y = 5 # NOQA" ],
135+ frozenset (("line" ,)),
136+ ),
137+ (
138+ ["step" , "step" , "step" , "step" , "continue" ],
139+ [
140+ "-- x = sqr(4) # NOQA" ,
141+ "-> def sqr(x):" ,
142+ "-- return x * x" ,
143+ "<- return x * x" ,
144+ "-- y = 5 # NOQA" ,
145+ ],
146+ tracer .ALL_EVENTS ,
147+ ),
148+ ):
144149 d = strarray_setup (cmds )
145- d .settings [' events' ] = eventset
150+ d .settings [" events" ] = eventset
146151 d .core .start ()
147152 ##############################
148- x = sqr (4 ) # NOQA
153+ x = sqr (4 ) # NOQA
149154 y = 5 # NOQA
150155 ##############################
151- d .core .stop (options = {' remove' : True })
152- compare_output (self , out , d , cmds )
156+ d .core .stop (options = {" remove" : True })
157+ compare_output (self , out , d )
153158 pass
154159 return
155160
156- @unittest .skip ("Need to fix" )
157161 def test_step_in_exception (self ):
158162 return
163+
159164 def boom (x ):
160- y = 0 / x # NOQA
165+ y = 0 / x # NOQA
161166 return
162167
163168 def bad (x ):
164169 boom (x )
165170 return x * x
166- cmds = ['step' , 'step' , 'step' , 'step' , 'step' , 'step' ,
167- 'step' , 'step' , 'step' , 'step' , 'continue' ]
171+
172+ cmds = [
173+ "step" ,
174+ "step" ,
175+ "step" ,
176+ "step" ,
177+ "step" ,
178+ "step" ,
179+ "step" ,
180+ "step" ,
181+ "step" ,
182+ "step" ,
183+ "continue" ,
184+ ]
168185 d = strarray_setup (cmds )
169186 try :
170187 d .core .start ()
171188 x = bad (0 )
172- self .assertTrue (False , ' should have raised an exception' )
189+ self .assertTrue (False , " should have raised an exception" )
173190 except ZeroDivisionError :
174- self .assertTrue (True , ' Got the exception' )
191+ self .assertTrue (True , " Got the exception" )
175192 finally :
176- d .core .stop (options = {' remove' : True })
193+ d .core .stop (options = {" remove" : True })
177194 pass
178195
179- out = ['-- x = bad(0) # NOQA' , # line event
180- '-> def bad(x):' , # call event
181- '-- boom(x)' , # line event
182- '-> def boom(x):' , # call event
183- '-- y = 0/x # NOQA' , # line event
184- '!! y = 0/x # NOQA' , # exception event
185- '<- y = 0/x # NOQA' , # return event
186- '!! boom(x)' , # exception event
187- '<- boom(x)' , # return event
188- '!! x = bad(0) # NOQA' , # exception event
189- '-- except ZeroDivisionError:' ]
190- compare_output (self , out , d , cmds )
196+ out = [
197+ "-- x = bad(0) # NOQA" , # line event
198+ "-> def bad(x):" , # call event
199+ "-- boom(x)" , # line event
200+ "-> def boom(x):" , # call event
201+ "-- y = 0/x # NOQA" , # line event
202+ "!! y = 0/x # NOQA" , # exception event
203+ "<- y = 0/x # NOQA" , # return event
204+ "!! boom(x)" , # exception event
205+ "<- boom(x)" , # return event
206+ "!! x = bad(0) # NOQA" , # exception event
207+ "-- except ZeroDivisionError:" ,
208+ ]
209+ compare_output (self , out , d )
191210 return
192211
193212 pass
194-
195- if __name__ == '__main__' :
196- unittest .main ()
197- pass
0 commit comments