##// END OF EJS Templates
Skip problemtic test on PyPy
Matthias Bussonnier -
Show More
@@ -1,563 +1,567 b''
1 """Tests for debugging machinery.
1 """Tests for debugging machinery.
2 """
2 """
3
3
4 # Copyright (c) IPython Development Team.
4 # Copyright (c) IPython Development Team.
5 # Distributed under the terms of the Modified BSD License.
5 # Distributed under the terms of the Modified BSD License.
6
6
7 import bdb
7 import bdb
8 import builtins
8 import builtins
9 import os
9 import os
10 import sys
10 import sys
11 import platform
11
12
12 from tempfile import NamedTemporaryFile
13 from tempfile import NamedTemporaryFile
13 from textwrap import dedent
14 from textwrap import dedent
14 from unittest.mock import patch
15 from unittest.mock import patch
15
16
16 from IPython.core import debugger
17 from IPython.core import debugger
17 from IPython.testing import IPYTHON_TESTING_TIMEOUT_SCALE
18 from IPython.testing import IPYTHON_TESTING_TIMEOUT_SCALE
18 from IPython.testing.decorators import skip_win32
19 from IPython.testing.decorators import skip_win32
20 import pytest
19
21
20 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
21 # Helper classes, from CPython's Pdb test suite
23 # Helper classes, from CPython's Pdb test suite
22 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
23
25
24 class _FakeInput(object):
26 class _FakeInput(object):
25 """
27 """
26 A fake input stream for pdb's interactive debugger. Whenever a
28 A fake input stream for pdb's interactive debugger. Whenever a
27 line is read, print it (to simulate the user typing it), and then
29 line is read, print it (to simulate the user typing it), and then
28 return it. The set of lines to return is specified in the
30 return it. The set of lines to return is specified in the
29 constructor; they should not have trailing newlines.
31 constructor; they should not have trailing newlines.
30 """
32 """
31 def __init__(self, lines):
33 def __init__(self, lines):
32 self.lines = iter(lines)
34 self.lines = iter(lines)
33
35
34 def readline(self):
36 def readline(self):
35 line = next(self.lines)
37 line = next(self.lines)
36 print(line)
38 print(line)
37 return line+'\n'
39 return line+'\n'
38
40
39 class PdbTestInput(object):
41 class PdbTestInput(object):
40 """Context manager that makes testing Pdb in doctests easier."""
42 """Context manager that makes testing Pdb in doctests easier."""
41
43
42 def __init__(self, input):
44 def __init__(self, input):
43 self.input = input
45 self.input = input
44
46
45 def __enter__(self):
47 def __enter__(self):
46 self.real_stdin = sys.stdin
48 self.real_stdin = sys.stdin
47 sys.stdin = _FakeInput(self.input)
49 sys.stdin = _FakeInput(self.input)
48
50
49 def __exit__(self, *exc):
51 def __exit__(self, *exc):
50 sys.stdin = self.real_stdin
52 sys.stdin = self.real_stdin
51
53
52 #-----------------------------------------------------------------------------
54 #-----------------------------------------------------------------------------
53 # Tests
55 # Tests
54 #-----------------------------------------------------------------------------
56 #-----------------------------------------------------------------------------
55
57
56 def test_ipdb_magics():
58 def test_ipdb_magics():
57 '''Test calling some IPython magics from ipdb.
59 '''Test calling some IPython magics from ipdb.
58
60
59 First, set up some test functions and classes which we can inspect.
61 First, set up some test functions and classes which we can inspect.
60
62
61 >>> class ExampleClass(object):
63 >>> class ExampleClass(object):
62 ... """Docstring for ExampleClass."""
64 ... """Docstring for ExampleClass."""
63 ... def __init__(self):
65 ... def __init__(self):
64 ... """Docstring for ExampleClass.__init__"""
66 ... """Docstring for ExampleClass.__init__"""
65 ... pass
67 ... pass
66 ... def __str__(self):
68 ... def __str__(self):
67 ... return "ExampleClass()"
69 ... return "ExampleClass()"
68
70
69 >>> def example_function(x, y, z="hello"):
71 >>> def example_function(x, y, z="hello"):
70 ... """Docstring for example_function."""
72 ... """Docstring for example_function."""
71 ... pass
73 ... pass
72
74
73 >>> old_trace = sys.gettrace()
75 >>> old_trace = sys.gettrace()
74
76
75 Create a function which triggers ipdb.
77 Create a function which triggers ipdb.
76
78
77 >>> def trigger_ipdb():
79 >>> def trigger_ipdb():
78 ... a = ExampleClass()
80 ... a = ExampleClass()
79 ... debugger.Pdb().set_trace()
81 ... debugger.Pdb().set_trace()
80
82
81 >>> with PdbTestInput([
83 >>> with PdbTestInput([
82 ... 'pdef example_function',
84 ... 'pdef example_function',
83 ... 'pdoc ExampleClass',
85 ... 'pdoc ExampleClass',
84 ... 'up',
86 ... 'up',
85 ... 'down',
87 ... 'down',
86 ... 'list',
88 ... 'list',
87 ... 'pinfo a',
89 ... 'pinfo a',
88 ... 'll',
90 ... 'll',
89 ... 'continue',
91 ... 'continue',
90 ... ]):
92 ... ]):
91 ... trigger_ipdb()
93 ... trigger_ipdb()
92 --Return--
94 --Return--
93 None
95 None
94 > <doctest ...>(3)trigger_ipdb()
96 > <doctest ...>(3)trigger_ipdb()
95 1 def trigger_ipdb():
97 1 def trigger_ipdb():
96 2 a = ExampleClass()
98 2 a = ExampleClass()
97 ----> 3 debugger.Pdb().set_trace()
99 ----> 3 debugger.Pdb().set_trace()
98 <BLANKLINE>
100 <BLANKLINE>
99 ipdb> pdef example_function
101 ipdb> pdef example_function
100 example_function(x, y, z='hello')
102 example_function(x, y, z='hello')
101 ipdb> pdoc ExampleClass
103 ipdb> pdoc ExampleClass
102 Class docstring:
104 Class docstring:
103 Docstring for ExampleClass.
105 Docstring for ExampleClass.
104 Init docstring:
106 Init docstring:
105 Docstring for ExampleClass.__init__
107 Docstring for ExampleClass.__init__
106 ipdb> up
108 ipdb> up
107 > <doctest ...>(11)<module>()
109 > <doctest ...>(11)<module>()
108 7 'pinfo a',
110 7 'pinfo a',
109 8 'll',
111 8 'll',
110 9 'continue',
112 9 'continue',
111 10 ]):
113 10 ]):
112 ---> 11 trigger_ipdb()
114 ---> 11 trigger_ipdb()
113 <BLANKLINE>
115 <BLANKLINE>
114 ipdb> down
116 ipdb> down
115 None
117 None
116 > <doctest ...>(3)trigger_ipdb()
118 > <doctest ...>(3)trigger_ipdb()
117 1 def trigger_ipdb():
119 1 def trigger_ipdb():
118 2 a = ExampleClass()
120 2 a = ExampleClass()
119 ----> 3 debugger.Pdb().set_trace()
121 ----> 3 debugger.Pdb().set_trace()
120 <BLANKLINE>
122 <BLANKLINE>
121 ipdb> list
123 ipdb> list
122 1 def trigger_ipdb():
124 1 def trigger_ipdb():
123 2 a = ExampleClass()
125 2 a = ExampleClass()
124 ----> 3 debugger.Pdb().set_trace()
126 ----> 3 debugger.Pdb().set_trace()
125 <BLANKLINE>
127 <BLANKLINE>
126 ipdb> pinfo a
128 ipdb> pinfo a
127 Type: ExampleClass
129 Type: ExampleClass
128 String form: ExampleClass()
130 String form: ExampleClass()
129 Namespace: Local...
131 Namespace: Local...
130 Docstring: Docstring for ExampleClass.
132 Docstring: Docstring for ExampleClass.
131 Init docstring: Docstring for ExampleClass.__init__
133 Init docstring: Docstring for ExampleClass.__init__
132 ipdb> ll
134 ipdb> ll
133 1 def trigger_ipdb():
135 1 def trigger_ipdb():
134 2 a = ExampleClass()
136 2 a = ExampleClass()
135 ----> 3 debugger.Pdb().set_trace()
137 ----> 3 debugger.Pdb().set_trace()
136 <BLANKLINE>
138 <BLANKLINE>
137 ipdb> continue
139 ipdb> continue
138
140
139 Restore previous trace function, e.g. for coverage.py
141 Restore previous trace function, e.g. for coverage.py
140
142
141 >>> sys.settrace(old_trace)
143 >>> sys.settrace(old_trace)
142 '''
144 '''
143
145
144 def test_ipdb_magics2():
146 def test_ipdb_magics2():
145 '''Test ipdb with a very short function.
147 '''Test ipdb with a very short function.
146
148
147 >>> old_trace = sys.gettrace()
149 >>> old_trace = sys.gettrace()
148
150
149 >>> def bar():
151 >>> def bar():
150 ... pass
152 ... pass
151
153
152 Run ipdb.
154 Run ipdb.
153
155
154 >>> with PdbTestInput([
156 >>> with PdbTestInput([
155 ... 'continue',
157 ... 'continue',
156 ... ]):
158 ... ]):
157 ... debugger.Pdb().runcall(bar)
159 ... debugger.Pdb().runcall(bar)
158 > <doctest ...>(2)bar()
160 > <doctest ...>(2)bar()
159 1 def bar():
161 1 def bar():
160 ----> 2 pass
162 ----> 2 pass
161 <BLANKLINE>
163 <BLANKLINE>
162 ipdb> continue
164 ipdb> continue
163
165
164 Restore previous trace function, e.g. for coverage.py
166 Restore previous trace function, e.g. for coverage.py
165
167
166 >>> sys.settrace(old_trace)
168 >>> sys.settrace(old_trace)
167 '''
169 '''
168
170
169 def can_quit():
171 def can_quit():
170 '''Test that quit work in ipydb
172 '''Test that quit work in ipydb
171
173
172 >>> old_trace = sys.gettrace()
174 >>> old_trace = sys.gettrace()
173
175
174 >>> def bar():
176 >>> def bar():
175 ... pass
177 ... pass
176
178
177 >>> with PdbTestInput([
179 >>> with PdbTestInput([
178 ... 'quit',
180 ... 'quit',
179 ... ]):
181 ... ]):
180 ... debugger.Pdb().runcall(bar)
182 ... debugger.Pdb().runcall(bar)
181 > <doctest ...>(2)bar()
183 > <doctest ...>(2)bar()
182 1 def bar():
184 1 def bar():
183 ----> 2 pass
185 ----> 2 pass
184 <BLANKLINE>
186 <BLANKLINE>
185 ipdb> quit
187 ipdb> quit
186
188
187 Restore previous trace function, e.g. for coverage.py
189 Restore previous trace function, e.g. for coverage.py
188
190
189 >>> sys.settrace(old_trace)
191 >>> sys.settrace(old_trace)
190 '''
192 '''
191
193
192
194
193 def can_exit():
195 def can_exit():
194 '''Test that quit work in ipydb
196 '''Test that quit work in ipydb
195
197
196 >>> old_trace = sys.gettrace()
198 >>> old_trace = sys.gettrace()
197
199
198 >>> def bar():
200 >>> def bar():
199 ... pass
201 ... pass
200
202
201 >>> with PdbTestInput([
203 >>> with PdbTestInput([
202 ... 'exit',
204 ... 'exit',
203 ... ]):
205 ... ]):
204 ... debugger.Pdb().runcall(bar)
206 ... debugger.Pdb().runcall(bar)
205 > <doctest ...>(2)bar()
207 > <doctest ...>(2)bar()
206 1 def bar():
208 1 def bar():
207 ----> 2 pass
209 ----> 2 pass
208 <BLANKLINE>
210 <BLANKLINE>
209 ipdb> exit
211 ipdb> exit
210
212
211 Restore previous trace function, e.g. for coverage.py
213 Restore previous trace function, e.g. for coverage.py
212
214
213 >>> sys.settrace(old_trace)
215 >>> sys.settrace(old_trace)
214 '''
216 '''
215
217
216
218
217 def test_interruptible_core_debugger():
219 def test_interruptible_core_debugger():
218 """The debugger can be interrupted.
220 """The debugger can be interrupted.
219
221
220 The presumption is there is some mechanism that causes a KeyboardInterrupt
222 The presumption is there is some mechanism that causes a KeyboardInterrupt
221 (this is implemented in ipykernel). We want to ensure the
223 (this is implemented in ipykernel). We want to ensure the
222 KeyboardInterrupt cause debugging to cease.
224 KeyboardInterrupt cause debugging to cease.
223 """
225 """
224 def raising_input(msg="", called=[0]):
226 def raising_input(msg="", called=[0]):
225 called[0] += 1
227 called[0] += 1
226 assert called[0] == 1, "input() should only be called once!"
228 assert called[0] == 1, "input() should only be called once!"
227 raise KeyboardInterrupt()
229 raise KeyboardInterrupt()
228
230
229 tracer_orig = sys.gettrace()
231 tracer_orig = sys.gettrace()
230 try:
232 try:
231 with patch.object(builtins, "input", raising_input):
233 with patch.object(builtins, "input", raising_input):
232 debugger.InterruptiblePdb().set_trace()
234 debugger.InterruptiblePdb().set_trace()
233 # The way this test will fail is by set_trace() never exiting,
235 # The way this test will fail is by set_trace() never exiting,
234 # resulting in a timeout by the test runner. The alternative
236 # resulting in a timeout by the test runner. The alternative
235 # implementation would involve a subprocess, but that adds issues
237 # implementation would involve a subprocess, but that adds issues
236 # with interrupting subprocesses that are rather complex, so it's
238 # with interrupting subprocesses that are rather complex, so it's
237 # simpler just to do it this way.
239 # simpler just to do it this way.
238 finally:
240 finally:
239 # restore the original trace function
241 # restore the original trace function
240 sys.settrace(tracer_orig)
242 sys.settrace(tracer_orig)
241
243
242
244
243 @skip_win32
245 @skip_win32
244 def test_xmode_skip():
246 def test_xmode_skip():
245 """that xmode skip frames
247 """that xmode skip frames
246
248
247 Not as a doctest as pytest does not run doctests.
249 Not as a doctest as pytest does not run doctests.
248 """
250 """
249 import pexpect
251 import pexpect
250 env = os.environ.copy()
252 env = os.environ.copy()
251 env["IPY_TEST_SIMPLE_PROMPT"] = "1"
253 env["IPY_TEST_SIMPLE_PROMPT"] = "1"
252
254
253 child = pexpect.spawn(
255 child = pexpect.spawn(
254 sys.executable, ["-m", "IPython", "--colors=nocolor"], env=env
256 sys.executable, ["-m", "IPython", "--colors=nocolor"], env=env
255 )
257 )
256 child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE
258 child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE
257
259
258 child.expect("IPython")
260 child.expect("IPython")
259 child.expect("\n")
261 child.expect("\n")
260 child.expect_exact("In [1]")
262 child.expect_exact("In [1]")
261
263
262 block = dedent(
264 block = dedent(
263 """
265 """
264 def f():
266 def f():
265 __tracebackhide__ = True
267 __tracebackhide__ = True
266 g()
268 g()
267
269
268 def g():
270 def g():
269 raise ValueError
271 raise ValueError
270
272
271 f()
273 f()
272 """
274 """
273 )
275 )
274
276
275 for line in block.splitlines():
277 for line in block.splitlines():
276 child.sendline(line)
278 child.sendline(line)
277 child.expect_exact(line)
279 child.expect_exact(line)
278 child.expect_exact("skipping")
280 child.expect_exact("skipping")
279
281
280 block = dedent(
282 block = dedent(
281 """
283 """
282 def f():
284 def f():
283 __tracebackhide__ = True
285 __tracebackhide__ = True
284 g()
286 g()
285
287
286 def g():
288 def g():
287 from IPython.core.debugger import set_trace
289 from IPython.core.debugger import set_trace
288 set_trace()
290 set_trace()
289
291
290 f()
292 f()
291 """
293 """
292 )
294 )
293
295
294 for line in block.splitlines():
296 for line in block.splitlines():
295 child.sendline(line)
297 child.sendline(line)
296 child.expect_exact(line)
298 child.expect_exact(line)
297
299
298 child.expect("ipdb>")
300 child.expect("ipdb>")
299 child.sendline("w")
301 child.sendline("w")
300 child.expect("hidden")
302 child.expect("hidden")
301 child.expect("ipdb>")
303 child.expect("ipdb>")
302 child.sendline("skip_hidden false")
304 child.sendline("skip_hidden false")
303 child.sendline("w")
305 child.sendline("w")
304 child.expect("__traceba")
306 child.expect("__traceba")
305 child.expect("ipdb>")
307 child.expect("ipdb>")
306
308
307 child.close()
309 child.close()
308
310
309
311
310 skip_decorators_blocks = (
312 skip_decorators_blocks = (
311 """
313 """
312 def helpers_helper():
314 def helpers_helper():
313 pass # should not stop here except breakpoint
315 pass # should not stop here except breakpoint
314 """,
316 """,
315 """
317 """
316 def helper_1():
318 def helper_1():
317 helpers_helper() # should not stop here
319 helpers_helper() # should not stop here
318 """,
320 """,
319 """
321 """
320 def helper_2():
322 def helper_2():
321 pass # should not stop here
323 pass # should not stop here
322 """,
324 """,
323 """
325 """
324 def pdb_skipped_decorator2(function):
326 def pdb_skipped_decorator2(function):
325 def wrapped_fn(*args, **kwargs):
327 def wrapped_fn(*args, **kwargs):
326 __debuggerskip__ = True
328 __debuggerskip__ = True
327 helper_2()
329 helper_2()
328 __debuggerskip__ = False
330 __debuggerskip__ = False
329 result = function(*args, **kwargs)
331 result = function(*args, **kwargs)
330 __debuggerskip__ = True
332 __debuggerskip__ = True
331 helper_2()
333 helper_2()
332 return result
334 return result
333 return wrapped_fn
335 return wrapped_fn
334 """,
336 """,
335 """
337 """
336 def pdb_skipped_decorator(function):
338 def pdb_skipped_decorator(function):
337 def wrapped_fn(*args, **kwargs):
339 def wrapped_fn(*args, **kwargs):
338 __debuggerskip__ = True
340 __debuggerskip__ = True
339 helper_1()
341 helper_1()
340 __debuggerskip__ = False
342 __debuggerskip__ = False
341 result = function(*args, **kwargs)
343 result = function(*args, **kwargs)
342 __debuggerskip__ = True
344 __debuggerskip__ = True
343 helper_2()
345 helper_2()
344 return result
346 return result
345 return wrapped_fn
347 return wrapped_fn
346 """,
348 """,
347 """
349 """
348 @pdb_skipped_decorator
350 @pdb_skipped_decorator
349 @pdb_skipped_decorator2
351 @pdb_skipped_decorator2
350 def bar(x, y):
352 def bar(x, y):
351 return x * y
353 return x * y
352 """,
354 """,
353 """import IPython.terminal.debugger as ipdb""",
355 """import IPython.terminal.debugger as ipdb""",
354 """
356 """
355 def f():
357 def f():
356 ipdb.set_trace()
358 ipdb.set_trace()
357 bar(3, 4)
359 bar(3, 4)
358 """,
360 """,
359 """
361 """
360 f()
362 f()
361 """,
363 """,
362 )
364 )
363
365
364
366
365 def _decorator_skip_setup():
367 def _decorator_skip_setup():
366 import pexpect
368 import pexpect
367
369
368 env = os.environ.copy()
370 env = os.environ.copy()
369 env["IPY_TEST_SIMPLE_PROMPT"] = "1"
371 env["IPY_TEST_SIMPLE_PROMPT"] = "1"
370
372
371 child = pexpect.spawn(
373 child = pexpect.spawn(
372 sys.executable, ["-m", "IPython", "--colors=nocolor"], env=env
374 sys.executable, ["-m", "IPython", "--colors=nocolor"], env=env
373 )
375 )
374 child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE
376 child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE
375
377
376 child.expect("IPython")
378 child.expect("IPython")
377 child.expect("\n")
379 child.expect("\n")
378
380
379 child.timeout = 5 * IPYTHON_TESTING_TIMEOUT_SCALE
381 child.timeout = 5 * IPYTHON_TESTING_TIMEOUT_SCALE
380
382
381 dedented_blocks = [dedent(b).strip() for b in skip_decorators_blocks]
383 dedented_blocks = [dedent(b).strip() for b in skip_decorators_blocks]
382 in_prompt_number = 1
384 in_prompt_number = 1
383 for cblock in dedented_blocks:
385 for cblock in dedented_blocks:
384 child.expect_exact(f"In [{in_prompt_number}]:")
386 child.expect_exact(f"In [{in_prompt_number}]:")
385 in_prompt_number += 1
387 in_prompt_number += 1
386 for line in cblock.splitlines():
388 for line in cblock.splitlines():
387 child.sendline(line)
389 child.sendline(line)
388 child.expect_exact(line)
390 child.expect_exact(line)
389 child.sendline("")
391 child.sendline("")
390 return child
392 return child
391
393
392
394
393 @skip_win32
395 @skip_win32
394 def test_decorator_skip():
396 def test_decorator_skip():
395 """test that decorator frames can be skipped."""
397 """test that decorator frames can be skipped."""
396
398
397 child = _decorator_skip_setup()
399 child = _decorator_skip_setup()
398
400
399 child.expect_exact("3 bar(3, 4)")
401 child.expect_exact("3 bar(3, 4)")
400 child.expect("ipdb>")
402 child.expect("ipdb>")
401
403
402 child.expect("ipdb>")
404 child.expect("ipdb>")
403 child.sendline("step")
405 child.sendline("step")
404 child.expect_exact("step")
406 child.expect_exact("step")
405
407
406 child.expect_exact("1 @pdb_skipped_decorator")
408 child.expect_exact("1 @pdb_skipped_decorator")
407
409
408 child.sendline("s")
410 child.sendline("s")
409 child.expect_exact("return x * y")
411 child.expect_exact("return x * y")
410
412
411 child.close()
413 child.close()
412
414
413
415
416 @pytest.mark.skip(platform.python_implementation() == "PyPy", reason="issues on PyPy")
414 @skip_win32
417 @skip_win32
415 def test_decorator_skip_disabled():
418 def test_decorator_skip_disabled():
416 """test that decorator frame skipping can be disabled"""
419 """test that decorator frame skipping can be disabled"""
417
420
418 child = _decorator_skip_setup()
421 child = _decorator_skip_setup()
419
422
420 child.expect_exact("3 bar(3, 4)")
423 child.expect_exact("3 bar(3, 4)")
421
424
422 for input_, expected in [
425 for input_, expected in [
423 ("skip_predicates debuggerskip False", ""),
426 ("skip_predicates debuggerskip False", ""),
424 ("skip_predicates", "debuggerskip : False"),
427 ("skip_predicates", "debuggerskip : False"),
425 ("step", "---> 2 def wrapped_fn"),
428 ("step", "---> 2 def wrapped_fn"),
426 ("step", "----> 3 __debuggerskip__"),
429 ("step", "----> 3 __debuggerskip__"),
427 ("step", "----> 4 helper_1()"),
430 ("step", "----> 4 helper_1()"),
428 ("step", "---> 1 def helper_1():"),
431 ("step", "---> 1 def helper_1():"),
429 ("next", "----> 2 helpers_helper()"),
432 ("next", "----> 2 helpers_helper()"),
430 ("next", "--Return--"),
433 ("next", "--Return--"),
431 ("next", "----> 5 __debuggerskip__ = False"),
434 ("next", "----> 5 __debuggerskip__ = False"),
432 ]:
435 ]:
433 child.expect("ipdb>")
436 child.expect("ipdb>")
434 child.sendline(input_)
437 child.sendline(input_)
435 child.expect_exact(input_)
438 child.expect_exact(input_)
436 child.expect_exact(expected)
439 child.expect_exact(expected)
437
440
438 child.close()
441 child.close()
439
442
440
443
444 @pytest.mark.skip(platform.python_implementation() == "PyPy", reason="issues on PyPy")
441 @skip_win32
445 @skip_win32
442 def test_decorator_skip_with_breakpoint():
446 def test_decorator_skip_with_breakpoint():
443 """test that decorator frame skipping can be disabled"""
447 """test that decorator frame skipping can be disabled"""
444
448
445 import pexpect
449 import pexpect
446
450
447 env = os.environ.copy()
451 env = os.environ.copy()
448 env["IPY_TEST_SIMPLE_PROMPT"] = "1"
452 env["IPY_TEST_SIMPLE_PROMPT"] = "1"
449
453
450 child = pexpect.spawn(
454 child = pexpect.spawn(
451 sys.executable, ["-m", "IPython", "--colors=nocolor"], env=env
455 sys.executable, ["-m", "IPython", "--colors=nocolor"], env=env
452 )
456 )
453 child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE
457 child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE
454
458
455 child.expect("IPython")
459 child.expect("IPython")
456 child.expect("\n")
460 child.expect("\n")
457
461
458 child.timeout = 5 * IPYTHON_TESTING_TIMEOUT_SCALE
462 child.timeout = 5 * IPYTHON_TESTING_TIMEOUT_SCALE
459
463
460 ### we need a filename, so we need to exec the full block with a filename
464 ### we need a filename, so we need to exec the full block with a filename
461 with NamedTemporaryFile(suffix=".py", dir=".", delete=True) as tf:
465 with NamedTemporaryFile(suffix=".py", dir=".", delete=True) as tf:
462
466
463 name = tf.name[:-3].split("/")[-1]
467 name = tf.name[:-3].split("/")[-1]
464 tf.write("\n".join([dedent(x) for x in skip_decorators_blocks[:-1]]).encode())
468 tf.write("\n".join([dedent(x) for x in skip_decorators_blocks[:-1]]).encode())
465 tf.flush()
469 tf.flush()
466 codeblock = f"from {name} import f"
470 codeblock = f"from {name} import f"
467
471
468 dedented_blocks = [
472 dedented_blocks = [
469 codeblock,
473 codeblock,
470 "f()",
474 "f()",
471 ]
475 ]
472
476
473 in_prompt_number = 1
477 in_prompt_number = 1
474 for cblock in dedented_blocks:
478 for cblock in dedented_blocks:
475 child.expect_exact(f"In [{in_prompt_number}]:")
479 child.expect_exact(f"In [{in_prompt_number}]:")
476 in_prompt_number += 1
480 in_prompt_number += 1
477 for line in cblock.splitlines():
481 for line in cblock.splitlines():
478 child.sendline(line)
482 child.sendline(line)
479 child.expect_exact(line)
483 child.expect_exact(line)
480 child.sendline("")
484 child.sendline("")
481
485
482 # as the filename does not exists, we'll rely on the filename prompt
486 # as the filename does not exists, we'll rely on the filename prompt
483 child.expect_exact("47 bar(3, 4)")
487 child.expect_exact("47 bar(3, 4)")
484
488
485 for input_, expected in [
489 for input_, expected in [
486 (f"b {name}.py:3", ""),
490 (f"b {name}.py:3", ""),
487 ("step", "1---> 3 pass # should not stop here except"),
491 ("step", "1---> 3 pass # should not stop here except"),
488 ("step", "---> 38 @pdb_skipped_decorator"),
492 ("step", "---> 38 @pdb_skipped_decorator"),
489 ("continue", ""),
493 ("continue", ""),
490 ]:
494 ]:
491 child.expect("ipdb>")
495 child.expect("ipdb>")
492 child.sendline(input_)
496 child.sendline(input_)
493 child.expect_exact(input_)
497 child.expect_exact(input_)
494 child.expect_exact(expected)
498 child.expect_exact(expected)
495
499
496 child.close()
500 child.close()
497
501
498
502
499 @skip_win32
503 @skip_win32
500 def test_where_erase_value():
504 def test_where_erase_value():
501 """Test that `where` does not access f_locals and erase values."""
505 """Test that `where` does not access f_locals and erase values."""
502 import pexpect
506 import pexpect
503
507
504 env = os.environ.copy()
508 env = os.environ.copy()
505 env["IPY_TEST_SIMPLE_PROMPT"] = "1"
509 env["IPY_TEST_SIMPLE_PROMPT"] = "1"
506
510
507 child = pexpect.spawn(
511 child = pexpect.spawn(
508 sys.executable, ["-m", "IPython", "--colors=nocolor"], env=env
512 sys.executable, ["-m", "IPython", "--colors=nocolor"], env=env
509 )
513 )
510 child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE
514 child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE
511
515
512 child.expect("IPython")
516 child.expect("IPython")
513 child.expect("\n")
517 child.expect("\n")
514 child.expect_exact("In [1]")
518 child.expect_exact("In [1]")
515
519
516 block = dedent(
520 block = dedent(
517 """
521 """
518 def simple_f():
522 def simple_f():
519 myvar = 1
523 myvar = 1
520 print(myvar)
524 print(myvar)
521 1/0
525 1/0
522 print(myvar)
526 print(myvar)
523 simple_f() """
527 simple_f() """
524 )
528 )
525
529
526 for line in block.splitlines():
530 for line in block.splitlines():
527 child.sendline(line)
531 child.sendline(line)
528 child.expect_exact(line)
532 child.expect_exact(line)
529 child.expect_exact("ZeroDivisionError")
533 child.expect_exact("ZeroDivisionError")
530 child.expect_exact("In [2]:")
534 child.expect_exact("In [2]:")
531
535
532 child.sendline("%debug")
536 child.sendline("%debug")
533
537
534 ##
538 ##
535 child.expect("ipdb>")
539 child.expect("ipdb>")
536
540
537 child.sendline("myvar")
541 child.sendline("myvar")
538 child.expect("1")
542 child.expect("1")
539
543
540 ##
544 ##
541 child.expect("ipdb>")
545 child.expect("ipdb>")
542
546
543 child.sendline("myvar = 2")
547 child.sendline("myvar = 2")
544
548
545 ##
549 ##
546 child.expect_exact("ipdb>")
550 child.expect_exact("ipdb>")
547
551
548 child.sendline("myvar")
552 child.sendline("myvar")
549
553
550 child.expect_exact("2")
554 child.expect_exact("2")
551
555
552 ##
556 ##
553 child.expect("ipdb>")
557 child.expect("ipdb>")
554 child.sendline("where")
558 child.sendline("where")
555
559
556 ##
560 ##
557 child.expect("ipdb>")
561 child.expect("ipdb>")
558 child.sendline("myvar")
562 child.sendline("myvar")
559
563
560 child.expect_exact("2")
564 child.expect_exact("2")
561 child.expect("ipdb>")
565 child.expect("ipdb>")
562
566
563 child.close()
567 child.close()
General Comments 0
You need to be logged in to leave comments. Login now