blob: a778c6c6a613933041e53e69f511f8064065bed0 [file] [log] [blame]
Georg Brandl46b9afc2010-07-30 09:14:20 +00001# A test suite for pdb; not very comprehensive at the moment.
Georg Brandl243ad662009-05-05 09:00:19 +00002
3import imp
Georg Brandl6cccb862010-07-30 14:16:43 +00004import pdb
Georg Brandl243ad662009-05-05 09:00:19 +00005import sys
Georg Brandl6cccb862010-07-30 14:16:43 +00006import unittest
7import subprocess
Georg Brandl243ad662009-05-05 09:00:19 +00008
9from test import support
10# This little helper class is essential for testing pdb under doctest.
11from test.test_doctest import _FakeInput
12
13
Georg Brandl9fa2e022009-09-16 16:40:45 +000014class PdbTestInput(object):
15 """Context manager that makes testing Pdb in doctests easier."""
16
17 def __init__(self, input):
18 self.input = input
19
20 def __enter__(self):
21 self.real_stdin = sys.stdin
22 sys.stdin = _FakeInput(self.input)
23
24 def __exit__(self, *exc):
25 sys.stdin = self.real_stdin
26
27
28def test_pdb_displayhook():
29 """This tests the custom displayhook for pdb.
30
31 >>> def test_function(foo, bar):
32 ... import pdb; pdb.Pdb().set_trace()
33 ... pass
34
35 >>> with PdbTestInput([
36 ... 'foo',
37 ... 'bar',
38 ... 'for i in range(5): print(i)',
39 ... 'continue',
40 ... ]):
41 ... test_function(1, None)
42 > <doctest test.test_pdb.test_pdb_displayhook[0]>(3)test_function()
43 -> pass
44 (Pdb) foo
45 1
46 (Pdb) bar
47 (Pdb) for i in range(5): print(i)
48 0
49 1
50 2
51 3
52 4
53 (Pdb) continue
54 """
55
56
Georg Brandl0d089622010-07-30 16:00:46 +000057def test_pdb_basic_commands():
58 """Test the basic commands of pdb.
59
60 >>> def test_function_2(foo, bar='default'):
61 ... print(foo)
62 ... for i in range(5):
63 ... print(i)
64 ... print(bar)
65 ... for i in range(10):
66 ... never_executed
67 ... print('after for')
68 ... print('...')
69 ... return foo.upper()
70
71 >>> def test_function():
72 ... import pdb; pdb.Pdb().set_trace()
73 ... ret = test_function_2('baz')
74 ... print(ret)
75
76 >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
77 ... 'step', # entering the function call
78 ... 'args', # display function args
79 ... 'list', # list function source
80 ... 'bt', # display backtrace
81 ... 'up', # step up to test_function()
82 ... 'down', # step down to test_function_2() again
83 ... 'next', # stepping to print(foo)
84 ... 'next', # stepping to the for loop
85 ... 'step', # stepping into the for loop
86 ... 'until', # continuing until out of the for loop
87 ... 'next', # executing the print(bar)
88 ... 'jump 8', # jump over second for loop
89 ... 'return', # return out of function
90 ... 'retval', # display return value
91 ... 'continue',
92 ... ]):
93 ... test_function()
94 > <doctest test.test_pdb.test_pdb_basic_commands[1]>(3)test_function()
95 -> ret = test_function_2('baz')
96 (Pdb) step
97 --Call--
98 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
99 -> def test_function_2(foo, bar='default'):
100 (Pdb) args
101 foo = 'baz'
102 bar = 'default'
103 (Pdb) list
104 1 -> def test_function_2(foo, bar='default'):
105 2 print(foo)
106 3 for i in range(5):
107 4 print(i)
108 5 print(bar)
109 6 for i in range(10):
110 7 never_executed
111 8 print('after for')
112 9 print('...')
113 10 return foo.upper()
114 [EOF]
115 (Pdb) bt
116 ...
117 <doctest test.test_pdb.test_pdb_basic_commands[2]>(18)<module>()
118 -> test_function()
119 <doctest test.test_pdb.test_pdb_basic_commands[1]>(3)test_function()
120 -> ret = test_function_2('baz')
121 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
122 -> def test_function_2(foo, bar='default'):
123 (Pdb) up
124 > <doctest test.test_pdb.test_pdb_basic_commands[1]>(3)test_function()
125 -> ret = test_function_2('baz')
126 (Pdb) down
127 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
128 -> def test_function_2(foo, bar='default'):
129 (Pdb) next
130 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(2)test_function_2()
131 -> print(foo)
132 (Pdb) next
133 baz
134 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(3)test_function_2()
135 -> for i in range(5):
136 (Pdb) step
137 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(4)test_function_2()
138 -> print(i)
139 (Pdb) until
140 0
141 1
142 2
143 3
144 4
145 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(5)test_function_2()
146 -> print(bar)
147 (Pdb) next
148 default
149 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(6)test_function_2()
150 -> for i in range(10):
151 (Pdb) jump 8
152 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(8)test_function_2()
153 -> print('after for')
154 (Pdb) return
155 after for
156 ...
157 --Return--
158 > <doctest test.test_pdb.test_pdb_basic_commands[0]>(10)test_function_2()->'BAZ'
159 -> return foo.upper()
160 (Pdb) retval
161 'BAZ'
162 (Pdb) continue
163 BAZ
164 """
165
166
167def test_pdb_breakpoint_commands():
168 """Test basic commands related to breakpoints.
169
170 >>> def test_function():
171 ... import pdb; pdb.Pdb().set_trace()
172 ... print(1)
173 ... print(2)
174 ... print(3)
175 ... print(4)
176
177 First, need to clear bdb state that might be left over from previous tests.
178 Otherwise, the new breakpoints might get assigned different numbers.
179
180 >>> from bdb import Breakpoint
181 >>> Breakpoint.next = 1
182 >>> Breakpoint.bplist = {}
183 >>> Breakpoint.bpbynumber = [None]
184
185 Now test the breakpoint commands. NORMALIZE_WHITESPACE is needed because
186 the breakpoint list outputs a tab for the "stop only" and "ignore next"
187 lines, which we don't want to put in here.
188
189 >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
190 ... 'break 3',
191 ... 'disable 1',
192 ... 'ignore 1 10',
193 ... 'condition 1 1 < 2',
194 ... 'break 4',
Senthil Kumaran6f107042010-11-29 11:54:17 +0000195 ... 'break 4',
196 ... 'break',
197 ... 'clear 3',
Georg Brandl0d089622010-07-30 16:00:46 +0000198 ... 'break',
199 ... 'condition 1',
200 ... 'enable 1',
201 ... 'clear 1',
202 ... 'commands 2',
203 ... 'print 42',
204 ... 'end',
205 ... 'continue', # will stop at breakpoint 2 (line 4)
206 ... 'clear', # clear all!
207 ... 'y',
208 ... 'tbreak 5',
209 ... 'continue', # will stop at temporary breakpoint
210 ... 'break', # make sure breakpoint is gone
211 ... 'continue',
212 ... ]):
213 ... test_function()
214 > <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(3)test_function()
215 -> print(1)
216 (Pdb) break 3
217 Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
218 (Pdb) disable 1
219 Disabled breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
220 (Pdb) ignore 1 10
221 Will ignore next 10 crossings of breakpoint 1.
222 (Pdb) condition 1 1 < 2
223 New condition set for breakpoint 1.
224 (Pdb) break 4
225 Breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
Senthil Kumaran6f107042010-11-29 11:54:17 +0000226 (Pdb) break 4
227 Breakpoint 3 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
228 (Pdb) break
229 Num Type Disp Enb Where
230 1 breakpoint keep no at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
231 stop only if 1 < 2
232 ignore next 10 hits
233 2 breakpoint keep yes at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
234 3 breakpoint keep yes at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
235 (Pdb) clear 3
236 Deleted breakpoint 3 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
Georg Brandl0d089622010-07-30 16:00:46 +0000237 (Pdb) break
238 Num Type Disp Enb Where
239 1 breakpoint keep no at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
240 stop only if 1 < 2
241 ignore next 10 hits
242 2 breakpoint keep yes at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
243 (Pdb) condition 1
244 Breakpoint 1 is now unconditional.
245 (Pdb) enable 1
246 Enabled breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
247 (Pdb) clear 1
248 Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
249 (Pdb) commands 2
250 (com) print 42
251 (com) end
252 (Pdb) continue
253 1
254 42
255 > <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(4)test_function()
256 -> print(2)
257 (Pdb) clear
258 Clear all breaks? y
259 Deleted breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
260 (Pdb) tbreak 5
Senthil Kumaran6f107042010-11-29 11:54:17 +0000261 Breakpoint 4 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:5
Georg Brandl0d089622010-07-30 16:00:46 +0000262 (Pdb) continue
263 2
Senthil Kumaran6f107042010-11-29 11:54:17 +0000264 Deleted breakpoint 4 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:5
Georg Brandl0d089622010-07-30 16:00:46 +0000265 > <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(5)test_function()
266 -> print(3)
267 (Pdb) break
268 (Pdb) continue
269 3
270 4
271 """
272
273
Georg Brandle59ca2a2010-07-30 17:04:28 +0000274def do_nothing():
275 pass
276
277def do_something():
278 print(42)
279
280def test_list_commands():
281 """Test the list and source commands of pdb.
282
283 >>> def test_function_2(foo):
Georg Brandla8fbc6a2010-07-31 11:52:46 +0000284 ... import test.test_pdb
285 ... test.test_pdb.do_nothing()
Georg Brandle59ca2a2010-07-30 17:04:28 +0000286 ... 'some...'
287 ... 'more...'
288 ... 'code...'
289 ... 'to...'
290 ... 'make...'
291 ... 'a...'
292 ... 'long...'
293 ... 'listing...'
294 ... 'useful...'
295 ... '...'
296 ... '...'
297 ... return foo
298
299 >>> def test_function():
300 ... import pdb; pdb.Pdb().set_trace()
301 ... ret = test_function_2('baz')
302
303 >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
304 ... 'list', # list first function
305 ... 'step', # step into second function
306 ... 'list', # list second function
307 ... 'list', # continue listing to EOF
308 ... 'list 1,3', # list specific lines
309 ... 'list x', # invalid argument
310 ... 'next', # step to import
311 ... 'next', # step over import
312 ... 'step', # step into do_nothing
313 ... 'longlist', # list all lines
314 ... 'source do_something', # list all lines of function
Georg Brandlcdf66a92010-07-30 18:15:16 +0000315 ... 'source fooxxx', # something that doesn't exit
Georg Brandle59ca2a2010-07-30 17:04:28 +0000316 ... 'continue',
317 ... ]):
318 ... test_function()
319 > <doctest test.test_pdb.test_list_commands[1]>(3)test_function()
320 -> ret = test_function_2('baz')
321 (Pdb) list
322 1 def test_function():
323 2 import pdb; pdb.Pdb().set_trace()
324 3 -> ret = test_function_2('baz')
325 [EOF]
326 (Pdb) step
327 --Call--
328 > <doctest test.test_pdb.test_list_commands[0]>(1)test_function_2()
329 -> def test_function_2(foo):
330 (Pdb) list
331 1 -> def test_function_2(foo):
Georg Brandla8fbc6a2010-07-31 11:52:46 +0000332 2 import test.test_pdb
333 3 test.test_pdb.do_nothing()
Georg Brandle59ca2a2010-07-30 17:04:28 +0000334 4 'some...'
335 5 'more...'
336 6 'code...'
337 7 'to...'
338 8 'make...'
339 9 'a...'
340 10 'long...'
341 11 'listing...'
342 (Pdb) list
343 12 'useful...'
344 13 '...'
345 14 '...'
346 15 return foo
347 [EOF]
348 (Pdb) list 1,3
349 1 -> def test_function_2(foo):
Georg Brandla8fbc6a2010-07-31 11:52:46 +0000350 2 import test.test_pdb
351 3 test.test_pdb.do_nothing()
Georg Brandle59ca2a2010-07-30 17:04:28 +0000352 (Pdb) list x
353 *** ...
354 (Pdb) next
355 > <doctest test.test_pdb.test_list_commands[0]>(2)test_function_2()
Georg Brandla8fbc6a2010-07-31 11:52:46 +0000356 -> import test.test_pdb
Georg Brandle59ca2a2010-07-30 17:04:28 +0000357 (Pdb) next
358 > <doctest test.test_pdb.test_list_commands[0]>(3)test_function_2()
Georg Brandla8fbc6a2010-07-31 11:52:46 +0000359 -> test.test_pdb.do_nothing()
Georg Brandle59ca2a2010-07-30 17:04:28 +0000360 (Pdb) step
361 --Call--
Georg Brandle1e8df12010-07-31 08:14:16 +0000362 > ...test_pdb.py(...)do_nothing()
Georg Brandle59ca2a2010-07-30 17:04:28 +0000363 -> def do_nothing():
364 (Pdb) longlist
365 ... -> def do_nothing():
366 ... pass
367 (Pdb) source do_something
368 ... def do_something():
369 ... print(42)
Georg Brandlcdf66a92010-07-30 18:15:16 +0000370 (Pdb) source fooxxx
371 *** ...
Georg Brandle59ca2a2010-07-30 17:04:28 +0000372 (Pdb) continue
373 """
374
375
Georg Brandl0a9c3e92010-07-30 18:46:38 +0000376def test_post_mortem():
377 """Test post mortem traceback debugging.
378
379 >>> def test_function_2():
380 ... try:
381 ... 1/0
382 ... finally:
383 ... print('Exception!')
384
385 >>> def test_function():
386 ... import pdb; pdb.Pdb().set_trace()
387 ... test_function_2()
388 ... print('Not reached.')
389
390 >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
391 ... 'next', # step over exception-raising call
392 ... 'bt', # get a backtrace
393 ... 'list', # list code of test_function()
394 ... 'down', # step into test_function_2()
395 ... 'list', # list code of test_function_2()
396 ... 'continue',
397 ... ]):
398 ... try:
399 ... test_function()
400 ... except ZeroDivisionError:
401 ... print('Correctly reraised.')
402 > <doctest test.test_pdb.test_post_mortem[1]>(3)test_function()
403 -> test_function_2()
404 (Pdb) next
405 Exception!
406 ZeroDivisionError: division by zero
407 > <doctest test.test_pdb.test_post_mortem[1]>(3)test_function()
408 -> test_function_2()
409 (Pdb) bt
410 ...
411 <doctest test.test_pdb.test_post_mortem[2]>(10)<module>()
412 -> test_function()
413 > <doctest test.test_pdb.test_post_mortem[1]>(3)test_function()
414 -> test_function_2()
415 <doctest test.test_pdb.test_post_mortem[0]>(3)test_function_2()
416 -> 1/0
417 (Pdb) list
418 1 def test_function():
419 2 import pdb; pdb.Pdb().set_trace()
420 3 -> test_function_2()
421 4 print('Not reached.')
422 [EOF]
423 (Pdb) down
424 > <doctest test.test_pdb.test_post_mortem[0]>(3)test_function_2()
425 -> 1/0
426 (Pdb) list
427 1 def test_function_2():
428 2 try:
429 3 >> 1/0
430 4 finally:
431 5 -> print('Exception!')
432 [EOF]
433 (Pdb) continue
434 Correctly reraised.
435 """
436
437
Georg Brandl243ad662009-05-05 09:00:19 +0000438def test_pdb_skip_modules():
439 """This illustrates the simple case of module skipping.
440
441 >>> def skip_module():
442 ... import string
443 ... import pdb; pdb.Pdb(skip=['stri*']).set_trace()
444 ... string.capwords('FOO')
Georg Brandl243ad662009-05-05 09:00:19 +0000445
Georg Brandl9fa2e022009-09-16 16:40:45 +0000446 >>> with PdbTestInput([
447 ... 'step',
448 ... 'continue',
449 ... ]):
Georg Brandl243ad662009-05-05 09:00:19 +0000450 ... skip_module()
Georg Brandl243ad662009-05-05 09:00:19 +0000451 > <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()
452 -> string.capwords('FOO')
453 (Pdb) step
454 --Return--
455 > <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()->None
456 -> string.capwords('FOO')
457 (Pdb) continue
Georg Brandl9fa2e022009-09-16 16:40:45 +0000458 """
Georg Brandl243ad662009-05-05 09:00:19 +0000459
460
461# Module for testing skipping of module that makes a callback
462mod = imp.new_module('module_to_skip')
463exec('def foo_pony(callback): x = 1; callback(); return None', mod.__dict__)
464
465
466def test_pdb_skip_modules_with_callback():
467 """This illustrates skipping of modules that call into other code.
468
469 >>> def skip_module():
470 ... def callback():
471 ... return None
Georg Brandl9fa2e022009-09-16 16:40:45 +0000472 ... import pdb; pdb.Pdb(skip=['module_to_skip*']).set_trace()
Georg Brandl243ad662009-05-05 09:00:19 +0000473 ... mod.foo_pony(callback)
Georg Brandl243ad662009-05-05 09:00:19 +0000474
Georg Brandl9fa2e022009-09-16 16:40:45 +0000475 >>> with PdbTestInput([
476 ... 'step',
477 ... 'step',
478 ... 'step',
479 ... 'step',
480 ... 'step',
481 ... 'continue',
482 ... ]):
Georg Brandl243ad662009-05-05 09:00:19 +0000483 ... skip_module()
Georg Brandl9fa2e022009-09-16 16:40:45 +0000484 ... pass # provides something to "step" to
Georg Brandl243ad662009-05-05 09:00:19 +0000485 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()
486 -> mod.foo_pony(callback)
487 (Pdb) step
488 --Call--
489 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(2)callback()
490 -> def callback():
491 (Pdb) step
492 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(3)callback()
493 -> return None
494 (Pdb) step
495 --Return--
496 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(3)callback()->None
497 -> return None
498 (Pdb) step
499 --Return--
500 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()->None
501 -> mod.foo_pony(callback)
502 (Pdb) step
Georg Brandl9fa2e022009-09-16 16:40:45 +0000503 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[1]>(10)<module>()
504 -> pass # provides something to "step" to
Georg Brandl243ad662009-05-05 09:00:19 +0000505 (Pdb) continue
Georg Brandl9fa2e022009-09-16 16:40:45 +0000506 """
Georg Brandl243ad662009-05-05 09:00:19 +0000507
508
Georg Brandl3f940892010-07-30 10:29:19 +0000509def test_pdb_continue_in_bottomframe():
510 """Test that "continue" and "next" work properly in bottom frame (issue #5294).
511
512 >>> def test_function():
513 ... import pdb, sys; inst = pdb.Pdb()
514 ... inst.set_trace()
515 ... inst.botframe = sys._getframe() # hackery to get the right botframe
516 ... print(1)
517 ... print(2)
518 ... print(3)
519 ... print(4)
520
Georg Brandl7410dd12010-07-30 12:01:20 +0000521 >>> with PdbTestInput([ # doctest: +ELLIPSIS
Georg Brandl3f940892010-07-30 10:29:19 +0000522 ... 'next',
523 ... 'break 7',
524 ... 'continue',
525 ... 'next',
526 ... 'continue',
527 ... 'continue',
528 ... ]):
529 ... test_function()
530 > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(4)test_function()
531 -> inst.botframe = sys._getframe() # hackery to get the right botframe
532 (Pdb) next
533 > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(5)test_function()
534 -> print(1)
535 (Pdb) break 7
Georg Brandl7410dd12010-07-30 12:01:20 +0000536 Breakpoint ... at <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>:7
Georg Brandl3f940892010-07-30 10:29:19 +0000537 (Pdb) continue
538 1
539 2
540 > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(7)test_function()
541 -> print(3)
542 (Pdb) next
543 3
544 > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(8)test_function()
545 -> print(4)
546 (Pdb) continue
547 4
548 """
549
550
Georg Brandl46b9afc2010-07-30 09:14:20 +0000551def pdb_invoke(method, arg):
552 """Run pdb.method(arg)."""
553 import pdb; getattr(pdb, method)(arg)
554
555
556def test_pdb_run_with_incorrect_argument():
557 """Testing run and runeval with incorrect first argument.
558
559 >>> pti = PdbTestInput(['continue',])
560 >>> with pti:
561 ... pdb_invoke('run', lambda x: x)
562 Traceback (most recent call last):
563 TypeError: exec() arg 1 must be a string, bytes or code object
564
565 >>> with pti:
566 ... pdb_invoke('runeval', lambda x: x)
567 Traceback (most recent call last):
568 TypeError: eval() arg 1 must be a string, bytes or code object
569 """
570
571
572def test_pdb_run_with_code_object():
573 """Testing run and runeval with code object as a first argument.
574
Georg Brandle1e8df12010-07-31 08:14:16 +0000575 >>> with PdbTestInput(['step','x', 'continue']): # doctest: +ELLIPSIS
Georg Brandl46b9afc2010-07-30 09:14:20 +0000576 ... pdb_invoke('run', compile('x=1', '<string>', 'exec'))
Georg Brandle1e8df12010-07-31 08:14:16 +0000577 > <string>(1)<module>()...
Georg Brandl46b9afc2010-07-30 09:14:20 +0000578 (Pdb) step
579 --Return--
580 > <string>(1)<module>()->None
581 (Pdb) x
582 1
583 (Pdb) continue
584
585 >>> with PdbTestInput(['x', 'continue']):
586 ... x=0
587 ... pdb_invoke('runeval', compile('x+1', '<string>', 'eval'))
588 > <string>(1)<module>()->None
589 (Pdb) x
590 1
591 (Pdb) continue
592 """
593
594
Georg Brandl6cccb862010-07-30 14:16:43 +0000595class PdbTestCase(unittest.TestCase):
596
597 def test_issue7964(self):
598 # open the file as binary so we can force \r\n newline
599 with open(support.TESTFN, 'wb') as f:
600 f.write(b'print("testing my pdb")\r\n')
601 cmd = [sys.executable, '-m', 'pdb', support.TESTFN]
602 proc = subprocess.Popen(cmd,
603 stdout=subprocess.PIPE,
604 stdin=subprocess.PIPE,
605 stderr=subprocess.STDOUT,
606 )
Brian Curtin994ad6c2010-11-05 15:38:47 +0000607 self.addCleanup(proc.stdout.close)
Georg Brandl6cccb862010-07-30 14:16:43 +0000608 stdout, stderr = proc.communicate(b'quit\n')
609 self.assertNotIn(b'SyntaxError', stdout,
610 "Got a syntax error running test script under PDB")
611
612 def tearDown(self):
613 support.unlink(support.TESTFN)
614
615
Georg Brandl243ad662009-05-05 09:00:19 +0000616def test_main():
617 from test import test_pdb
618 support.run_doctest(test_pdb, verbosity=True)
Georg Brandl6cccb862010-07-30 14:16:43 +0000619 support.run_unittest(PdbTestCase)
Georg Brandl243ad662009-05-05 09:00:19 +0000620
621
622if __name__ == '__main__':
623 test_main()