summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/bdb.py13
-rwxr-xr-xLib/pdb.py4
-rw-r--r--Lib/test/test_pdb.py99
3 files changed, 113 insertions, 3 deletions
diff --git a/Lib/bdb.py b/Lib/bdb.py
index 6dc54ed..3b4f991 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -1,5 +1,6 @@
"""Debugger basics"""
+import fnmatch
import sys
import os
import types
@@ -19,7 +20,8 @@ class Bdb:
The standard debugger class (pdb.Pdb) is an example.
"""
- def __init__(self):
+ def __init__(self, skip=None):
+ self.skip = set(skip) if skip else None
self.breaks = {}
self.fncache = {}
@@ -94,9 +96,18 @@ class Bdb:
# methods, but they may if they want to redefine the
# definition of stopping and breakpoints.
+ def is_skipped_module(self, module_name):
+ for pattern in self.skip:
+ if fnmatch.fnmatch(module_name, pattern):
+ return True
+ return False
+
def stop_here(self, frame):
# (CT) stopframe may now also be None, see dispatch_call.
# (CT) the former test for None is therefore removed from here.
+ if self.skip and \
+ self.is_skipped_module(frame.f_globals.get('__name__')):
+ return False
if frame is self.stopframe:
return frame.f_lineno >= self.stoplineno
while frame is not None and frame is not self.stopframe:
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 22fc4c5..c9c66c5 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -58,8 +58,8 @@ line_prefix = '\n-> ' # Probably a better default
class Pdb(bdb.Bdb, cmd.Cmd):
- def __init__(self, completekey='tab', stdin=None, stdout=None):
- bdb.Bdb.__init__(self)
+ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None):
+ bdb.Bdb.__init__(self, skip=skip)
cmd.Cmd.__init__(self, completekey, stdin, stdout)
if stdout:
self.use_rawinput = 0
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
new file mode 100644
index 0000000..bcd4853
--- /dev/null
+++ b/Lib/test/test_pdb.py
@@ -0,0 +1,99 @@
+# A test suite for pdb; at the moment, this only validates skipping of
+# specified test modules (RFE #5142).
+
+import imp
+import os
+import sys
+import doctest
+import tempfile
+
+from test import support
+# This little helper class is essential for testing pdb under doctest.
+from test.test_doctest import _FakeInput
+
+
+def test_pdb_skip_modules():
+ """This illustrates the simple case of module skipping.
+
+ >>> def skip_module():
+ ... import string
+ ... import pdb; pdb.Pdb(skip=['stri*']).set_trace()
+ ... string.capwords('FOO')
+ >>> real_stdin = sys.stdin
+ >>> sys.stdin = _FakeInput([
+ ... 'step',
+ ... 'continue',
+ ... ])
+
+ >>> try:
+ ... skip_module()
+ ... finally:
+ ... sys.stdin = real_stdin
+ > <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
+"""
+
+
+# Module for testing skipping of module that makes a callback
+mod = imp.new_module('module_to_skip')
+exec('def foo_pony(callback): x = 1; callback(); return None', mod.__dict__)
+
+
+def test_pdb_skip_modules_with_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*']).set_trace()
+ ... mod.foo_pony(callback)
+ >>> real_stdin = sys.stdin
+ >>> sys.stdin = _FakeInput([
+ ... 'step',
+ ... 'step',
+ ... 'step',
+ ... 'step',
+ ... 'step',
+ ... 'continue',
+ ... ])
+
+ >>> try:
+ ... skip_module()
+ ... finally:
+ ... sys.stdin = real_stdin
+ > <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[3]>(4)<module>()
+ -> sys.stdin = real_stdin
+ (Pdb) continue
+"""
+
+
+def test_main():
+ from test import test_pdb
+ support.run_doctest(test_pdb, verbosity=True)
+
+
+if __name__ == '__main__':
+ test_main()