annotate Lib/test/test_pdb.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents c49bc330327c
children 32448f8a6c63
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
53776
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
1 # A test suite for pdb; at the moment, this only validates skipping of
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
2 # specified test modules (RFE #5142).
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
3
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
4 import imp
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
5 import os
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
6 import sys
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
7 import doctest
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
8 import tempfile
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
9
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
10 from test import test_support
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
11 # This little helper class is essential for testing pdb under doctest.
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
12 from test_doctest import _FakeInput
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
13
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
14
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
15 def test_pdb_skip_modules():
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
16 """This illustrates the simple case of module skipping.
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
17
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
18 >>> def skip_module():
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
19 ... import string
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
20 ... import pdb;pdb.Pdb(skip=['string*']).set_trace()
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
21 ... string.lower('FOO')
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
22 >>> real_stdin = sys.stdin
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
23 >>> sys.stdin = _FakeInput([
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
24 ... 'step',
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
25 ... 'continue',
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
26 ... ])
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
27
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
28 >>> try:
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
29 ... skip_module()
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
30 ... finally:
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
31 ... sys.stdin = real_stdin
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
32 > <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
33 -> string.lower('FOO')
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
34 (Pdb) step
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
35 --Return--
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
36 > <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()->None
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
37 -> string.lower('FOO')
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
38 (Pdb) continue
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
39 """
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
40
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
41
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
42 # Module for testing skipping of module that makes a callback
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
43 mod = imp.new_module('module_to_skip')
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
44 exec 'def foo_pony(callback): x = 1; callback(); return None' in mod.__dict__
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
45
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
46
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
47 def test_pdb_skip_modules_with_callback():
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
48 """This illustrates skipping of modules that call into other code.
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
49
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
50 >>> def skip_module():
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
51 ... def callback():
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
52 ... return None
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
53 ... import pdb;pdb.Pdb(skip=['module_to_skip*']).set_trace()
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
54 ... mod.foo_pony(callback)
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
55 >>> real_stdin = sys.stdin
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
56 >>> sys.stdin = _FakeInput([
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
57 ... 'step',
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
58 ... 'step',
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
59 ... 'step',
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
60 ... 'step',
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
61 ... 'step',
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
62 ... 'continue',
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
63 ... ])
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
64
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
65 >>> try:
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
66 ... skip_module()
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
67 ... finally:
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
68 ... sys.stdin = real_stdin
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
69 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
70 -> mod.foo_pony(callback)
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
71 (Pdb) step
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
72 --Call--
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
73 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(2)callback()
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
74 -> def callback():
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
75 (Pdb) step
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
76 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(3)callback()
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
77 -> return None
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
78 (Pdb) step
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
79 --Return--
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
80 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(3)callback()->None
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
81 -> return None
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
82 (Pdb) step
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
83 --Return--
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
84 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()->None
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
85 -> mod.foo_pony(callback)
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
86 (Pdb) step
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
87 > <doctest test.test_pdb.test_pdb_skip_modules_with_callback[3]>(4)<module>()
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
88 -> sys.stdin = real_stdin
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
89 (Pdb) continue
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
90 """
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
91
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
92
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
93 def test_main():
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
94 from test import test_pdb
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
95 test_support.run_doctest(test_pdb, verbosity=True)
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
96
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
97
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
98 if __name__ == '__main__':
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
diff changeset
99 test_main()