Back to index

python3.2  3.2.2
Classes | Functions | Variables
test.test_pdb Namespace Reference

Classes

class  PdbTestInput
class  PdbTestCase

Functions

def test_pdb_displayhook
def test_pdb_basic_commands
def test_pdb_breakpoint_commands
def do_nothing
def do_something
def test_list_commands
def test_post_mortem
def test_pdb_skip_modules
def test_pdb_skip_modules_with_callback
def test_pdb_continue_in_bottomframe
def pdb_invoke
def test_pdb_run_with_incorrect_argument
def test_pdb_run_with_code_object
def test_main

Variables

tuple mod = imp.new_module('module_to_skip')

Function Documentation

Definition at line 274 of file test_pdb.py.

00274 
00275 def do_nothing():
00276     pass

Definition at line 277 of file test_pdb.py.

00277 
00278 def do_something():
00279     print(42)

def test.test_pdb.pdb_invoke (   method,
  arg 
)
Run pdb.method(arg).

Definition at line 551 of file test_pdb.py.

00551 
00552 def pdb_invoke(method, arg):
00553     """Run pdb.method(arg)."""
00554     import pdb
00555     getattr(pdb.Pdb(nosigint=True), method)(arg)
00556 

Here is the call graph for this function:

Test the list and source commands of pdb.

>>> def test_function_2(foo):
...     import test.test_pdb
...     test.test_pdb.do_nothing()
...     'some...'
...     'more...'
...     'code...'
...     'to...'
...     'make...'
...     'a...'
...     'long...'
...     'listing...'
...     'useful...'
...     '...'
...     '...'
...     return foo

>>> def test_function():
...     import pdb; pdb.Pdb(nosigint=True).set_trace()
...     ret = test_function_2('baz')

>>> with PdbTestInput([  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
...     'list',      # list first function
...     'step',      # step into second function
...     'list',      # list second function
...     'list',      # continue listing to EOF
...     'list 1,3',  # list specific lines
...     'list x',    # invalid argument
...     'next',      # step to import
...     'next',      # step over import
...     'step',      # step into do_nothing
...     'longlist',  # list all lines
...     'source do_something',  # list all lines of function
...     'source fooxxx',        # something that doesn't exit
...     'continue',
... ]):
...    test_function()
> <doctest test.test_pdb.test_list_commands[1]>(3)test_function()
-> ret = test_function_2('baz')
(Pdb) list
  1         def test_function():
  2             import pdb; pdb.Pdb(nosigint=True).set_trace()
  3  ->         ret = test_function_2('baz')
[EOF]
(Pdb) step
--Call--
> <doctest test.test_pdb.test_list_commands[0]>(1)test_function_2()
-> def test_function_2(foo):
(Pdb) list
  1  ->     def test_function_2(foo):
  2             import test.test_pdb
  3             test.test_pdb.do_nothing()
  4             'some...'
  5             'more...'
  6             'code...'
  7             'to...'
  8             'make...'
  9             'a...'
 10             'long...'
 11             'listing...'
(Pdb) list
 12             'useful...'
 13             '...'
 14             '...'
 15             return foo
[EOF]
(Pdb) list 1,3
  1  ->     def test_function_2(foo):
  2             import test.test_pdb
  3             test.test_pdb.do_nothing()
(Pdb) list x
*** ...
(Pdb) next
> <doctest test.test_pdb.test_list_commands[0]>(2)test_function_2()
-> import test.test_pdb
(Pdb) next
> <doctest test.test_pdb.test_list_commands[0]>(3)test_function_2()
-> test.test_pdb.do_nothing()
(Pdb) step
--Call--
> ...test_pdb.py(...)do_nothing()
-> def do_nothing():
(Pdb) longlist
...  ->     def do_nothing():
...             pass
(Pdb) source do_something
...         def do_something():
...             print(42)
(Pdb) source fooxxx
*** ...
(Pdb) continue

Definition at line 280 of file test_pdb.py.

00280 
00281 def test_list_commands():
00282     """Test the list and source commands of pdb.
00283 
00284     >>> def test_function_2(foo):
00285     ...     import test.test_pdb
00286     ...     test.test_pdb.do_nothing()
00287     ...     'some...'
00288     ...     'more...'
00289     ...     'code...'
00290     ...     'to...'
00291     ...     'make...'
00292     ...     'a...'
00293     ...     'long...'
00294     ...     'listing...'
00295     ...     'useful...'
00296     ...     '...'
00297     ...     '...'
00298     ...     return foo
00299 
00300     >>> def test_function():
00301     ...     import pdb; pdb.Pdb(nosigint=True).set_trace()
00302     ...     ret = test_function_2('baz')
00303 
00304     >>> with PdbTestInput([  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
00305     ...     'list',      # list first function
00306     ...     'step',      # step into second function
00307     ...     'list',      # list second function
00308     ...     'list',      # continue listing to EOF
00309     ...     'list 1,3',  # list specific lines
00310     ...     'list x',    # invalid argument
00311     ...     'next',      # step to import
00312     ...     'next',      # step over import
00313     ...     'step',      # step into do_nothing
00314     ...     'longlist',  # list all lines
00315     ...     'source do_something',  # list all lines of function
00316     ...     'source fooxxx',        # something that doesn't exit
00317     ...     'continue',
00318     ... ]):
00319     ...    test_function()
00320     > <doctest test.test_pdb.test_list_commands[1]>(3)test_function()
00321     -> ret = test_function_2('baz')
00322     (Pdb) list
00323       1         def test_function():
00324       2             import pdb; pdb.Pdb(nosigint=True).set_trace()
00325       3  ->         ret = test_function_2('baz')
00326     [EOF]
00327     (Pdb) step
00328     --Call--
00329     > <doctest test.test_pdb.test_list_commands[0]>(1)test_function_2()
00330     -> def test_function_2(foo):
00331     (Pdb) list
00332       1  ->     def test_function_2(foo):
00333       2             import test.test_pdb
00334       3             test.test_pdb.do_nothing()
00335       4             'some...'
00336       5             'more...'
00337       6             'code...'
00338       7             'to...'
00339       8             'make...'
00340       9             'a...'
00341      10             'long...'
00342      11             'listing...'
00343     (Pdb) list
00344      12             'useful...'
00345      13             '...'
00346      14             '...'
00347      15             return foo
00348     [EOF]
00349     (Pdb) list 1,3
00350       1  ->     def test_function_2(foo):
00351       2             import test.test_pdb
00352       3             test.test_pdb.do_nothing()
00353     (Pdb) list x
00354     *** ...
00355     (Pdb) next
00356     > <doctest test.test_pdb.test_list_commands[0]>(2)test_function_2()
00357     -> import test.test_pdb
00358     (Pdb) next
00359     > <doctest test.test_pdb.test_list_commands[0]>(3)test_function_2()
00360     -> test.test_pdb.do_nothing()
00361     (Pdb) step
00362     --Call--
00363     > ...test_pdb.py(...)do_nothing()
00364     -> def do_nothing():
00365     (Pdb) longlist
00366     ...  ->     def do_nothing():
00367     ...             pass
00368     (Pdb) source do_something
00369     ...         def do_something():
00370     ...             print(42)
00371     (Pdb) source fooxxx
00372     *** ...
00373     (Pdb) continue
00374     """
00375 

Definition at line 617 of file test_pdb.py.

00617 
00618 def test_main():
00619     from test import test_pdb
00620     support.run_doctest(test_pdb, verbosity=True)
00621     support.run_unittest(PdbTestCase)
00622 

Test the basic commands of pdb.

>>> def test_function_2(foo, bar='default'):
...     print(foo)
...     for i in range(5):
...         print(i)
...     print(bar)
...     for i in range(10):
...         never_executed
...     print('after for')
...     print('...')
...     return foo.upper()

>>> def test_function():
...     import pdb; pdb.Pdb(nosigint=True).set_trace()
...     ret = test_function_2('baz')
...     print(ret)

>>> with PdbTestInput([  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
...     'step',       # entering the function call
...     'args',       # display function args
...     'list',       # list function source
...     'bt',         # display backtrace
...     'up',         # step up to test_function()
...     'down',       # step down to test_function_2() again
...     'next',       # stepping to print(foo)
...     'next',       # stepping to the for loop
...     'step',       # stepping into the for loop
...     'until',      # continuing until out of the for loop
...     'next',       # executing the print(bar)
...     'jump 8',     # jump over second for loop
...     'return',     # return out of function
...     'retval',     # display return value
...     'continue',
... ]):
...    test_function()
> <doctest test.test_pdb.test_pdb_basic_commands[1]>(3)test_function()
-> ret = test_function_2('baz')
(Pdb) step
--Call--
> <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
-> def test_function_2(foo, bar='default'):
(Pdb) args
foo = 'baz'
bar = 'default'
(Pdb) list
  1  ->     def test_function_2(foo, bar='default'):
  2             print(foo)
  3             for i in range(5):
  4                 print(i)
  5             print(bar)
  6             for i in range(10):
  7                 never_executed
  8             print('after for')
  9             print('...')
 10             return foo.upper()
[EOF]
(Pdb) bt
...
  <doctest test.test_pdb.test_pdb_basic_commands[2]>(18)<module>()
-> test_function()
  <doctest test.test_pdb.test_pdb_basic_commands[1]>(3)test_function()
-> ret = test_function_2('baz')
> <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
-> def test_function_2(foo, bar='default'):
(Pdb) up
> <doctest test.test_pdb.test_pdb_basic_commands[1]>(3)test_function()
-> ret = test_function_2('baz')
(Pdb) down
> <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
-> def test_function_2(foo, bar='default'):
(Pdb) next
> <doctest test.test_pdb.test_pdb_basic_commands[0]>(2)test_function_2()
-> print(foo)
(Pdb) next
baz
> <doctest test.test_pdb.test_pdb_basic_commands[0]>(3)test_function_2()
-> for i in range(5):
(Pdb) step
> <doctest test.test_pdb.test_pdb_basic_commands[0]>(4)test_function_2()
-> print(i)
(Pdb) until
0
1
2
3
4
> <doctest test.test_pdb.test_pdb_basic_commands[0]>(5)test_function_2()
-> print(bar)
(Pdb) next
default
> <doctest test.test_pdb.test_pdb_basic_commands[0]>(6)test_function_2()
-> for i in range(10):
(Pdb) jump 8
> <doctest test.test_pdb.test_pdb_basic_commands[0]>(8)test_function_2()
-> print('after for')
(Pdb) return
after for
...
--Return--
> <doctest test.test_pdb.test_pdb_basic_commands[0]>(10)test_function_2()->'BAZ'
-> return foo.upper()
(Pdb) retval
'BAZ'
(Pdb) continue
BAZ

Definition at line 57 of file test_pdb.py.

00057 
00058 def test_pdb_basic_commands():
00059     """Test the basic commands of pdb.
00060 
00061     >>> def test_function_2(foo, bar='default'):
00062     ...     print(foo)
00063     ...     for i in range(5):
00064     ...         print(i)
00065     ...     print(bar)
00066     ...     for i in range(10):
00067     ...         never_executed
00068     ...     print('after for')
00069     ...     print('...')
00070     ...     return foo.upper()
00071 
00072     >>> def test_function():
00073     ...     import pdb; pdb.Pdb(nosigint=True).set_trace()
00074     ...     ret = test_function_2('baz')
00075     ...     print(ret)
00076 
00077     >>> with PdbTestInput([  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
00078     ...     'step',       # entering the function call
00079     ...     'args',       # display function args
00080     ...     'list',       # list function source
00081     ...     'bt',         # display backtrace
00082     ...     'up',         # step up to test_function()
00083     ...     'down',       # step down to test_function_2() again
00084     ...     'next',       # stepping to print(foo)
00085     ...     'next',       # stepping to the for loop
00086     ...     'step',       # stepping into the for loop
00087     ...     'until',      # continuing until out of the for loop
00088     ...     'next',       # executing the print(bar)
00089     ...     'jump 8',     # jump over second for loop
00090     ...     'return',     # return out of function
00091     ...     'retval',     # display return value
00092     ...     'continue',
00093     ... ]):
00094     ...    test_function()
00095     > <doctest test.test_pdb.test_pdb_basic_commands[1]>(3)test_function()
00096     -> ret = test_function_2('baz')
00097     (Pdb) step
00098     --Call--
00099     > <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
00100     -> def test_function_2(foo, bar='default'):
00101     (Pdb) args
00102     foo = 'baz'
00103     bar = 'default'
00104     (Pdb) list
00105       1  ->     def test_function_2(foo, bar='default'):
00106       2             print(foo)
00107       3             for i in range(5):
00108       4                 print(i)
00109       5             print(bar)
00110       6             for i in range(10):
00111       7                 never_executed
00112       8             print('after for')
00113       9             print('...')
00114      10             return foo.upper()
00115     [EOF]
00116     (Pdb) bt
00117     ...
00118       <doctest test.test_pdb.test_pdb_basic_commands[2]>(18)<module>()
00119     -> test_function()
00120       <doctest test.test_pdb.test_pdb_basic_commands[1]>(3)test_function()
00121     -> ret = test_function_2('baz')
00122     > <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
00123     -> def test_function_2(foo, bar='default'):
00124     (Pdb) up
00125     > <doctest test.test_pdb.test_pdb_basic_commands[1]>(3)test_function()
00126     -> ret = test_function_2('baz')
00127     (Pdb) down
00128     > <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
00129     -> def test_function_2(foo, bar='default'):
00130     (Pdb) next
00131     > <doctest test.test_pdb.test_pdb_basic_commands[0]>(2)test_function_2()
00132     -> print(foo)
00133     (Pdb) next
00134     baz
00135     > <doctest test.test_pdb.test_pdb_basic_commands[0]>(3)test_function_2()
00136     -> for i in range(5):
00137     (Pdb) step
00138     > <doctest test.test_pdb.test_pdb_basic_commands[0]>(4)test_function_2()
00139     -> print(i)
00140     (Pdb) until
00141     0
00142     1
00143     2
00144     3
00145     4
00146     > <doctest test.test_pdb.test_pdb_basic_commands[0]>(5)test_function_2()
00147     -> print(bar)
00148     (Pdb) next
00149     default
00150     > <doctest test.test_pdb.test_pdb_basic_commands[0]>(6)test_function_2()
00151     -> for i in range(10):
00152     (Pdb) jump 8
00153     > <doctest test.test_pdb.test_pdb_basic_commands[0]>(8)test_function_2()
00154     -> print('after for')
00155     (Pdb) return
00156     after for
00157     ...
00158     --Return--
00159     > <doctest test.test_pdb.test_pdb_basic_commands[0]>(10)test_function_2()->'BAZ'
00160     -> return foo.upper()
00161     (Pdb) retval
00162     'BAZ'
00163     (Pdb) continue
00164     BAZ
00165     """
00166 

Test basic commands related to breakpoints.

>>> def test_function():
...     import pdb; pdb.Pdb(nosigint=True).set_trace()
...     print(1)
...     print(2)
...     print(3)
...     print(4)

First, need to clear bdb state that might be left over from previous tests.
Otherwise, the new breakpoints might get assigned different numbers.

>>> from bdb import Breakpoint
>>> Breakpoint.next = 1
>>> Breakpoint.bplist = {}
>>> Breakpoint.bpbynumber = [None]

Now test the breakpoint commands.  NORMALIZE_WHITESPACE is needed because
the breakpoint list outputs a tab for the "stop only" and "ignore next"
lines, which we don't want to put in here.

>>> with PdbTestInput([  # doctest: +NORMALIZE_WHITESPACE
...     'break 3',
...     'disable 1',
...     'ignore 1 10',
...     'condition 1 1 < 2',
...     'break 4',
...     'break 4',
...     'break',
...     'clear 3',
...     'break',
...     'condition 1',
...     'enable 1',
...     'clear 1',
...     'commands 2',
...     'print 42',
...     'end',
...     'continue',  # will stop at breakpoint 2 (line 4)
...     'clear',     # clear all!
...     'y',
...     'tbreak 5',
...     'continue',  # will stop at temporary breakpoint
...     'break',     # make sure breakpoint is gone
...     'continue',
... ]):
...    test_function()
> <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(3)test_function()
-> print(1)
(Pdb) break 3
Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
(Pdb) disable 1
Disabled breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
(Pdb) ignore 1 10
Will ignore next 10 crossings of breakpoint 1.
(Pdb) condition 1 1 < 2
New condition set for breakpoint 1.
(Pdb) break 4
Breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
(Pdb) break 4
Breakpoint 3 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
(Pdb) break
Num Type         Disp Enb   Where
1   breakpoint   keep no    at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
        stop only if 1 < 2
        ignore next 10 hits
2   breakpoint   keep yes   at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
3   breakpoint   keep yes   at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
(Pdb) clear 3
Deleted breakpoint 3 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
(Pdb) break
Num Type         Disp Enb   Where
1   breakpoint   keep no    at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
        stop only if 1 < 2
        ignore next 10 hits
2   breakpoint   keep yes   at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
(Pdb) condition 1
Breakpoint 1 is now unconditional.
(Pdb) enable 1
Enabled breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
(Pdb) clear 1
Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
(Pdb) commands 2
(com) print 42
(com) end
(Pdb) continue
1
42
> <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(4)test_function()
-> print(2)
(Pdb) clear
Clear all breaks? y
Deleted breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
(Pdb) tbreak 5
Breakpoint 4 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:5
(Pdb) continue
2
Deleted breakpoint 4 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:5
> <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(5)test_function()
-> print(3)
(Pdb) break
(Pdb) continue
3
4

Definition at line 167 of file test_pdb.py.

00167 
00168 def test_pdb_breakpoint_commands():
00169     """Test basic commands related to breakpoints.
00170 
00171     >>> def test_function():
00172     ...     import pdb; pdb.Pdb(nosigint=True).set_trace()
00173     ...     print(1)
00174     ...     print(2)
00175     ...     print(3)
00176     ...     print(4)
00177 
00178     First, need to clear bdb state that might be left over from previous tests.
00179     Otherwise, the new breakpoints might get assigned different numbers.
00180 
00181     >>> from bdb import Breakpoint
00182     >>> Breakpoint.next = 1
00183     >>> Breakpoint.bplist = {}
00184     >>> Breakpoint.bpbynumber = [None]
00185 
00186     Now test the breakpoint commands.  NORMALIZE_WHITESPACE is needed because
00187     the breakpoint list outputs a tab for the "stop only" and "ignore next"
00188     lines, which we don't want to put in here.
00189 
00190     >>> with PdbTestInput([  # doctest: +NORMALIZE_WHITESPACE
00191     ...     'break 3',
00192     ...     'disable 1',
00193     ...     'ignore 1 10',
00194     ...     'condition 1 1 < 2',
00195     ...     'break 4',
00196     ...     'break 4',
00197     ...     'break',
00198     ...     'clear 3',
00199     ...     'break',
00200     ...     'condition 1',
00201     ...     'enable 1',
00202     ...     'clear 1',
00203     ...     'commands 2',
00204     ...     'print 42',
00205     ...     'end',
00206     ...     'continue',  # will stop at breakpoint 2 (line 4)
00207     ...     'clear',     # clear all!
00208     ...     'y',
00209     ...     'tbreak 5',
00210     ...     'continue',  # will stop at temporary breakpoint
00211     ...     'break',     # make sure breakpoint is gone
00212     ...     'continue',
00213     ... ]):
00214     ...    test_function()
00215     > <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(3)test_function()
00216     -> print(1)
00217     (Pdb) break 3
00218     Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
00219     (Pdb) disable 1
00220     Disabled breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
00221     (Pdb) ignore 1 10
00222     Will ignore next 10 crossings of breakpoint 1.
00223     (Pdb) condition 1 1 < 2
00224     New condition set for breakpoint 1.
00225     (Pdb) break 4
00226     Breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
00227     (Pdb) break 4
00228     Breakpoint 3 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
00229     (Pdb) break
00230     Num Type         Disp Enb   Where
00231     1   breakpoint   keep no    at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
00232             stop only if 1 < 2
00233             ignore next 10 hits
00234     2   breakpoint   keep yes   at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
00235     3   breakpoint   keep yes   at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
00236     (Pdb) clear 3
00237     Deleted breakpoint 3 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
00238     (Pdb) break
00239     Num Type         Disp Enb   Where
00240     1   breakpoint   keep no    at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
00241             stop only if 1 < 2
00242             ignore next 10 hits
00243     2   breakpoint   keep yes   at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
00244     (Pdb) condition 1
00245     Breakpoint 1 is now unconditional.
00246     (Pdb) enable 1
00247     Enabled breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
00248     (Pdb) clear 1
00249     Deleted breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
00250     (Pdb) commands 2
00251     (com) print 42
00252     (com) end
00253     (Pdb) continue
00254     1
00255     42
00256     > <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(4)test_function()
00257     -> print(2)
00258     (Pdb) clear
00259     Clear all breaks? y
00260     Deleted breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
00261     (Pdb) tbreak 5
00262     Breakpoint 4 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:5
00263     (Pdb) continue
00264     2
00265     Deleted breakpoint 4 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:5
00266     > <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(5)test_function()
00267     -> print(3)
00268     (Pdb) break
00269     (Pdb) continue
00270     3
00271     4
00272     """
00273 

Test that "continue" and "next" work properly in bottom frame (issue #5294).

>>> def test_function():
...     import pdb, sys; inst = pdb.Pdb(nosigint=True)
...     inst.set_trace()
...     inst.botframe = sys._getframe()  # hackery to get the right botframe
...     print(1)
...     print(2)
...     print(3)
...     print(4)

>>> with PdbTestInput([  # doctest: +ELLIPSIS
...     'next',
...     'break 7',
...     'continue',
...     'next',
...     'continue',
...     'continue',
... ]):
...    test_function()
> <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(4)test_function()
-> inst.botframe = sys._getframe()  # hackery to get the right botframe
(Pdb) next
> <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(5)test_function()
-> print(1)
(Pdb) break 7
Breakpoint ... at <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>:7
(Pdb) continue
1
2
> <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(7)test_function()
-> print(3)
(Pdb) next
3
> <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(8)test_function()
-> print(4)
(Pdb) continue
4

Definition at line 509 of file test_pdb.py.

00509 
00510 def test_pdb_continue_in_bottomframe():
00511     """Test that "continue" and "next" work properly in bottom frame (issue #5294).
00512 
00513     >>> def test_function():
00514     ...     import pdb, sys; inst = pdb.Pdb(nosigint=True)
00515     ...     inst.set_trace()
00516     ...     inst.botframe = sys._getframe()  # hackery to get the right botframe
00517     ...     print(1)
00518     ...     print(2)
00519     ...     print(3)
00520     ...     print(4)
00521 
00522     >>> with PdbTestInput([  # doctest: +ELLIPSIS
00523     ...     'next',
00524     ...     'break 7',
00525     ...     'continue',
00526     ...     'next',
00527     ...     'continue',
00528     ...     'continue',
00529     ... ]):
00530     ...    test_function()
00531     > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(4)test_function()
00532     -> inst.botframe = sys._getframe()  # hackery to get the right botframe
00533     (Pdb) next
00534     > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(5)test_function()
00535     -> print(1)
00536     (Pdb) break 7
00537     Breakpoint ... at <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>:7
00538     (Pdb) continue
00539     1
00540     2
00541     > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(7)test_function()
00542     -> print(3)
00543     (Pdb) next
00544     3
00545     > <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(8)test_function()
00546     -> print(4)
00547     (Pdb) continue
00548     4
00549     """
00550 

This tests the custom displayhook for pdb.

>>> def test_function(foo, bar):
...     import pdb; pdb.Pdb(nosigint=True).set_trace()
...     pass

>>> with PdbTestInput([
...     'foo',
...     'bar',
...     'for i in range(5): print(i)',
...     'continue',
... ]):
...     test_function(1, None)
> <doctest test.test_pdb.test_pdb_displayhook[0]>(3)test_function()
-> pass
(Pdb) foo
1
(Pdb) bar
(Pdb) for i in range(5): print(i)
0
1
2
3
4
(Pdb) continue

Definition at line 28 of file test_pdb.py.

00028 
00029 def test_pdb_displayhook():
00030     """This tests the custom displayhook for pdb.
00031 
00032     >>> def test_function(foo, bar):
00033     ...     import pdb; pdb.Pdb(nosigint=True).set_trace()
00034     ...     pass
00035 
00036     >>> with PdbTestInput([
00037     ...     'foo',
00038     ...     'bar',
00039     ...     'for i in range(5): print(i)',
00040     ...     'continue',
00041     ... ]):
00042     ...     test_function(1, None)
00043     > <doctest test.test_pdb.test_pdb_displayhook[0]>(3)test_function()
00044     -> pass
00045     (Pdb) foo
00046     1
00047     (Pdb) bar
00048     (Pdb) for i in range(5): print(i)
00049     0
00050     1
00051     2
00052     3
00053     4
00054     (Pdb) continue
00055     """
00056 

Testing run and runeval with code object as a first argument.

>>> with PdbTestInput(['step','x', 'continue']):  # doctest: +ELLIPSIS
...     pdb_invoke('run', compile('x=1', '<string>', 'exec'))
> <string>(1)<module>()...
(Pdb) step
--Return--
> <string>(1)<module>()->None
(Pdb) x
1
(Pdb) continue

>>> with PdbTestInput(['x', 'continue']):
...     x=0
...     pdb_invoke('runeval', compile('x+1', '<string>', 'eval'))
> <string>(1)<module>()->None
(Pdb) x
1
(Pdb) continue

Definition at line 573 of file test_pdb.py.

00573 
00574 def test_pdb_run_with_code_object():
00575     """Testing run and runeval with code object as a first argument.
00576 
00577     >>> with PdbTestInput(['step','x', 'continue']):  # doctest: +ELLIPSIS
00578     ...     pdb_invoke('run', compile('x=1', '<string>', 'exec'))
00579     > <string>(1)<module>()...
00580     (Pdb) step
00581     --Return--
00582     > <string>(1)<module>()->None
00583     (Pdb) x
00584     1
00585     (Pdb) continue
00586 
00587     >>> with PdbTestInput(['x', 'continue']):
00588     ...     x=0
00589     ...     pdb_invoke('runeval', compile('x+1', '<string>', 'eval'))
00590     > <string>(1)<module>()->None
00591     (Pdb) x
00592     1
00593     (Pdb) continue
00594     """
00595 

Testing run and runeval with incorrect first argument.

>>> pti = PdbTestInput(['continue',])
>>> with pti:
...     pdb_invoke('run', lambda x: x)
Traceback (most recent call last):
TypeError: exec() arg 1 must be a string, bytes or code object

>>> with pti:
...     pdb_invoke('runeval', lambda x: x)
Traceback (most recent call last):
TypeError: eval() arg 1 must be a string, bytes or code object

Definition at line 557 of file test_pdb.py.

00557 
00558 def test_pdb_run_with_incorrect_argument():
00559     """Testing run and runeval with incorrect first argument.
00560 
00561     >>> pti = PdbTestInput(['continue',])
00562     >>> with pti:
00563     ...     pdb_invoke('run', lambda x: x)
00564     Traceback (most recent call last):
00565     TypeError: exec() arg 1 must be a string, bytes or code object
00566 
00567     >>> with pti:
00568     ...     pdb_invoke('runeval', lambda x: x)
00569     Traceback (most recent call last):
00570     TypeError: eval() arg 1 must be a string, bytes or code object
00571     """
00572 

This illustrates the simple case of module skipping.

>>> def skip_module():
...     import string
...     import pdb; pdb.Pdb(skip=['stri*'], nosigint=True).set_trace()
...     string.capwords('FOO')

>>> with PdbTestInput([
...     'step',
...     'continue',
... ]):
...     skip_module()
> <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()
-> string.capwords('FOO')
(Pdb) step
--Return--
> <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()->None
-> string.capwords('FOO')
(Pdb) continue

Definition at line 438 of file test_pdb.py.

00438 
00439 def test_pdb_skip_modules():
00440     """This illustrates the simple case of module skipping.
00441 
00442     >>> def skip_module():
00443     ...     import string
00444     ...     import pdb; pdb.Pdb(skip=['stri*'], nosigint=True).set_trace()
00445     ...     string.capwords('FOO')
00446 
00447     >>> with PdbTestInput([
00448     ...     'step',
00449     ...     'continue',
00450     ... ]):
00451     ...     skip_module()
00452     > <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()
00453     -> string.capwords('FOO')
00454     (Pdb) step
00455     --Return--
00456     > <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()->None
00457     -> string.capwords('FOO')
00458     (Pdb) continue
00459     """
00460 
00461 
# Module for testing skipping of module that makes a callback
This illustrates skipping of modules that call into other code.

>>> def skip_module():
...     def callback():
...         return None
...     import pdb; pdb.Pdb(skip=['module_to_skip*'], nosigint=True).set_trace()
...     mod.foo_pony(callback)

>>> with PdbTestInput([
...     'step',
...     'step',
...     'step',
...     'step',
...     'step',
...     'continue',
... ]):
...     skip_module()
...     pass  # provides something to "step" to
> <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()
-> mod.foo_pony(callback)
(Pdb) step
--Call--
> <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(2)callback()
-> def callback():
(Pdb) step
> <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(3)callback()
-> return None
(Pdb) step
--Return--
> <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(3)callback()->None
-> return None
(Pdb) step
--Return--
> <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()->None
-> mod.foo_pony(callback)
(Pdb) step
> <doctest test.test_pdb.test_pdb_skip_modules_with_callback[1]>(10)<module>()
-> pass  # provides something to "step" to
(Pdb) continue

Definition at line 466 of file test_pdb.py.

00466 
00467 def test_pdb_skip_modules_with_callback():
00468     """This illustrates skipping of modules that call into other code.
00469 
00470     >>> def skip_module():
00471     ...     def callback():
00472     ...         return None
00473     ...     import pdb; pdb.Pdb(skip=['module_to_skip*'], nosigint=True).set_trace()
00474     ...     mod.foo_pony(callback)
00475 
00476     >>> with PdbTestInput([
00477     ...     'step',
00478     ...     'step',
00479     ...     'step',
00480     ...     'step',
00481     ...     'step',
00482     ...     'continue',
00483     ... ]):
00484     ...     skip_module()
00485     ...     pass  # provides something to "step" to
00486     > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()
00487     -> mod.foo_pony(callback)
00488     (Pdb) step
00489     --Call--
00490     > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(2)callback()
00491     -> def callback():
00492     (Pdb) step
00493     > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(3)callback()
00494     -> return None
00495     (Pdb) step
00496     --Return--
00497     > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(3)callback()->None
00498     -> return None
00499     (Pdb) step
00500     --Return--
00501     > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()->None
00502     -> mod.foo_pony(callback)
00503     (Pdb) step
00504     > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[1]>(10)<module>()
00505     -> pass  # provides something to "step" to
00506     (Pdb) continue
00507     """
00508 

Test post mortem traceback debugging.

>>> def test_function_2():
...     try:
...         1/0
...     finally:
...         print('Exception!')

>>> def test_function():
...     import pdb; pdb.Pdb(nosigint=True).set_trace()
...     test_function_2()
...     print('Not reached.')

>>> with PdbTestInput([  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
...     'next',      # step over exception-raising call
...     'bt',        # get a backtrace
...     'list',      # list code of test_function()
...     'down',      # step into test_function_2()
...     'list',      # list code of test_function_2()
...     'continue',
... ]):
...    try:
...        test_function()
...    except ZeroDivisionError:
...        print('Correctly reraised.')
> <doctest test.test_pdb.test_post_mortem[1]>(3)test_function()
-> test_function_2()
(Pdb) next
Exception!
ZeroDivisionError: division by zero
> <doctest test.test_pdb.test_post_mortem[1]>(3)test_function()
-> test_function_2()
(Pdb) bt
...
  <doctest test.test_pdb.test_post_mortem[2]>(10)<module>()
-> test_function()
> <doctest test.test_pdb.test_post_mortem[1]>(3)test_function()
-> test_function_2()
  <doctest test.test_pdb.test_post_mortem[0]>(3)test_function_2()
-> 1/0
(Pdb) list
  1         def test_function():
  2             import pdb; pdb.Pdb(nosigint=True).set_trace()
  3  ->         test_function_2()
  4             print('Not reached.')
[EOF]
(Pdb) down
> <doctest test.test_pdb.test_post_mortem[0]>(3)test_function_2()
-> 1/0
(Pdb) list
  1         def test_function_2():
  2             try:
  3  >>             1/0
  4             finally:
  5  ->             print('Exception!')
[EOF]
(Pdb) continue
Correctly reraised.

Definition at line 376 of file test_pdb.py.

00376 
00377 def test_post_mortem():
00378     """Test post mortem traceback debugging.
00379 
00380     >>> def test_function_2():
00381     ...     try:
00382     ...         1/0
00383     ...     finally:
00384     ...         print('Exception!')
00385 
00386     >>> def test_function():
00387     ...     import pdb; pdb.Pdb(nosigint=True).set_trace()
00388     ...     test_function_2()
00389     ...     print('Not reached.')
00390 
00391     >>> with PdbTestInput([  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
00392     ...     'next',      # step over exception-raising call
00393     ...     'bt',        # get a backtrace
00394     ...     'list',      # list code of test_function()
00395     ...     'down',      # step into test_function_2()
00396     ...     'list',      # list code of test_function_2()
00397     ...     'continue',
00398     ... ]):
00399     ...    try:
00400     ...        test_function()
00401     ...    except ZeroDivisionError:
00402     ...        print('Correctly reraised.')
00403     > <doctest test.test_pdb.test_post_mortem[1]>(3)test_function()
00404     -> test_function_2()
00405     (Pdb) next
00406     Exception!
00407     ZeroDivisionError: division by zero
00408     > <doctest test.test_pdb.test_post_mortem[1]>(3)test_function()
00409     -> test_function_2()
00410     (Pdb) bt
00411     ...
00412       <doctest test.test_pdb.test_post_mortem[2]>(10)<module>()
00413     -> test_function()
00414     > <doctest test.test_pdb.test_post_mortem[1]>(3)test_function()
00415     -> test_function_2()
00416       <doctest test.test_pdb.test_post_mortem[0]>(3)test_function_2()
00417     -> 1/0
00418     (Pdb) list
00419       1         def test_function():
00420       2             import pdb; pdb.Pdb(nosigint=True).set_trace()
00421       3  ->         test_function_2()
00422       4             print('Not reached.')
00423     [EOF]
00424     (Pdb) down
00425     > <doctest test.test_pdb.test_post_mortem[0]>(3)test_function_2()
00426     -> 1/0
00427     (Pdb) list
00428       1         def test_function_2():
00429       2             try:
00430       3  >>             1/0
00431       4             finally:
00432       5  ->             print('Exception!')
00433     [EOF]
00434     (Pdb) continue
00435     Correctly reraised.
00436     """
00437 


Variable Documentation

tuple test.test_pdb.mod = imp.new_module('module_to_skip')

Definition at line 462 of file test_pdb.py.