Georg Brandl | 46b9afc | 2010-07-30 09:14:20 +0000 | [diff] [blame] | 1 | # A test suite for pdb; not very comprehensive at the moment. |
Martin v. Löwis | 67880cc | 2012-05-02 07:41:22 +0200 | [diff] [blame] | 2 | |
Andrew Svetlov | f0efea0 | 2013-03-18 10:09:50 -0700 | [diff] [blame] | 3 | import doctest |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 4 | import os |
Georg Brandl | 6cccb86 | 2010-07-30 14:16:43 +0000 | [diff] [blame] | 5 | import pdb |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 6 | import sys |
Brett Cannon | 9529fbf | 2013-06-15 17:11:25 -0400 | [diff] [blame] | 7 | import types |
Serhiy Storchaka | 19fcffa | 2020-06-21 11:07:50 +0300 | [diff] [blame^] | 8 | import codecs |
Georg Brandl | 6cccb86 | 2010-07-30 14:16:43 +0000 | [diff] [blame] | 9 | import unittest |
| 10 | import subprocess |
Senthil Kumaran | 42d7081 | 2012-05-01 10:07:49 +0800 | [diff] [blame] | 11 | import textwrap |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 12 | |
Barry Warsaw | 35425d6 | 2017-09-22 12:29:42 -0400 | [diff] [blame] | 13 | from contextlib import ExitStack |
| 14 | from io import StringIO |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 15 | from test import support |
| 16 | # This little helper class is essential for testing pdb under doctest. |
| 17 | from test.test_doctest import _FakeInput |
Barry Warsaw | 35425d6 | 2017-09-22 12:29:42 -0400 | [diff] [blame] | 18 | from unittest.mock import patch |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 19 | |
| 20 | |
Georg Brandl | 9fa2e02 | 2009-09-16 16:40:45 +0000 | [diff] [blame] | 21 | class PdbTestInput(object): |
| 22 | """Context manager that makes testing Pdb in doctests easier.""" |
| 23 | |
| 24 | def __init__(self, input): |
| 25 | self.input = input |
| 26 | |
| 27 | def __enter__(self): |
| 28 | self.real_stdin = sys.stdin |
| 29 | sys.stdin = _FakeInput(self.input) |
Brett Cannon | 31f5929 | 2011-02-21 19:29:56 +0000 | [diff] [blame] | 30 | self.orig_trace = sys.gettrace() if hasattr(sys, 'gettrace') else None |
Georg Brandl | 9fa2e02 | 2009-09-16 16:40:45 +0000 | [diff] [blame] | 31 | |
| 32 | def __exit__(self, *exc): |
| 33 | sys.stdin = self.real_stdin |
Brett Cannon | 31f5929 | 2011-02-21 19:29:56 +0000 | [diff] [blame] | 34 | if self.orig_trace: |
| 35 | sys.settrace(self.orig_trace) |
Georg Brandl | 9fa2e02 | 2009-09-16 16:40:45 +0000 | [diff] [blame] | 36 | |
| 37 | |
| 38 | def test_pdb_displayhook(): |
| 39 | """This tests the custom displayhook for pdb. |
| 40 | |
| 41 | >>> def test_function(foo, bar): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 42 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
Georg Brandl | 9fa2e02 | 2009-09-16 16:40:45 +0000 | [diff] [blame] | 43 | ... pass |
| 44 | |
| 45 | >>> with PdbTestInput([ |
| 46 | ... 'foo', |
| 47 | ... 'bar', |
| 48 | ... 'for i in range(5): print(i)', |
| 49 | ... 'continue', |
| 50 | ... ]): |
| 51 | ... test_function(1, None) |
| 52 | > <doctest test.test_pdb.test_pdb_displayhook[0]>(3)test_function() |
| 53 | -> pass |
| 54 | (Pdb) foo |
| 55 | 1 |
| 56 | (Pdb) bar |
| 57 | (Pdb) for i in range(5): print(i) |
| 58 | 0 |
| 59 | 1 |
| 60 | 2 |
| 61 | 3 |
| 62 | 4 |
| 63 | (Pdb) continue |
| 64 | """ |
| 65 | |
| 66 | |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 67 | def test_pdb_basic_commands(): |
| 68 | """Test the basic commands of pdb. |
| 69 | |
| 70 | >>> def test_function_2(foo, bar='default'): |
| 71 | ... print(foo) |
| 72 | ... for i in range(5): |
| 73 | ... print(i) |
| 74 | ... print(bar) |
| 75 | ... for i in range(10): |
| 76 | ... never_executed |
| 77 | ... print('after for') |
| 78 | ... print('...') |
| 79 | ... return foo.upper() |
| 80 | |
Rémi Lapeyre | bf457c7 | 2019-05-21 00:17:30 +0200 | [diff] [blame] | 81 | >>> def test_function3(arg=None, *, kwonly=None): |
| 82 | ... pass |
| 83 | |
Rémi Lapeyre | 4585603 | 2019-05-24 22:44:31 +0200 | [diff] [blame] | 84 | >>> def test_function4(a, b, c, /): |
| 85 | ... pass |
| 86 | |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 87 | >>> def test_function(): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 88 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 89 | ... ret = test_function_2('baz') |
Rémi Lapeyre | bf457c7 | 2019-05-21 00:17:30 +0200 | [diff] [blame] | 90 | ... test_function3(kwonly=True) |
Rémi Lapeyre | 4585603 | 2019-05-24 22:44:31 +0200 | [diff] [blame] | 91 | ... test_function4(1, 2, 3) |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 92 | ... print(ret) |
| 93 | |
| 94 | >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE |
| 95 | ... 'step', # entering the function call |
| 96 | ... 'args', # display function args |
| 97 | ... 'list', # list function source |
| 98 | ... 'bt', # display backtrace |
| 99 | ... 'up', # step up to test_function() |
| 100 | ... 'down', # step down to test_function_2() again |
| 101 | ... 'next', # stepping to print(foo) |
| 102 | ... 'next', # stepping to the for loop |
| 103 | ... 'step', # stepping into the for loop |
| 104 | ... 'until', # continuing until out of the for loop |
| 105 | ... 'next', # executing the print(bar) |
| 106 | ... 'jump 8', # jump over second for loop |
| 107 | ... 'return', # return out of function |
| 108 | ... 'retval', # display return value |
Rémi Lapeyre | bf457c7 | 2019-05-21 00:17:30 +0200 | [diff] [blame] | 109 | ... 'next', # step to test_function3() |
| 110 | ... 'step', # stepping into test_function3() |
| 111 | ... 'args', # display function args |
Rémi Lapeyre | 4585603 | 2019-05-24 22:44:31 +0200 | [diff] [blame] | 112 | ... 'return', # return out of function |
| 113 | ... 'next', # step to test_function4() |
| 114 | ... 'step', # stepping to test_function4() |
| 115 | ... 'args', # display function args |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 116 | ... 'continue', |
| 117 | ... ]): |
| 118 | ... test_function() |
Rémi Lapeyre | 4585603 | 2019-05-24 22:44:31 +0200 | [diff] [blame] | 119 | > <doctest test.test_pdb.test_pdb_basic_commands[3]>(3)test_function() |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 120 | -> ret = test_function_2('baz') |
| 121 | (Pdb) step |
| 122 | --Call-- |
| 123 | > <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2() |
| 124 | -> def test_function_2(foo, bar='default'): |
| 125 | (Pdb) args |
| 126 | foo = 'baz' |
| 127 | bar = 'default' |
| 128 | (Pdb) list |
| 129 | 1 -> def test_function_2(foo, bar='default'): |
| 130 | 2 print(foo) |
| 131 | 3 for i in range(5): |
| 132 | 4 print(i) |
| 133 | 5 print(bar) |
| 134 | 6 for i in range(10): |
| 135 | 7 never_executed |
| 136 | 8 print('after for') |
| 137 | 9 print('...') |
| 138 | 10 return foo.upper() |
| 139 | [EOF] |
| 140 | (Pdb) bt |
| 141 | ... |
Rémi Lapeyre | 4585603 | 2019-05-24 22:44:31 +0200 | [diff] [blame] | 142 | <doctest test.test_pdb.test_pdb_basic_commands[4]>(25)<module>() |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 143 | -> test_function() |
Rémi Lapeyre | 4585603 | 2019-05-24 22:44:31 +0200 | [diff] [blame] | 144 | <doctest test.test_pdb.test_pdb_basic_commands[3]>(3)test_function() |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 145 | -> ret = test_function_2('baz') |
| 146 | > <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2() |
| 147 | -> def test_function_2(foo, bar='default'): |
| 148 | (Pdb) up |
Rémi Lapeyre | 4585603 | 2019-05-24 22:44:31 +0200 | [diff] [blame] | 149 | > <doctest test.test_pdb.test_pdb_basic_commands[3]>(3)test_function() |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 150 | -> ret = test_function_2('baz') |
| 151 | (Pdb) down |
| 152 | > <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2() |
| 153 | -> def test_function_2(foo, bar='default'): |
| 154 | (Pdb) next |
| 155 | > <doctest test.test_pdb.test_pdb_basic_commands[0]>(2)test_function_2() |
| 156 | -> print(foo) |
| 157 | (Pdb) next |
| 158 | baz |
| 159 | > <doctest test.test_pdb.test_pdb_basic_commands[0]>(3)test_function_2() |
| 160 | -> for i in range(5): |
| 161 | (Pdb) step |
| 162 | > <doctest test.test_pdb.test_pdb_basic_commands[0]>(4)test_function_2() |
| 163 | -> print(i) |
| 164 | (Pdb) until |
| 165 | 0 |
| 166 | 1 |
| 167 | 2 |
| 168 | 3 |
| 169 | 4 |
| 170 | > <doctest test.test_pdb.test_pdb_basic_commands[0]>(5)test_function_2() |
| 171 | -> print(bar) |
| 172 | (Pdb) next |
| 173 | default |
| 174 | > <doctest test.test_pdb.test_pdb_basic_commands[0]>(6)test_function_2() |
| 175 | -> for i in range(10): |
| 176 | (Pdb) jump 8 |
| 177 | > <doctest test.test_pdb.test_pdb_basic_commands[0]>(8)test_function_2() |
| 178 | -> print('after for') |
| 179 | (Pdb) return |
| 180 | after for |
| 181 | ... |
| 182 | --Return-- |
| 183 | > <doctest test.test_pdb.test_pdb_basic_commands[0]>(10)test_function_2()->'BAZ' |
| 184 | -> return foo.upper() |
| 185 | (Pdb) retval |
| 186 | 'BAZ' |
Rémi Lapeyre | bf457c7 | 2019-05-21 00:17:30 +0200 | [diff] [blame] | 187 | (Pdb) next |
Rémi Lapeyre | 4585603 | 2019-05-24 22:44:31 +0200 | [diff] [blame] | 188 | > <doctest test.test_pdb.test_pdb_basic_commands[3]>(4)test_function() |
Rémi Lapeyre | bf457c7 | 2019-05-21 00:17:30 +0200 | [diff] [blame] | 189 | -> test_function3(kwonly=True) |
| 190 | (Pdb) step |
| 191 | --Call-- |
| 192 | > <doctest test.test_pdb.test_pdb_basic_commands[1]>(1)test_function3() |
| 193 | -> def test_function3(arg=None, *, kwonly=None): |
| 194 | (Pdb) args |
| 195 | arg = None |
| 196 | kwonly = True |
Rémi Lapeyre | 4585603 | 2019-05-24 22:44:31 +0200 | [diff] [blame] | 197 | (Pdb) return |
| 198 | --Return-- |
| 199 | > <doctest test.test_pdb.test_pdb_basic_commands[1]>(2)test_function3()->None |
| 200 | -> pass |
| 201 | (Pdb) next |
| 202 | > <doctest test.test_pdb.test_pdb_basic_commands[3]>(5)test_function() |
| 203 | -> test_function4(1, 2, 3) |
| 204 | (Pdb) step |
| 205 | --Call-- |
| 206 | > <doctest test.test_pdb.test_pdb_basic_commands[2]>(1)test_function4() |
| 207 | -> def test_function4(a, b, c, /): |
| 208 | (Pdb) args |
| 209 | a = 1 |
| 210 | b = 2 |
| 211 | c = 3 |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 212 | (Pdb) continue |
| 213 | BAZ |
| 214 | """ |
| 215 | |
| 216 | |
| 217 | def test_pdb_breakpoint_commands(): |
| 218 | """Test basic commands related to breakpoints. |
| 219 | |
| 220 | >>> def test_function(): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 221 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 222 | ... print(1) |
| 223 | ... print(2) |
| 224 | ... print(3) |
| 225 | ... print(4) |
| 226 | |
| 227 | First, need to clear bdb state that might be left over from previous tests. |
| 228 | Otherwise, the new breakpoints might get assigned different numbers. |
| 229 | |
| 230 | >>> from bdb import Breakpoint |
| 231 | >>> Breakpoint.next = 1 |
| 232 | >>> Breakpoint.bplist = {} |
| 233 | >>> Breakpoint.bpbynumber = [None] |
| 234 | |
| 235 | Now test the breakpoint commands. NORMALIZE_WHITESPACE is needed because |
| 236 | the breakpoint list outputs a tab for the "stop only" and "ignore next" |
| 237 | lines, which we don't want to put in here. |
| 238 | |
| 239 | >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE |
| 240 | ... 'break 3', |
| 241 | ... 'disable 1', |
| 242 | ... 'ignore 1 10', |
| 243 | ... 'condition 1 1 < 2', |
| 244 | ... 'break 4', |
Senthil Kumaran | 6f10704 | 2010-11-29 11:54:17 +0000 | [diff] [blame] | 245 | ... 'break 4', |
| 246 | ... 'break', |
| 247 | ... 'clear 3', |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 248 | ... 'break', |
| 249 | ... 'condition 1', |
| 250 | ... 'enable 1', |
| 251 | ... 'clear 1', |
| 252 | ... 'commands 2', |
R David Murray | 78d692f | 2013-10-10 17:23:26 -0400 | [diff] [blame] | 253 | ... 'p "42"', |
| 254 | ... 'print("42", 7*6)', # Issue 18764 (not about breakpoints) |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 255 | ... 'end', |
| 256 | ... 'continue', # will stop at breakpoint 2 (line 4) |
| 257 | ... 'clear', # clear all! |
| 258 | ... 'y', |
| 259 | ... 'tbreak 5', |
| 260 | ... 'continue', # will stop at temporary breakpoint |
| 261 | ... 'break', # make sure breakpoint is gone |
| 262 | ... 'continue', |
| 263 | ... ]): |
| 264 | ... test_function() |
| 265 | > <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(3)test_function() |
| 266 | -> print(1) |
| 267 | (Pdb) break 3 |
| 268 | Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3 |
| 269 | (Pdb) disable 1 |
| 270 | Disabled breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3 |
| 271 | (Pdb) ignore 1 10 |
| 272 | Will ignore next 10 crossings of breakpoint 1. |
| 273 | (Pdb) condition 1 1 < 2 |
| 274 | New condition set for breakpoint 1. |
| 275 | (Pdb) break 4 |
| 276 | Breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4 |
Senthil Kumaran | 6f10704 | 2010-11-29 11:54:17 +0000 | [diff] [blame] | 277 | (Pdb) break 4 |
| 278 | Breakpoint 3 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4 |
| 279 | (Pdb) break |
| 280 | Num Type Disp Enb Where |
| 281 | 1 breakpoint keep no at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3 |
| 282 | stop only if 1 < 2 |
| 283 | ignore next 10 hits |
| 284 | 2 breakpoint keep yes at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4 |
| 285 | 3 breakpoint keep yes at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4 |
| 286 | (Pdb) clear 3 |
| 287 | Deleted breakpoint 3 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4 |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 288 | (Pdb) break |
| 289 | Num Type Disp Enb Where |
| 290 | 1 breakpoint keep no at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3 |
| 291 | stop only if 1 < 2 |
| 292 | ignore next 10 hits |
| 293 | 2 breakpoint keep yes at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4 |
| 294 | (Pdb) condition 1 |
| 295 | Breakpoint 1 is now unconditional. |
| 296 | (Pdb) enable 1 |
| 297 | Enabled breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3 |
| 298 | (Pdb) clear 1 |
| 299 | Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3 |
| 300 | (Pdb) commands 2 |
R David Murray | 78d692f | 2013-10-10 17:23:26 -0400 | [diff] [blame] | 301 | (com) p "42" |
| 302 | (com) print("42", 7*6) |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 303 | (com) end |
| 304 | (Pdb) continue |
| 305 | 1 |
R David Murray | 78d692f | 2013-10-10 17:23:26 -0400 | [diff] [blame] | 306 | '42' |
| 307 | 42 42 |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 308 | > <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(4)test_function() |
| 309 | -> print(2) |
| 310 | (Pdb) clear |
| 311 | Clear all breaks? y |
| 312 | Deleted breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4 |
| 313 | (Pdb) tbreak 5 |
Senthil Kumaran | 6f10704 | 2010-11-29 11:54:17 +0000 | [diff] [blame] | 314 | Breakpoint 4 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:5 |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 315 | (Pdb) continue |
| 316 | 2 |
Senthil Kumaran | 6f10704 | 2010-11-29 11:54:17 +0000 | [diff] [blame] | 317 | Deleted breakpoint 4 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:5 |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 318 | > <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(5)test_function() |
| 319 | -> print(3) |
| 320 | (Pdb) break |
| 321 | (Pdb) continue |
| 322 | 3 |
| 323 | 4 |
| 324 | """ |
| 325 | |
| 326 | |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 327 | def do_nothing(): |
| 328 | pass |
| 329 | |
| 330 | def do_something(): |
| 331 | print(42) |
| 332 | |
| 333 | def test_list_commands(): |
| 334 | """Test the list and source commands of pdb. |
| 335 | |
| 336 | >>> def test_function_2(foo): |
Georg Brandl | a8fbc6a | 2010-07-31 11:52:46 +0000 | [diff] [blame] | 337 | ... import test.test_pdb |
| 338 | ... test.test_pdb.do_nothing() |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 339 | ... 'some...' |
| 340 | ... 'more...' |
| 341 | ... 'code...' |
| 342 | ... 'to...' |
| 343 | ... 'make...' |
| 344 | ... 'a...' |
| 345 | ... 'long...' |
| 346 | ... 'listing...' |
| 347 | ... 'useful...' |
| 348 | ... '...' |
| 349 | ... '...' |
| 350 | ... return foo |
| 351 | |
| 352 | >>> def test_function(): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 353 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 354 | ... ret = test_function_2('baz') |
| 355 | |
| 356 | >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE |
| 357 | ... 'list', # list first function |
| 358 | ... 'step', # step into second function |
| 359 | ... 'list', # list second function |
| 360 | ... 'list', # continue listing to EOF |
| 361 | ... 'list 1,3', # list specific lines |
| 362 | ... 'list x', # invalid argument |
| 363 | ... 'next', # step to import |
| 364 | ... 'next', # step over import |
| 365 | ... 'step', # step into do_nothing |
| 366 | ... 'longlist', # list all lines |
| 367 | ... 'source do_something', # list all lines of function |
Georg Brandl | cdf66a9 | 2010-07-30 18:15:16 +0000 | [diff] [blame] | 368 | ... 'source fooxxx', # something that doesn't exit |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 369 | ... 'continue', |
| 370 | ... ]): |
| 371 | ... test_function() |
| 372 | > <doctest test.test_pdb.test_list_commands[1]>(3)test_function() |
| 373 | -> ret = test_function_2('baz') |
| 374 | (Pdb) list |
| 375 | 1 def test_function(): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 376 | 2 import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 377 | 3 -> ret = test_function_2('baz') |
| 378 | [EOF] |
| 379 | (Pdb) step |
| 380 | --Call-- |
| 381 | > <doctest test.test_pdb.test_list_commands[0]>(1)test_function_2() |
| 382 | -> def test_function_2(foo): |
| 383 | (Pdb) list |
| 384 | 1 -> def test_function_2(foo): |
Georg Brandl | a8fbc6a | 2010-07-31 11:52:46 +0000 | [diff] [blame] | 385 | 2 import test.test_pdb |
| 386 | 3 test.test_pdb.do_nothing() |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 387 | 4 'some...' |
| 388 | 5 'more...' |
| 389 | 6 'code...' |
| 390 | 7 'to...' |
| 391 | 8 'make...' |
| 392 | 9 'a...' |
| 393 | 10 'long...' |
| 394 | 11 'listing...' |
| 395 | (Pdb) list |
| 396 | 12 'useful...' |
| 397 | 13 '...' |
| 398 | 14 '...' |
| 399 | 15 return foo |
| 400 | [EOF] |
| 401 | (Pdb) list 1,3 |
| 402 | 1 -> def test_function_2(foo): |
Georg Brandl | a8fbc6a | 2010-07-31 11:52:46 +0000 | [diff] [blame] | 403 | 2 import test.test_pdb |
| 404 | 3 test.test_pdb.do_nothing() |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 405 | (Pdb) list x |
| 406 | *** ... |
| 407 | (Pdb) next |
| 408 | > <doctest test.test_pdb.test_list_commands[0]>(2)test_function_2() |
Georg Brandl | a8fbc6a | 2010-07-31 11:52:46 +0000 | [diff] [blame] | 409 | -> import test.test_pdb |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 410 | (Pdb) next |
| 411 | > <doctest test.test_pdb.test_list_commands[0]>(3)test_function_2() |
Georg Brandl | a8fbc6a | 2010-07-31 11:52:46 +0000 | [diff] [blame] | 412 | -> test.test_pdb.do_nothing() |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 413 | (Pdb) step |
| 414 | --Call-- |
Georg Brandl | e1e8df1 | 2010-07-31 08:14:16 +0000 | [diff] [blame] | 415 | > ...test_pdb.py(...)do_nothing() |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 416 | -> def do_nothing(): |
| 417 | (Pdb) longlist |
| 418 | ... -> def do_nothing(): |
| 419 | ... pass |
| 420 | (Pdb) source do_something |
| 421 | ... def do_something(): |
| 422 | ... print(42) |
Georg Brandl | cdf66a9 | 2010-07-30 18:15:16 +0000 | [diff] [blame] | 423 | (Pdb) source fooxxx |
| 424 | *** ... |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 425 | (Pdb) continue |
| 426 | """ |
| 427 | |
| 428 | |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 429 | def test_post_mortem(): |
| 430 | """Test post mortem traceback debugging. |
| 431 | |
| 432 | >>> def test_function_2(): |
| 433 | ... try: |
| 434 | ... 1/0 |
| 435 | ... finally: |
| 436 | ... print('Exception!') |
| 437 | |
| 438 | >>> def test_function(): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 439 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 440 | ... test_function_2() |
| 441 | ... print('Not reached.') |
| 442 | |
| 443 | >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE |
| 444 | ... 'next', # step over exception-raising call |
| 445 | ... 'bt', # get a backtrace |
| 446 | ... 'list', # list code of test_function() |
| 447 | ... 'down', # step into test_function_2() |
| 448 | ... 'list', # list code of test_function_2() |
| 449 | ... 'continue', |
| 450 | ... ]): |
| 451 | ... try: |
| 452 | ... test_function() |
| 453 | ... except ZeroDivisionError: |
| 454 | ... print('Correctly reraised.') |
| 455 | > <doctest test.test_pdb.test_post_mortem[1]>(3)test_function() |
| 456 | -> test_function_2() |
| 457 | (Pdb) next |
| 458 | Exception! |
| 459 | ZeroDivisionError: division by zero |
| 460 | > <doctest test.test_pdb.test_post_mortem[1]>(3)test_function() |
| 461 | -> test_function_2() |
| 462 | (Pdb) bt |
| 463 | ... |
| 464 | <doctest test.test_pdb.test_post_mortem[2]>(10)<module>() |
| 465 | -> test_function() |
| 466 | > <doctest test.test_pdb.test_post_mortem[1]>(3)test_function() |
| 467 | -> test_function_2() |
| 468 | <doctest test.test_pdb.test_post_mortem[0]>(3)test_function_2() |
| 469 | -> 1/0 |
| 470 | (Pdb) list |
| 471 | 1 def test_function(): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 472 | 2 import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 473 | 3 -> test_function_2() |
| 474 | 4 print('Not reached.') |
| 475 | [EOF] |
| 476 | (Pdb) down |
| 477 | > <doctest test.test_pdb.test_post_mortem[0]>(3)test_function_2() |
| 478 | -> 1/0 |
| 479 | (Pdb) list |
| 480 | 1 def test_function_2(): |
| 481 | 2 try: |
| 482 | 3 >> 1/0 |
| 483 | 4 finally: |
| 484 | 5 -> print('Exception!') |
| 485 | [EOF] |
| 486 | (Pdb) continue |
| 487 | Correctly reraised. |
| 488 | """ |
| 489 | |
| 490 | |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 491 | def test_pdb_skip_modules(): |
| 492 | """This illustrates the simple case of module skipping. |
| 493 | |
| 494 | >>> def skip_module(): |
| 495 | ... import string |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 496 | ... import pdb; pdb.Pdb(skip=['stri*'], nosigint=True, readrc=False).set_trace() |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 497 | ... string.capwords('FOO') |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 498 | |
Georg Brandl | 9fa2e02 | 2009-09-16 16:40:45 +0000 | [diff] [blame] | 499 | >>> with PdbTestInput([ |
| 500 | ... 'step', |
| 501 | ... 'continue', |
| 502 | ... ]): |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 503 | ... skip_module() |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 504 | > <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module() |
| 505 | -> string.capwords('FOO') |
| 506 | (Pdb) step |
| 507 | --Return-- |
| 508 | > <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()->None |
| 509 | -> string.capwords('FOO') |
| 510 | (Pdb) continue |
Georg Brandl | 9fa2e02 | 2009-09-16 16:40:45 +0000 | [diff] [blame] | 511 | """ |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 512 | |
| 513 | |
| 514 | # Module for testing skipping of module that makes a callback |
Brett Cannon | 9529fbf | 2013-06-15 17:11:25 -0400 | [diff] [blame] | 515 | mod = types.ModuleType('module_to_skip') |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 516 | exec('def foo_pony(callback): x = 1; callback(); return None', mod.__dict__) |
| 517 | |
| 518 | |
| 519 | def test_pdb_skip_modules_with_callback(): |
| 520 | """This illustrates skipping of modules that call into other code. |
| 521 | |
| 522 | >>> def skip_module(): |
| 523 | ... def callback(): |
| 524 | ... return None |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 525 | ... import pdb; pdb.Pdb(skip=['module_to_skip*'], nosigint=True, readrc=False).set_trace() |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 526 | ... mod.foo_pony(callback) |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 527 | |
Georg Brandl | 9fa2e02 | 2009-09-16 16:40:45 +0000 | [diff] [blame] | 528 | >>> with PdbTestInput([ |
| 529 | ... 'step', |
| 530 | ... 'step', |
| 531 | ... 'step', |
| 532 | ... 'step', |
| 533 | ... 'step', |
| 534 | ... 'continue', |
| 535 | ... ]): |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 536 | ... skip_module() |
Georg Brandl | 9fa2e02 | 2009-09-16 16:40:45 +0000 | [diff] [blame] | 537 | ... pass # provides something to "step" to |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 538 | > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module() |
| 539 | -> mod.foo_pony(callback) |
| 540 | (Pdb) step |
| 541 | --Call-- |
| 542 | > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(2)callback() |
| 543 | -> def callback(): |
| 544 | (Pdb) step |
| 545 | > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(3)callback() |
| 546 | -> return None |
| 547 | (Pdb) step |
| 548 | --Return-- |
| 549 | > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(3)callback()->None |
| 550 | -> return None |
| 551 | (Pdb) step |
| 552 | --Return-- |
| 553 | > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()->None |
| 554 | -> mod.foo_pony(callback) |
| 555 | (Pdb) step |
Georg Brandl | 9fa2e02 | 2009-09-16 16:40:45 +0000 | [diff] [blame] | 556 | > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[1]>(10)<module>() |
| 557 | -> pass # provides something to "step" to |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 558 | (Pdb) continue |
Georg Brandl | 9fa2e02 | 2009-09-16 16:40:45 +0000 | [diff] [blame] | 559 | """ |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 560 | |
| 561 | |
Georg Brandl | 3f94089 | 2010-07-30 10:29:19 +0000 | [diff] [blame] | 562 | def test_pdb_continue_in_bottomframe(): |
| 563 | """Test that "continue" and "next" work properly in bottom frame (issue #5294). |
| 564 | |
| 565 | >>> def test_function(): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 566 | ... import pdb, sys; inst = pdb.Pdb(nosigint=True, readrc=False) |
Georg Brandl | 3f94089 | 2010-07-30 10:29:19 +0000 | [diff] [blame] | 567 | ... inst.set_trace() |
| 568 | ... inst.botframe = sys._getframe() # hackery to get the right botframe |
| 569 | ... print(1) |
| 570 | ... print(2) |
| 571 | ... print(3) |
| 572 | ... print(4) |
| 573 | |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 574 | >>> with PdbTestInput([ # doctest: +ELLIPSIS |
Georg Brandl | 3f94089 | 2010-07-30 10:29:19 +0000 | [diff] [blame] | 575 | ... 'next', |
| 576 | ... 'break 7', |
| 577 | ... 'continue', |
| 578 | ... 'next', |
| 579 | ... 'continue', |
| 580 | ... 'continue', |
| 581 | ... ]): |
| 582 | ... test_function() |
| 583 | > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(4)test_function() |
| 584 | -> inst.botframe = sys._getframe() # hackery to get the right botframe |
| 585 | (Pdb) next |
| 586 | > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(5)test_function() |
| 587 | -> print(1) |
| 588 | (Pdb) break 7 |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 589 | Breakpoint ... at <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>:7 |
Georg Brandl | 3f94089 | 2010-07-30 10:29:19 +0000 | [diff] [blame] | 590 | (Pdb) continue |
| 591 | 1 |
| 592 | 2 |
| 593 | > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(7)test_function() |
| 594 | -> print(3) |
| 595 | (Pdb) next |
| 596 | 3 |
| 597 | > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(8)test_function() |
| 598 | -> print(4) |
| 599 | (Pdb) continue |
| 600 | 4 |
| 601 | """ |
| 602 | |
| 603 | |
Georg Brandl | 46b9afc | 2010-07-30 09:14:20 +0000 | [diff] [blame] | 604 | def pdb_invoke(method, arg): |
| 605 | """Run pdb.method(arg).""" |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 606 | getattr(pdb.Pdb(nosigint=True, readrc=False), method)(arg) |
Georg Brandl | 46b9afc | 2010-07-30 09:14:20 +0000 | [diff] [blame] | 607 | |
| 608 | |
| 609 | def test_pdb_run_with_incorrect_argument(): |
| 610 | """Testing run and runeval with incorrect first argument. |
| 611 | |
| 612 | >>> pti = PdbTestInput(['continue',]) |
| 613 | >>> with pti: |
| 614 | ... pdb_invoke('run', lambda x: x) |
| 615 | Traceback (most recent call last): |
| 616 | TypeError: exec() arg 1 must be a string, bytes or code object |
| 617 | |
| 618 | >>> with pti: |
| 619 | ... pdb_invoke('runeval', lambda x: x) |
| 620 | Traceback (most recent call last): |
| 621 | TypeError: eval() arg 1 must be a string, bytes or code object |
| 622 | """ |
| 623 | |
| 624 | |
| 625 | def test_pdb_run_with_code_object(): |
| 626 | """Testing run and runeval with code object as a first argument. |
| 627 | |
Georg Brandl | e1e8df1 | 2010-07-31 08:14:16 +0000 | [diff] [blame] | 628 | >>> with PdbTestInput(['step','x', 'continue']): # doctest: +ELLIPSIS |
Georg Brandl | 46b9afc | 2010-07-30 09:14:20 +0000 | [diff] [blame] | 629 | ... pdb_invoke('run', compile('x=1', '<string>', 'exec')) |
Georg Brandl | e1e8df1 | 2010-07-31 08:14:16 +0000 | [diff] [blame] | 630 | > <string>(1)<module>()... |
Georg Brandl | 46b9afc | 2010-07-30 09:14:20 +0000 | [diff] [blame] | 631 | (Pdb) step |
| 632 | --Return-- |
| 633 | > <string>(1)<module>()->None |
| 634 | (Pdb) x |
| 635 | 1 |
| 636 | (Pdb) continue |
| 637 | |
| 638 | >>> with PdbTestInput(['x', 'continue']): |
| 639 | ... x=0 |
| 640 | ... pdb_invoke('runeval', compile('x+1', '<string>', 'eval')) |
| 641 | > <string>(1)<module>()->None |
| 642 | (Pdb) x |
| 643 | 1 |
| 644 | (Pdb) continue |
| 645 | """ |
| 646 | |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 647 | def test_next_until_return_at_return_event(): |
| 648 | """Test that pdb stops after a next/until/return issued at a return debug event. |
| 649 | |
| 650 | >>> def test_function_2(): |
| 651 | ... x = 1 |
| 652 | ... x = 2 |
| 653 | |
| 654 | >>> def test_function(): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 655 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 656 | ... test_function_2() |
| 657 | ... test_function_2() |
| 658 | ... test_function_2() |
| 659 | ... end = 1 |
| 660 | |
Antoine Pitrou | c04d468 | 2014-08-11 21:40:38 -0400 | [diff] [blame] | 661 | >>> from bdb import Breakpoint |
| 662 | >>> Breakpoint.next = 1 |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 663 | >>> with PdbTestInput(['break test_function_2', |
| 664 | ... 'continue', |
| 665 | ... 'return', |
| 666 | ... 'next', |
| 667 | ... 'continue', |
| 668 | ... 'return', |
| 669 | ... 'until', |
| 670 | ... 'continue', |
| 671 | ... 'return', |
| 672 | ... 'return', |
| 673 | ... 'continue']): |
| 674 | ... test_function() |
| 675 | > <doctest test.test_pdb.test_next_until_return_at_return_event[1]>(3)test_function() |
| 676 | -> test_function_2() |
| 677 | (Pdb) break test_function_2 |
| 678 | Breakpoint 1 at <doctest test.test_pdb.test_next_until_return_at_return_event[0]>:1 |
| 679 | (Pdb) continue |
| 680 | > <doctest test.test_pdb.test_next_until_return_at_return_event[0]>(2)test_function_2() |
| 681 | -> x = 1 |
| 682 | (Pdb) return |
| 683 | --Return-- |
| 684 | > <doctest test.test_pdb.test_next_until_return_at_return_event[0]>(3)test_function_2()->None |
| 685 | -> x = 2 |
| 686 | (Pdb) next |
| 687 | > <doctest test.test_pdb.test_next_until_return_at_return_event[1]>(4)test_function() |
| 688 | -> test_function_2() |
| 689 | (Pdb) continue |
| 690 | > <doctest test.test_pdb.test_next_until_return_at_return_event[0]>(2)test_function_2() |
| 691 | -> x = 1 |
| 692 | (Pdb) return |
| 693 | --Return-- |
| 694 | > <doctest test.test_pdb.test_next_until_return_at_return_event[0]>(3)test_function_2()->None |
| 695 | -> x = 2 |
| 696 | (Pdb) until |
| 697 | > <doctest test.test_pdb.test_next_until_return_at_return_event[1]>(5)test_function() |
| 698 | -> test_function_2() |
| 699 | (Pdb) continue |
| 700 | > <doctest test.test_pdb.test_next_until_return_at_return_event[0]>(2)test_function_2() |
| 701 | -> x = 1 |
| 702 | (Pdb) return |
| 703 | --Return-- |
| 704 | > <doctest test.test_pdb.test_next_until_return_at_return_event[0]>(3)test_function_2()->None |
| 705 | -> x = 2 |
| 706 | (Pdb) return |
| 707 | > <doctest test.test_pdb.test_next_until_return_at_return_event[1]>(6)test_function() |
| 708 | -> end = 1 |
| 709 | (Pdb) continue |
| 710 | """ |
| 711 | |
| 712 | def test_pdb_next_command_for_generator(): |
| 713 | """Testing skip unwindng stack on yield for generators for "next" command |
| 714 | |
| 715 | >>> def test_gen(): |
| 716 | ... yield 0 |
| 717 | ... return 1 |
| 718 | ... yield 2 |
| 719 | |
| 720 | >>> def test_function(): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 721 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 722 | ... it = test_gen() |
| 723 | ... try: |
Serhiy Storchaka | a16de5d | 2015-04-01 16:58:19 +0300 | [diff] [blame] | 724 | ... if next(it) != 0: |
| 725 | ... raise AssertionError |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 726 | ... next(it) |
| 727 | ... except StopIteration as ex: |
Serhiy Storchaka | a16de5d | 2015-04-01 16:58:19 +0300 | [diff] [blame] | 728 | ... if ex.value != 1: |
| 729 | ... raise AssertionError |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 730 | ... print("finished") |
| 731 | |
| 732 | >>> with PdbTestInput(['step', |
| 733 | ... 'step', |
| 734 | ... 'step', |
| 735 | ... 'next', |
| 736 | ... 'next', |
| 737 | ... 'step', |
| 738 | ... 'step', |
| 739 | ... 'continue']): |
| 740 | ... test_function() |
| 741 | > <doctest test.test_pdb.test_pdb_next_command_for_generator[1]>(3)test_function() |
| 742 | -> it = test_gen() |
| 743 | (Pdb) step |
| 744 | > <doctest test.test_pdb.test_pdb_next_command_for_generator[1]>(4)test_function() |
| 745 | -> try: |
| 746 | (Pdb) step |
| 747 | > <doctest test.test_pdb.test_pdb_next_command_for_generator[1]>(5)test_function() |
Serhiy Storchaka | a16de5d | 2015-04-01 16:58:19 +0300 | [diff] [blame] | 748 | -> if next(it) != 0: |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 749 | (Pdb) step |
| 750 | --Call-- |
| 751 | > <doctest test.test_pdb.test_pdb_next_command_for_generator[0]>(1)test_gen() |
| 752 | -> def test_gen(): |
| 753 | (Pdb) next |
| 754 | > <doctest test.test_pdb.test_pdb_next_command_for_generator[0]>(2)test_gen() |
| 755 | -> yield 0 |
| 756 | (Pdb) next |
| 757 | > <doctest test.test_pdb.test_pdb_next_command_for_generator[0]>(3)test_gen() |
| 758 | -> return 1 |
| 759 | (Pdb) step |
| 760 | --Return-- |
| 761 | > <doctest test.test_pdb.test_pdb_next_command_for_generator[0]>(3)test_gen()->1 |
| 762 | -> return 1 |
| 763 | (Pdb) step |
| 764 | StopIteration: 1 |
Serhiy Storchaka | a16de5d | 2015-04-01 16:58:19 +0300 | [diff] [blame] | 765 | > <doctest test.test_pdb.test_pdb_next_command_for_generator[1]>(7)test_function() |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 766 | -> next(it) |
| 767 | (Pdb) continue |
| 768 | finished |
| 769 | """ |
| 770 | |
Pablo Galindo | 4687702 | 2018-01-29 00:25:05 +0000 | [diff] [blame] | 771 | def test_pdb_next_command_for_coroutine(): |
| 772 | """Testing skip unwindng stack on yield for coroutines for "next" command |
| 773 | |
| 774 | >>> import asyncio |
| 775 | |
| 776 | >>> async def test_coro(): |
| 777 | ... await asyncio.sleep(0) |
| 778 | ... await asyncio.sleep(0) |
| 779 | ... await asyncio.sleep(0) |
| 780 | |
| 781 | >>> async def test_main(): |
| 782 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
| 783 | ... await test_coro() |
| 784 | |
| 785 | >>> def test_function(): |
Pablo Galindo | c7ab581 | 2018-01-29 01:31:00 +0000 | [diff] [blame] | 786 | ... loop = asyncio.new_event_loop() |
Pablo Galindo | 4687702 | 2018-01-29 00:25:05 +0000 | [diff] [blame] | 787 | ... loop.run_until_complete(test_main()) |
| 788 | ... loop.close() |
Brett Cannon | 8425de4 | 2018-06-01 20:34:09 -0700 | [diff] [blame] | 789 | ... asyncio.set_event_loop_policy(None) |
Pablo Galindo | 4687702 | 2018-01-29 00:25:05 +0000 | [diff] [blame] | 790 | ... print("finished") |
| 791 | |
| 792 | >>> with PdbTestInput(['step', |
| 793 | ... 'step', |
| 794 | ... 'next', |
| 795 | ... 'next', |
| 796 | ... 'next', |
| 797 | ... 'step', |
| 798 | ... 'continue']): |
| 799 | ... test_function() |
| 800 | > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[2]>(3)test_main() |
| 801 | -> await test_coro() |
| 802 | (Pdb) step |
| 803 | --Call-- |
| 804 | > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(1)test_coro() |
| 805 | -> async def test_coro(): |
| 806 | (Pdb) step |
| 807 | > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(2)test_coro() |
| 808 | -> await asyncio.sleep(0) |
| 809 | (Pdb) next |
| 810 | > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(3)test_coro() |
| 811 | -> await asyncio.sleep(0) |
| 812 | (Pdb) next |
| 813 | > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(4)test_coro() |
| 814 | -> await asyncio.sleep(0) |
| 815 | (Pdb) next |
| 816 | Internal StopIteration |
| 817 | > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[2]>(3)test_main() |
| 818 | -> await test_coro() |
| 819 | (Pdb) step |
| 820 | --Return-- |
| 821 | > <doctest test.test_pdb.test_pdb_next_command_for_coroutine[2]>(3)test_main()->None |
| 822 | -> await test_coro() |
| 823 | (Pdb) continue |
| 824 | finished |
| 825 | """ |
| 826 | |
Yury Selivanov | 9ee1bf9 | 2018-01-28 22:43:46 -0500 | [diff] [blame] | 827 | def test_pdb_next_command_for_asyncgen(): |
| 828 | """Testing skip unwindng stack on yield for coroutines for "next" command |
| 829 | |
| 830 | >>> import asyncio |
| 831 | |
| 832 | >>> async def agen(): |
| 833 | ... yield 1 |
| 834 | ... await asyncio.sleep(0) |
| 835 | ... yield 2 |
| 836 | |
| 837 | >>> async def test_coro(): |
| 838 | ... async for x in agen(): |
| 839 | ... print(x) |
| 840 | |
| 841 | >>> async def test_main(): |
| 842 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
| 843 | ... await test_coro() |
| 844 | |
| 845 | >>> def test_function(): |
| 846 | ... loop = asyncio.new_event_loop() |
| 847 | ... loop.run_until_complete(test_main()) |
| 848 | ... loop.close() |
Brett Cannon | 8425de4 | 2018-06-01 20:34:09 -0700 | [diff] [blame] | 849 | ... asyncio.set_event_loop_policy(None) |
Yury Selivanov | 9ee1bf9 | 2018-01-28 22:43:46 -0500 | [diff] [blame] | 850 | ... print("finished") |
| 851 | |
| 852 | >>> with PdbTestInput(['step', |
| 853 | ... 'step', |
| 854 | ... 'next', |
| 855 | ... 'next', |
| 856 | ... 'step', |
| 857 | ... 'next', |
| 858 | ... 'continue']): |
| 859 | ... test_function() |
| 860 | > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[3]>(3)test_main() |
| 861 | -> await test_coro() |
| 862 | (Pdb) step |
| 863 | --Call-- |
| 864 | > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(1)test_coro() |
| 865 | -> async def test_coro(): |
| 866 | (Pdb) step |
| 867 | > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(2)test_coro() |
| 868 | -> async for x in agen(): |
| 869 | (Pdb) next |
| 870 | > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(3)test_coro() |
| 871 | -> print(x) |
| 872 | (Pdb) next |
| 873 | 1 |
| 874 | > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[2]>(2)test_coro() |
| 875 | -> async for x in agen(): |
| 876 | (Pdb) step |
| 877 | --Call-- |
| 878 | > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[1]>(2)agen() |
| 879 | -> yield 1 |
| 880 | (Pdb) next |
| 881 | > <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[1]>(3)agen() |
| 882 | -> await asyncio.sleep(0) |
| 883 | (Pdb) continue |
| 884 | 2 |
| 885 | finished |
| 886 | """ |
| 887 | |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 888 | def test_pdb_return_command_for_generator(): |
| 889 | """Testing no unwindng stack on yield for generators |
| 890 | for "return" command |
| 891 | |
| 892 | >>> def test_gen(): |
| 893 | ... yield 0 |
| 894 | ... return 1 |
| 895 | ... yield 2 |
| 896 | |
| 897 | >>> def test_function(): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 898 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 899 | ... it = test_gen() |
| 900 | ... try: |
Serhiy Storchaka | a16de5d | 2015-04-01 16:58:19 +0300 | [diff] [blame] | 901 | ... if next(it) != 0: |
| 902 | ... raise AssertionError |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 903 | ... next(it) |
| 904 | ... except StopIteration as ex: |
Serhiy Storchaka | a16de5d | 2015-04-01 16:58:19 +0300 | [diff] [blame] | 905 | ... if ex.value != 1: |
| 906 | ... raise AssertionError |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 907 | ... print("finished") |
| 908 | |
| 909 | >>> with PdbTestInput(['step', |
| 910 | ... 'step', |
| 911 | ... 'step', |
| 912 | ... 'return', |
| 913 | ... 'step', |
| 914 | ... 'step', |
| 915 | ... 'continue']): |
| 916 | ... test_function() |
| 917 | > <doctest test.test_pdb.test_pdb_return_command_for_generator[1]>(3)test_function() |
| 918 | -> it = test_gen() |
| 919 | (Pdb) step |
| 920 | > <doctest test.test_pdb.test_pdb_return_command_for_generator[1]>(4)test_function() |
| 921 | -> try: |
| 922 | (Pdb) step |
| 923 | > <doctest test.test_pdb.test_pdb_return_command_for_generator[1]>(5)test_function() |
Serhiy Storchaka | a16de5d | 2015-04-01 16:58:19 +0300 | [diff] [blame] | 924 | -> if next(it) != 0: |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 925 | (Pdb) step |
| 926 | --Call-- |
| 927 | > <doctest test.test_pdb.test_pdb_return_command_for_generator[0]>(1)test_gen() |
| 928 | -> def test_gen(): |
| 929 | (Pdb) return |
| 930 | StopIteration: 1 |
Serhiy Storchaka | a16de5d | 2015-04-01 16:58:19 +0300 | [diff] [blame] | 931 | > <doctest test.test_pdb.test_pdb_return_command_for_generator[1]>(7)test_function() |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 932 | -> next(it) |
| 933 | (Pdb) step |
Serhiy Storchaka | a16de5d | 2015-04-01 16:58:19 +0300 | [diff] [blame] | 934 | > <doctest test.test_pdb.test_pdb_return_command_for_generator[1]>(8)test_function() |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 935 | -> except StopIteration as ex: |
| 936 | (Pdb) step |
Serhiy Storchaka | a16de5d | 2015-04-01 16:58:19 +0300 | [diff] [blame] | 937 | > <doctest test.test_pdb.test_pdb_return_command_for_generator[1]>(9)test_function() |
| 938 | -> if ex.value != 1: |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 939 | (Pdb) continue |
| 940 | finished |
| 941 | """ |
| 942 | |
Pablo Galindo | c7ab581 | 2018-01-29 01:31:00 +0000 | [diff] [blame] | 943 | def test_pdb_return_command_for_coroutine(): |
| 944 | """Testing no unwindng stack on yield for coroutines for "return" command |
| 945 | |
| 946 | >>> import asyncio |
| 947 | |
| 948 | >>> async def test_coro(): |
| 949 | ... await asyncio.sleep(0) |
| 950 | ... await asyncio.sleep(0) |
| 951 | ... await asyncio.sleep(0) |
| 952 | |
| 953 | >>> async def test_main(): |
| 954 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
| 955 | ... await test_coro() |
| 956 | |
| 957 | >>> def test_function(): |
| 958 | ... loop = asyncio.new_event_loop() |
| 959 | ... loop.run_until_complete(test_main()) |
| 960 | ... loop.close() |
Brett Cannon | 8425de4 | 2018-06-01 20:34:09 -0700 | [diff] [blame] | 961 | ... asyncio.set_event_loop_policy(None) |
Pablo Galindo | c7ab581 | 2018-01-29 01:31:00 +0000 | [diff] [blame] | 962 | ... print("finished") |
| 963 | |
| 964 | >>> with PdbTestInput(['step', |
| 965 | ... 'step', |
| 966 | ... 'next', |
| 967 | ... 'continue']): |
| 968 | ... test_function() |
| 969 | > <doctest test.test_pdb.test_pdb_return_command_for_coroutine[2]>(3)test_main() |
| 970 | -> await test_coro() |
| 971 | (Pdb) step |
| 972 | --Call-- |
| 973 | > <doctest test.test_pdb.test_pdb_return_command_for_coroutine[1]>(1)test_coro() |
| 974 | -> async def test_coro(): |
| 975 | (Pdb) step |
| 976 | > <doctest test.test_pdb.test_pdb_return_command_for_coroutine[1]>(2)test_coro() |
| 977 | -> await asyncio.sleep(0) |
| 978 | (Pdb) next |
| 979 | > <doctest test.test_pdb.test_pdb_return_command_for_coroutine[1]>(3)test_coro() |
| 980 | -> await asyncio.sleep(0) |
| 981 | (Pdb) continue |
| 982 | finished |
| 983 | """ |
| 984 | |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 985 | def test_pdb_until_command_for_generator(): |
| 986 | """Testing no unwindng stack on yield for generators |
Min ho Kim | c4cacc8 | 2019-07-31 08:16:13 +1000 | [diff] [blame] | 987 | for "until" command if target breakpoint is not reached |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 988 | |
| 989 | >>> def test_gen(): |
| 990 | ... yield 0 |
| 991 | ... yield 1 |
| 992 | ... yield 2 |
| 993 | |
| 994 | >>> def test_function(): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 995 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 996 | ... for i in test_gen(): |
| 997 | ... print(i) |
| 998 | ... print("finished") |
| 999 | |
| 1000 | >>> with PdbTestInput(['step', |
| 1001 | ... 'until 4', |
| 1002 | ... 'step', |
| 1003 | ... 'step', |
| 1004 | ... 'continue']): |
| 1005 | ... test_function() |
| 1006 | > <doctest test.test_pdb.test_pdb_until_command_for_generator[1]>(3)test_function() |
| 1007 | -> for i in test_gen(): |
| 1008 | (Pdb) step |
| 1009 | --Call-- |
| 1010 | > <doctest test.test_pdb.test_pdb_until_command_for_generator[0]>(1)test_gen() |
| 1011 | -> def test_gen(): |
| 1012 | (Pdb) until 4 |
| 1013 | 0 |
| 1014 | 1 |
| 1015 | > <doctest test.test_pdb.test_pdb_until_command_for_generator[0]>(4)test_gen() |
| 1016 | -> yield 2 |
| 1017 | (Pdb) step |
| 1018 | --Return-- |
| 1019 | > <doctest test.test_pdb.test_pdb_until_command_for_generator[0]>(4)test_gen()->2 |
| 1020 | -> yield 2 |
| 1021 | (Pdb) step |
| 1022 | > <doctest test.test_pdb.test_pdb_until_command_for_generator[1]>(4)test_function() |
| 1023 | -> print(i) |
| 1024 | (Pdb) continue |
| 1025 | 2 |
| 1026 | finished |
| 1027 | """ |
| 1028 | |
Andrew Svetlov | 4f4ef0a | 2018-01-29 16:17:45 +0200 | [diff] [blame] | 1029 | def test_pdb_until_command_for_coroutine(): |
| 1030 | """Testing no unwindng stack for coroutines |
Min ho Kim | c4cacc8 | 2019-07-31 08:16:13 +1000 | [diff] [blame] | 1031 | for "until" command if target breakpoint is not reached |
Andrew Svetlov | 4f4ef0a | 2018-01-29 16:17:45 +0200 | [diff] [blame] | 1032 | |
| 1033 | >>> import asyncio |
| 1034 | |
| 1035 | >>> async def test_coro(): |
| 1036 | ... print(0) |
| 1037 | ... await asyncio.sleep(0) |
| 1038 | ... print(1) |
| 1039 | ... await asyncio.sleep(0) |
| 1040 | ... print(2) |
| 1041 | ... await asyncio.sleep(0) |
| 1042 | ... print(3) |
| 1043 | |
| 1044 | >>> async def test_main(): |
| 1045 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
| 1046 | ... await test_coro() |
| 1047 | |
| 1048 | >>> def test_function(): |
| 1049 | ... loop = asyncio.new_event_loop() |
| 1050 | ... loop.run_until_complete(test_main()) |
| 1051 | ... loop.close() |
Brett Cannon | 8425de4 | 2018-06-01 20:34:09 -0700 | [diff] [blame] | 1052 | ... asyncio.set_event_loop_policy(None) |
Andrew Svetlov | 4f4ef0a | 2018-01-29 16:17:45 +0200 | [diff] [blame] | 1053 | ... print("finished") |
| 1054 | |
| 1055 | >>> with PdbTestInput(['step', |
| 1056 | ... 'until 8', |
| 1057 | ... 'continue']): |
| 1058 | ... test_function() |
| 1059 | > <doctest test.test_pdb.test_pdb_until_command_for_coroutine[2]>(3)test_main() |
| 1060 | -> await test_coro() |
| 1061 | (Pdb) step |
| 1062 | --Call-- |
| 1063 | > <doctest test.test_pdb.test_pdb_until_command_for_coroutine[1]>(1)test_coro() |
| 1064 | -> async def test_coro(): |
| 1065 | (Pdb) until 8 |
| 1066 | 0 |
| 1067 | 1 |
| 1068 | 2 |
| 1069 | > <doctest test.test_pdb.test_pdb_until_command_for_coroutine[1]>(8)test_coro() |
| 1070 | -> print(3) |
| 1071 | (Pdb) continue |
| 1072 | 3 |
| 1073 | finished |
| 1074 | """ |
| 1075 | |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 1076 | def test_pdb_next_command_in_generator_for_loop(): |
Martin Panter | 46f5072 | 2016-05-26 05:35:26 +0000 | [diff] [blame] | 1077 | """The next command on returning from a generator controlled by a for loop. |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 1078 | |
| 1079 | >>> def test_gen(): |
| 1080 | ... yield 0 |
| 1081 | ... return 1 |
| 1082 | |
| 1083 | >>> def test_function(): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 1084 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 1085 | ... for i in test_gen(): |
| 1086 | ... print('value', i) |
| 1087 | ... x = 123 |
| 1088 | |
| 1089 | >>> with PdbTestInput(['break test_gen', |
| 1090 | ... 'continue', |
| 1091 | ... 'next', |
| 1092 | ... 'next', |
| 1093 | ... 'next', |
| 1094 | ... 'continue']): |
| 1095 | ... test_function() |
| 1096 | > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[1]>(3)test_function() |
| 1097 | -> for i in test_gen(): |
| 1098 | (Pdb) break test_gen |
| 1099 | Breakpoint 6 at <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>:1 |
| 1100 | (Pdb) continue |
| 1101 | > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>(2)test_gen() |
| 1102 | -> yield 0 |
| 1103 | (Pdb) next |
| 1104 | value 0 |
| 1105 | > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>(3)test_gen() |
| 1106 | -> return 1 |
| 1107 | (Pdb) next |
| 1108 | Internal StopIteration: 1 |
| 1109 | > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[1]>(3)test_function() |
| 1110 | -> for i in test_gen(): |
| 1111 | (Pdb) next |
| 1112 | > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[1]>(5)test_function() |
| 1113 | -> x = 123 |
| 1114 | (Pdb) continue |
| 1115 | """ |
| 1116 | |
| 1117 | def test_pdb_next_command_subiterator(): |
| 1118 | """The next command in a generator with a subiterator. |
| 1119 | |
| 1120 | >>> def test_subgenerator(): |
| 1121 | ... yield 0 |
| 1122 | ... return 1 |
| 1123 | |
| 1124 | >>> def test_gen(): |
| 1125 | ... x = yield from test_subgenerator() |
| 1126 | ... return x |
| 1127 | |
| 1128 | >>> def test_function(): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 1129 | ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() |
Guido van Rossum | 8820c23 | 2013-11-21 11:30:06 -0800 | [diff] [blame] | 1130 | ... for i in test_gen(): |
| 1131 | ... print('value', i) |
| 1132 | ... x = 123 |
| 1133 | |
| 1134 | >>> with PdbTestInput(['step', |
| 1135 | ... 'step', |
| 1136 | ... 'next', |
| 1137 | ... 'next', |
| 1138 | ... 'next', |
| 1139 | ... 'continue']): |
| 1140 | ... test_function() |
| 1141 | > <doctest test.test_pdb.test_pdb_next_command_subiterator[2]>(3)test_function() |
| 1142 | -> for i in test_gen(): |
| 1143 | (Pdb) step |
| 1144 | --Call-- |
| 1145 | > <doctest test.test_pdb.test_pdb_next_command_subiterator[1]>(1)test_gen() |
| 1146 | -> def test_gen(): |
| 1147 | (Pdb) step |
| 1148 | > <doctest test.test_pdb.test_pdb_next_command_subiterator[1]>(2)test_gen() |
| 1149 | -> x = yield from test_subgenerator() |
| 1150 | (Pdb) next |
| 1151 | value 0 |
| 1152 | > <doctest test.test_pdb.test_pdb_next_command_subiterator[1]>(3)test_gen() |
| 1153 | -> return x |
| 1154 | (Pdb) next |
| 1155 | Internal StopIteration: 1 |
| 1156 | > <doctest test.test_pdb.test_pdb_next_command_subiterator[2]>(3)test_function() |
| 1157 | -> for i in test_gen(): |
| 1158 | (Pdb) next |
| 1159 | > <doctest test.test_pdb.test_pdb_next_command_subiterator[2]>(5)test_function() |
| 1160 | -> x = 123 |
| 1161 | (Pdb) continue |
| 1162 | """ |
| 1163 | |
Xavier de Gaye | 10e54ae | 2016-10-12 20:13:24 +0200 | [diff] [blame] | 1164 | def test_pdb_issue_20766(): |
| 1165 | """Test for reference leaks when the SIGINT handler is set. |
| 1166 | |
| 1167 | >>> def test_function(): |
| 1168 | ... i = 1 |
| 1169 | ... while i <= 2: |
| 1170 | ... sess = pdb.Pdb() |
| 1171 | ... sess.set_trace(sys._getframe()) |
| 1172 | ... print('pdb %d: %s' % (i, sess._previous_sigint_handler)) |
| 1173 | ... i += 1 |
| 1174 | |
| 1175 | >>> with PdbTestInput(['continue', |
| 1176 | ... 'continue']): |
| 1177 | ... test_function() |
| 1178 | > <doctest test.test_pdb.test_pdb_issue_20766[0]>(6)test_function() |
| 1179 | -> print('pdb %d: %s' % (i, sess._previous_sigint_handler)) |
| 1180 | (Pdb) continue |
| 1181 | pdb 1: <built-in function default_int_handler> |
| 1182 | > <doctest test.test_pdb.test_pdb_issue_20766[0]>(5)test_function() |
| 1183 | -> sess.set_trace(sys._getframe()) |
| 1184 | (Pdb) continue |
| 1185 | pdb 2: <built-in function default_int_handler> |
| 1186 | """ |
Georg Brandl | 46b9afc | 2010-07-30 09:14:20 +0000 | [diff] [blame] | 1187 | |
Georg Brandl | 6cccb86 | 2010-07-30 14:16:43 +0000 | [diff] [blame] | 1188 | |
Mario Corchero | 9f1e5f1 | 2018-01-06 07:53:05 +0000 | [diff] [blame] | 1189 | class PdbTestCase(unittest.TestCase): |
| 1190 | def tearDown(self): |
| 1191 | support.unlink(support.TESTFN) |
| 1192 | |
| 1193 | def _run_pdb(self, pdb_args, commands): |
| 1194 | self.addCleanup(support.rmtree, '__pycache__') |
| 1195 | cmd = [sys.executable, '-m', 'pdb'] + pdb_args |
| 1196 | with subprocess.Popen( |
| 1197 | cmd, |
| 1198 | stdout=subprocess.PIPE, |
| 1199 | stdin=subprocess.PIPE, |
| 1200 | stderr=subprocess.STDOUT, |
| 1201 | ) as proc: |
| 1202 | stdout, stderr = proc.communicate(str.encode(commands)) |
| 1203 | stdout = stdout and bytes.decode(stdout) |
| 1204 | stderr = stderr and bytes.decode(stderr) |
| 1205 | return stdout, stderr |
| 1206 | |
| 1207 | def run_pdb_script(self, script, commands): |
Senthil Kumaran | 42d7081 | 2012-05-01 10:07:49 +0800 | [diff] [blame] | 1208 | """Run 'script' lines with pdb and the pdb 'commands'.""" |
| 1209 | filename = 'main.py' |
| 1210 | with open(filename, 'w') as f: |
| 1211 | f.write(textwrap.dedent(script)) |
Georg Brandl | 4bde9ca | 2012-05-01 09:21:16 +0200 | [diff] [blame] | 1212 | self.addCleanup(support.unlink, filename) |
Mario Corchero | 9f1e5f1 | 2018-01-06 07:53:05 +0000 | [diff] [blame] | 1213 | return self._run_pdb([filename], commands) |
| 1214 | |
| 1215 | def run_pdb_module(self, script, commands): |
| 1216 | """Runs the script code as part of a module""" |
| 1217 | self.module_name = 't_main' |
| 1218 | support.rmtree(self.module_name) |
| 1219 | main_file = self.module_name + '/__main__.py' |
| 1220 | init_file = self.module_name + '/__init__.py' |
| 1221 | os.mkdir(self.module_name) |
| 1222 | with open(init_file, 'w') as f: |
| 1223 | pass |
| 1224 | with open(main_file, 'w') as f: |
| 1225 | f.write(textwrap.dedent(script)) |
| 1226 | self.addCleanup(support.rmtree, self.module_name) |
| 1227 | return self._run_pdb(['-m', self.module_name], commands) |
Senthil Kumaran | 42d7081 | 2012-05-01 10:07:49 +0800 | [diff] [blame] | 1228 | |
Georg Brandl | 6e22055 | 2013-10-13 20:51:47 +0200 | [diff] [blame] | 1229 | def _assert_find_function(self, file_content, func_name, expected): |
Serhiy Storchaka | 19fcffa | 2020-06-21 11:07:50 +0300 | [diff] [blame^] | 1230 | with open(support.TESTFN, 'wb') as f: |
Georg Brandl | 6e22055 | 2013-10-13 20:51:47 +0200 | [diff] [blame] | 1231 | f.write(file_content) |
| 1232 | |
| 1233 | expected = None if not expected else ( |
| 1234 | expected[0], support.TESTFN, expected[1]) |
| 1235 | self.assertEqual( |
| 1236 | expected, pdb.find_function(func_name, support.TESTFN)) |
| 1237 | |
| 1238 | def test_find_function_empty_file(self): |
Serhiy Storchaka | 19fcffa | 2020-06-21 11:07:50 +0300 | [diff] [blame^] | 1239 | self._assert_find_function(b'', 'foo', None) |
Georg Brandl | 6e22055 | 2013-10-13 20:51:47 +0200 | [diff] [blame] | 1240 | |
| 1241 | def test_find_function_found(self): |
| 1242 | self._assert_find_function( |
| 1243 | """\ |
Serhiy Storchaka | 19fcffa | 2020-06-21 11:07:50 +0300 | [diff] [blame^] | 1244 | def foo(): |
| 1245 | pass |
Georg Brandl | 6e22055 | 2013-10-13 20:51:47 +0200 | [diff] [blame] | 1246 | |
Serhiy Storchaka | 19fcffa | 2020-06-21 11:07:50 +0300 | [diff] [blame^] | 1247 | def bœr(): |
| 1248 | pass |
Georg Brandl | 6e22055 | 2013-10-13 20:51:47 +0200 | [diff] [blame] | 1249 | |
Serhiy Storchaka | 19fcffa | 2020-06-21 11:07:50 +0300 | [diff] [blame^] | 1250 | def quux(): |
| 1251 | pass |
| 1252 | """.encode(), |
| 1253 | 'bœr', |
| 1254 | ('bœr', 4), |
| 1255 | ) |
| 1256 | |
| 1257 | def test_find_function_found_with_encoding_cookie(self): |
| 1258 | self._assert_find_function( |
| 1259 | """\ |
| 1260 | # coding: iso-8859-15 |
| 1261 | def foo(): |
| 1262 | pass |
| 1263 | |
| 1264 | def bœr(): |
| 1265 | pass |
| 1266 | |
| 1267 | def quux(): |
| 1268 | pass |
| 1269 | """.encode('iso-8859-15'), |
| 1270 | 'bœr', |
| 1271 | ('bœr', 5), |
| 1272 | ) |
| 1273 | |
| 1274 | def test_find_function_found_with_bom(self): |
| 1275 | self._assert_find_function( |
| 1276 | codecs.BOM_UTF8 + """\ |
| 1277 | def bœr(): |
| 1278 | pass |
| 1279 | """.encode(), |
| 1280 | 'bœr', |
| 1281 | ('bœr', 1), |
Georg Brandl | 6e22055 | 2013-10-13 20:51:47 +0200 | [diff] [blame] | 1282 | ) |
| 1283 | |
Georg Brandl | 6cccb86 | 2010-07-30 14:16:43 +0000 | [diff] [blame] | 1284 | def test_issue7964(self): |
| 1285 | # open the file as binary so we can force \r\n newline |
| 1286 | with open(support.TESTFN, 'wb') as f: |
| 1287 | f.write(b'print("testing my pdb")\r\n') |
| 1288 | cmd = [sys.executable, '-m', 'pdb', support.TESTFN] |
| 1289 | proc = subprocess.Popen(cmd, |
| 1290 | stdout=subprocess.PIPE, |
| 1291 | stdin=subprocess.PIPE, |
| 1292 | stderr=subprocess.STDOUT, |
| 1293 | ) |
Brian Curtin | 994ad6c | 2010-11-05 15:38:47 +0000 | [diff] [blame] | 1294 | self.addCleanup(proc.stdout.close) |
Georg Brandl | 6cccb86 | 2010-07-30 14:16:43 +0000 | [diff] [blame] | 1295 | stdout, stderr = proc.communicate(b'quit\n') |
| 1296 | self.assertNotIn(b'SyntaxError', stdout, |
| 1297 | "Got a syntax error running test script under PDB") |
| 1298 | |
Senthil Kumaran | 42d7081 | 2012-05-01 10:07:49 +0800 | [diff] [blame] | 1299 | def test_issue13183(self): |
| 1300 | script = """ |
| 1301 | from bar import bar |
| 1302 | |
| 1303 | def foo(): |
| 1304 | bar() |
| 1305 | |
| 1306 | def nope(): |
| 1307 | pass |
| 1308 | |
| 1309 | def foobar(): |
| 1310 | foo() |
| 1311 | nope() |
| 1312 | |
| 1313 | foobar() |
| 1314 | """ |
| 1315 | commands = """ |
| 1316 | from bar import bar |
| 1317 | break bar |
| 1318 | continue |
| 1319 | step |
| 1320 | step |
| 1321 | quit |
| 1322 | """ |
| 1323 | bar = """ |
| 1324 | def bar(): |
Senthil Kumaran | cb17204 | 2012-05-02 08:00:22 +0800 | [diff] [blame] | 1325 | pass |
Senthil Kumaran | 42d7081 | 2012-05-01 10:07:49 +0800 | [diff] [blame] | 1326 | """ |
| 1327 | with open('bar.py', 'w') as f: |
| 1328 | f.write(textwrap.dedent(bar)) |
Georg Brandl | 4bde9ca | 2012-05-01 09:21:16 +0200 | [diff] [blame] | 1329 | self.addCleanup(support.unlink, 'bar.py') |
Mario Corchero | 9f1e5f1 | 2018-01-06 07:53:05 +0000 | [diff] [blame] | 1330 | stdout, stderr = self.run_pdb_script(script, commands) |
Georg Brandl | 4bde9ca | 2012-05-01 09:21:16 +0200 | [diff] [blame] | 1331 | self.assertTrue( |
| 1332 | any('main.py(5)foo()->None' in l for l in stdout.splitlines()), |
| 1333 | 'Fail to step into the caller after a return') |
Senthil Kumaran | 42d7081 | 2012-05-01 10:07:49 +0800 | [diff] [blame] | 1334 | |
Daniel Hahler | 9139f92 | 2019-04-01 23:59:50 +0200 | [diff] [blame] | 1335 | def test_issue13120(self): |
| 1336 | # Invoking "continue" on a non-main thread triggered an exception |
| 1337 | # inside signal.signal. |
Andrew Svetlov | 539ee5d | 2012-12-04 21:08:28 +0200 | [diff] [blame] | 1338 | |
| 1339 | with open(support.TESTFN, 'wb') as f: |
| 1340 | f.write(textwrap.dedent(""" |
| 1341 | import threading |
| 1342 | import pdb |
| 1343 | |
| 1344 | def start_pdb(): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 1345 | pdb.Pdb(readrc=False).set_trace() |
Andrew Svetlov | 539ee5d | 2012-12-04 21:08:28 +0200 | [diff] [blame] | 1346 | x = 1 |
| 1347 | y = 1 |
| 1348 | |
| 1349 | t = threading.Thread(target=start_pdb) |
| 1350 | t.start()""").encode('ascii')) |
| 1351 | cmd = [sys.executable, '-u', support.TESTFN] |
| 1352 | proc = subprocess.Popen(cmd, |
| 1353 | stdout=subprocess.PIPE, |
| 1354 | stdin=subprocess.PIPE, |
| 1355 | stderr=subprocess.STDOUT, |
| 1356 | ) |
| 1357 | self.addCleanup(proc.stdout.close) |
| 1358 | stdout, stderr = proc.communicate(b'cont\n') |
| 1359 | self.assertNotIn('Error', stdout.decode(), |
| 1360 | "Got an error running test script under PDB") |
| 1361 | |
Daniel Hahler | 8d64bfa | 2019-09-09 12:45:58 +0200 | [diff] [blame] | 1362 | def test_issue36250(self): |
| 1363 | |
| 1364 | with open(support.TESTFN, 'wb') as f: |
| 1365 | f.write(textwrap.dedent(""" |
| 1366 | import threading |
| 1367 | import pdb |
| 1368 | |
| 1369 | evt = threading.Event() |
| 1370 | |
| 1371 | def start_pdb(): |
| 1372 | evt.wait() |
| 1373 | pdb.Pdb(readrc=False).set_trace() |
| 1374 | |
| 1375 | t = threading.Thread(target=start_pdb) |
| 1376 | t.start() |
| 1377 | pdb.Pdb(readrc=False).set_trace() |
| 1378 | evt.set() |
| 1379 | t.join()""").encode('ascii')) |
| 1380 | cmd = [sys.executable, '-u', support.TESTFN] |
| 1381 | proc = subprocess.Popen(cmd, |
| 1382 | stdout=subprocess.PIPE, |
| 1383 | stdin=subprocess.PIPE, |
| 1384 | stderr=subprocess.STDOUT, |
| 1385 | ) |
| 1386 | self.addCleanup(proc.stdout.close) |
| 1387 | stdout, stderr = proc.communicate(b'cont\ncont\n') |
| 1388 | self.assertNotIn('Error', stdout.decode(), |
| 1389 | "Got an error running test script under PDB") |
| 1390 | |
Terry Jan Reedy | ca3f435 | 2015-09-05 19:13:26 -0400 | [diff] [blame] | 1391 | def test_issue16180(self): |
| 1392 | # A syntax error in the debuggee. |
| 1393 | script = "def f: pass\n" |
| 1394 | commands = '' |
| 1395 | expected = "SyntaxError:" |
Mario Corchero | 9f1e5f1 | 2018-01-06 07:53:05 +0000 | [diff] [blame] | 1396 | stdout, stderr = self.run_pdb_script(script, commands) |
Terry Jan Reedy | ca3f435 | 2015-09-05 19:13:26 -0400 | [diff] [blame] | 1397 | self.assertIn(expected, stdout, |
| 1398 | '\n\nExpected:\n{}\nGot:\n{}\n' |
| 1399 | 'Fail to handle a syntax error in the debuggee.' |
| 1400 | .format(expected, stdout)) |
| 1401 | |
| 1402 | |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 1403 | def test_readrc_kwarg(self): |
Victor Stinner | 11ea044 | 2016-09-09 22:56:54 -0700 | [diff] [blame] | 1404 | script = textwrap.dedent(""" |
| 1405 | import pdb; pdb.Pdb(readrc=False).set_trace() |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 1406 | |
Victor Stinner | 11ea044 | 2016-09-09 22:56:54 -0700 | [diff] [blame] | 1407 | print('hello') |
| 1408 | """) |
Victor Stinner | 11ea044 | 2016-09-09 22:56:54 -0700 | [diff] [blame] | 1409 | |
Victor Stinner | bc62626 | 2016-09-09 23:22:09 -0700 | [diff] [blame] | 1410 | save_home = os.environ.pop('HOME', None) |
| 1411 | try: |
| 1412 | with support.temp_cwd(): |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 1413 | with open('.pdbrc', 'w') as f: |
| 1414 | f.write("invalid\n") |
| 1415 | |
| 1416 | with open('main.py', 'w') as f: |
| 1417 | f.write(script) |
| 1418 | |
| 1419 | cmd = [sys.executable, 'main.py'] |
| 1420 | proc = subprocess.Popen( |
| 1421 | cmd, |
| 1422 | stdout=subprocess.PIPE, |
| 1423 | stdin=subprocess.PIPE, |
| 1424 | stderr=subprocess.PIPE, |
| 1425 | ) |
Victor Stinner | bc62626 | 2016-09-09 23:22:09 -0700 | [diff] [blame] | 1426 | with proc: |
| 1427 | stdout, stderr = proc.communicate(b'q\n') |
| 1428 | self.assertNotIn("NameError: name 'invalid' is not defined", |
| 1429 | stdout.decode()) |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 1430 | |
| 1431 | finally: |
Victor Stinner | 11ea044 | 2016-09-09 22:56:54 -0700 | [diff] [blame] | 1432 | if save_home is not None: |
| 1433 | os.environ['HOME'] = save_home |
Łukasz Langa | 2eb6eca | 2016-09-09 22:21:17 -0700 | [diff] [blame] | 1434 | |
Timothy Hopper | 7ea9a85 | 2019-08-02 18:20:14 -0400 | [diff] [blame] | 1435 | def test_readrc_homedir(self): |
| 1436 | save_home = os.environ.pop("HOME", None) |
| 1437 | with support.temp_dir() as temp_dir, patch("os.path.expanduser"): |
| 1438 | rc_path = os.path.join(temp_dir, ".pdbrc") |
| 1439 | os.path.expanduser.return_value = rc_path |
| 1440 | try: |
| 1441 | with open(rc_path, "w") as f: |
| 1442 | f.write("invalid") |
| 1443 | self.assertEqual(pdb.Pdb().rcLines[0], "invalid") |
| 1444 | finally: |
| 1445 | if save_home is not None: |
| 1446 | os.environ["HOME"] = save_home |
| 1447 | |
Barry Warsaw | 35425d6 | 2017-09-22 12:29:42 -0400 | [diff] [blame] | 1448 | def test_header(self): |
| 1449 | stdout = StringIO() |
| 1450 | header = 'Nobody expects... blah, blah, blah' |
| 1451 | with ExitStack() as resources: |
| 1452 | resources.enter_context(patch('sys.stdout', stdout)) |
| 1453 | resources.enter_context(patch.object(pdb.Pdb, 'set_trace')) |
| 1454 | pdb.set_trace(header=header) |
| 1455 | self.assertEqual(stdout.getvalue(), header + '\n') |
| 1456 | |
Mario Corchero | 9f1e5f1 | 2018-01-06 07:53:05 +0000 | [diff] [blame] | 1457 | def test_run_module(self): |
| 1458 | script = """print("SUCCESS")""" |
| 1459 | commands = """ |
| 1460 | continue |
| 1461 | quit |
| 1462 | """ |
| 1463 | stdout, stderr = self.run_pdb_module(script, commands) |
| 1464 | self.assertTrue(any("SUCCESS" in l for l in stdout.splitlines()), stdout) |
| 1465 | |
| 1466 | def test_module_is_run_as_main(self): |
| 1467 | script = """ |
| 1468 | if __name__ == '__main__': |
| 1469 | print("SUCCESS") |
| 1470 | """ |
| 1471 | commands = """ |
| 1472 | continue |
| 1473 | quit |
| 1474 | """ |
| 1475 | stdout, stderr = self.run_pdb_module(script, commands) |
| 1476 | self.assertTrue(any("SUCCESS" in l for l in stdout.splitlines()), stdout) |
| 1477 | |
| 1478 | def test_breakpoint(self): |
| 1479 | script = """ |
| 1480 | if __name__ == '__main__': |
| 1481 | pass |
| 1482 | print("SUCCESS") |
| 1483 | pass |
| 1484 | """ |
| 1485 | commands = """ |
| 1486 | b 3 |
| 1487 | quit |
| 1488 | """ |
| 1489 | stdout, stderr = self.run_pdb_module(script, commands) |
| 1490 | self.assertTrue(any("Breakpoint 1 at" in l for l in stdout.splitlines()), stdout) |
| 1491 | self.assertTrue(all("SUCCESS" not in l for l in stdout.splitlines()), stdout) |
| 1492 | |
| 1493 | def test_run_pdb_with_pdb(self): |
| 1494 | commands = """ |
| 1495 | c |
| 1496 | quit |
| 1497 | """ |
| 1498 | stdout, stderr = self._run_pdb(["-m", "pdb"], commands) |
Mario Corchero | fcf8b4c | 2018-01-28 04:58:47 +0000 | [diff] [blame] | 1499 | self.assertIn( |
| 1500 | pdb._usage, |
| 1501 | stdout.replace('\r', '') # remove \r for windows |
| 1502 | ) |
Mario Corchero | 9f1e5f1 | 2018-01-06 07:53:05 +0000 | [diff] [blame] | 1503 | |
| 1504 | def test_module_without_a_main(self): |
| 1505 | module_name = 't_main' |
| 1506 | support.rmtree(module_name) |
| 1507 | init_file = module_name + '/__init__.py' |
| 1508 | os.mkdir(module_name) |
| 1509 | with open(init_file, 'w') as f: |
| 1510 | pass |
| 1511 | self.addCleanup(support.rmtree, module_name) |
| 1512 | stdout, stderr = self._run_pdb(['-m', module_name], "") |
| 1513 | self.assertIn("ImportError: No module named t_main.__main__", |
| 1514 | stdout.splitlines()) |
| 1515 | |
| 1516 | def test_blocks_at_first_code_line(self): |
| 1517 | script = """ |
| 1518 | #This is a comment, on line 2 |
| 1519 | |
| 1520 | print("SUCCESS") |
| 1521 | """ |
| 1522 | commands = """ |
| 1523 | quit |
| 1524 | """ |
| 1525 | stdout, stderr = self.run_pdb_module(script, commands) |
| 1526 | self.assertTrue(any("__main__.py(4)<module>()" |
| 1527 | in l for l in stdout.splitlines()), stdout) |
| 1528 | |
| 1529 | def test_relative_imports(self): |
| 1530 | self.module_name = 't_main' |
| 1531 | support.rmtree(self.module_name) |
| 1532 | main_file = self.module_name + '/__main__.py' |
| 1533 | init_file = self.module_name + '/__init__.py' |
| 1534 | module_file = self.module_name + '/module.py' |
| 1535 | self.addCleanup(support.rmtree, self.module_name) |
| 1536 | os.mkdir(self.module_name) |
| 1537 | with open(init_file, 'w') as f: |
| 1538 | f.write(textwrap.dedent(""" |
| 1539 | top_var = "VAR from top" |
| 1540 | """)) |
| 1541 | with open(main_file, 'w') as f: |
| 1542 | f.write(textwrap.dedent(""" |
| 1543 | from . import top_var |
| 1544 | from .module import var |
| 1545 | from . import module |
| 1546 | pass # We'll stop here and print the vars |
| 1547 | """)) |
| 1548 | with open(module_file, 'w') as f: |
| 1549 | f.write(textwrap.dedent(""" |
| 1550 | var = "VAR from module" |
| 1551 | var2 = "second var" |
| 1552 | """)) |
| 1553 | commands = """ |
| 1554 | b 5 |
| 1555 | c |
| 1556 | p top_var |
| 1557 | p var |
| 1558 | p module.var2 |
| 1559 | quit |
| 1560 | """ |
| 1561 | stdout, _ = self._run_pdb(['-m', self.module_name], commands) |
Mario Corchero | 38bfa84 | 2018-02-03 06:40:11 +0000 | [diff] [blame] | 1562 | self.assertTrue(any("VAR from module" in l for l in stdout.splitlines()), stdout) |
Mario Corchero | 9f1e5f1 | 2018-01-06 07:53:05 +0000 | [diff] [blame] | 1563 | self.assertTrue(any("VAR from top" in l for l in stdout.splitlines())) |
| 1564 | self.assertTrue(any("second var" in l for l in stdout.splitlines())) |
Georg Brandl | 6cccb86 | 2010-07-30 14:16:43 +0000 | [diff] [blame] | 1565 | |
Mario Corchero | 38bfa84 | 2018-02-03 06:40:11 +0000 | [diff] [blame] | 1566 | def test_relative_imports_on_plain_module(self): |
| 1567 | # Validates running a plain module. See bpo32691 |
| 1568 | self.module_name = 't_main' |
| 1569 | support.rmtree(self.module_name) |
| 1570 | main_file = self.module_name + '/runme.py' |
| 1571 | init_file = self.module_name + '/__init__.py' |
| 1572 | module_file = self.module_name + '/module.py' |
| 1573 | self.addCleanup(support.rmtree, self.module_name) |
| 1574 | os.mkdir(self.module_name) |
| 1575 | with open(init_file, 'w') as f: |
| 1576 | f.write(textwrap.dedent(""" |
| 1577 | top_var = "VAR from top" |
| 1578 | """)) |
| 1579 | with open(main_file, 'w') as f: |
| 1580 | f.write(textwrap.dedent(""" |
| 1581 | from . import module |
| 1582 | pass # We'll stop here and print the vars |
| 1583 | """)) |
| 1584 | with open(module_file, 'w') as f: |
| 1585 | f.write(textwrap.dedent(""" |
| 1586 | var = "VAR from module" |
| 1587 | """)) |
| 1588 | commands = """ |
| 1589 | b 3 |
| 1590 | c |
| 1591 | p module.var |
| 1592 | quit |
| 1593 | """ |
| 1594 | stdout, _ = self._run_pdb(['-m', self.module_name + '.runme'], commands) |
| 1595 | self.assertTrue(any("VAR from module" in l for l in stdout.splitlines()), stdout) |
| 1596 | |
Daniel Hahler | 3e93643 | 2019-03-12 04:29:04 +0100 | [diff] [blame] | 1597 | def test_errors_in_command(self): |
| 1598 | commands = "\n".join([ |
| 1599 | 'print(', |
| 1600 | 'debug print(', |
| 1601 | 'debug doesnotexist', |
| 1602 | 'c', |
| 1603 | ]) |
| 1604 | stdout, _ = self.run_pdb_script('', commands + '\n') |
| 1605 | |
Daniel Hahler | 4327705 | 2019-02-15 21:52:53 +0100 | [diff] [blame] | 1606 | self.assertEqual(stdout.splitlines()[1:], [ |
| 1607 | '(Pdb) *** SyntaxError: unexpected EOF while parsing', |
Daniel Hahler | 3e93643 | 2019-03-12 04:29:04 +0100 | [diff] [blame] | 1608 | |
| 1609 | '(Pdb) ENTERING RECURSIVE DEBUGGER', |
| 1610 | '*** SyntaxError: unexpected EOF while parsing', |
| 1611 | 'LEAVING RECURSIVE DEBUGGER', |
| 1612 | |
| 1613 | '(Pdb) ENTERING RECURSIVE DEBUGGER', |
| 1614 | '> <string>(1)<module>()', |
| 1615 | "((Pdb)) *** NameError: name 'doesnotexist' is not defined", |
| 1616 | 'LEAVING RECURSIVE DEBUGGER', |
Daniel Hahler | 4327705 | 2019-02-15 21:52:53 +0100 | [diff] [blame] | 1617 | '(Pdb) ', |
| 1618 | ]) |
Georg Brandl | 6cccb86 | 2010-07-30 14:16:43 +0000 | [diff] [blame] | 1619 | |
Andrew Svetlov | f0efea0 | 2013-03-18 10:09:50 -0700 | [diff] [blame] | 1620 | def load_tests(*args): |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 1621 | from test import test_pdb |
Mario Corchero | 9f1e5f1 | 2018-01-06 07:53:05 +0000 | [diff] [blame] | 1622 | suites = [ |
| 1623 | unittest.makeSuite(PdbTestCase), |
| 1624 | doctest.DocTestSuite(test_pdb) |
| 1625 | ] |
Andrew Svetlov | f0efea0 | 2013-03-18 10:09:50 -0700 | [diff] [blame] | 1626 | return unittest.TestSuite(suites) |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 1627 | |
| 1628 | |
| 1629 | if __name__ == '__main__': |
Andrew Svetlov | f0efea0 | 2013-03-18 10:09:50 -0700 | [diff] [blame] | 1630 | unittest.main() |