summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>2007-05-15 16:57:16 +0200
committerAdrien Di Mascio <Adrien.DiMascio@logilab.fr>2007-05-15 16:57:16 +0200
commita2410952a6bb38962e7111a9f65b7b028c9caba6 (patch)
tree6922da0e1ea80ace5cb366a93f7fa89d23616b11
parentd9c05378d0628d1c0779da8abb1a693a8abe9915 (diff)
downloadlogilab-common-a2410952a6bb38962e7111a9f65b7b028c9caba6.tar.gz
added history file for debuggers
-rw-r--r--testlib.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/testlib.py b/testlib.py
index f4ecbeb..cf69d4b 100644
--- a/testlib.py
+++ b/testlib.py
@@ -35,6 +35,10 @@ import difflib
import types
from warnings import warn
from compiler.consts import CO_GENERATOR
+try:
+ import readline
+except ImportError:
+ readline = None
# PRINT_ = file('stdout.txt', 'w').write
@@ -266,6 +270,8 @@ def _count(n, word):
return "%d %ss" % (n, word)
+
+
## PostMortem Debug facilities #####
from pdb import Pdb
class Debugger(Pdb):
@@ -275,10 +281,27 @@ class Debugger(Pdb):
while tcbk.tb_next is not None:
tcbk = tcbk.tb_next
self._tcbk = tcbk
+ self._histfile = osp.join(os.environ["HOME"], ".pdbhist")
+ def setup_history_file(self):
+ if readline is not None:
+ try:
+ readline.read_history_file(self._histfile)
+ except IOError:
+ pass
+
def start(self):
self.interaction(self._tcbk.tb_frame, self._tcbk)
+ def setup(self, frame, tcbk):
+ self.setup_history_file()
+ Pdb.setup(self, frame, tcbk)
+
+ def set_quit(self):
+ if readline is not None:
+ readline.write_history_file(self._histfile)
+ Pdb.set_quit(self)
+
def start_interactive_mode(debuggers, descrs):
"""starts an interactive shell so that the user can inspect errors
"""
@@ -328,6 +351,7 @@ class SkipAwareTestResult(unittest._TextTestResult):
self.printonly = printonly
self.pdbmode = pdbmode
self.cvg = cvg
+ self.pdbclass = Debugger
## def startTest(self, test):
## "Called when the given test is about to be run"
@@ -344,7 +368,7 @@ class SkipAwareTestResult(unittest._TextTestResult):
def _create_pdb(self, test_descr):
if self.pdbmode:
- self.debuggers.append(Debugger(sys.exc_info()[2]))
+ self.debuggers.append(self.pdbclass(sys.exc_info()[2]))
self.descrs.append(test_descr)
def addError(self, test, err):
@@ -794,6 +818,7 @@ class TestCase(unittest.TestCase):
"""unittest.TestCase with some additional methods"""
capture = False
+ pdbclass = Debugger
def __init__(self, methodName='runTest'):
super(TestCase, self).__init__(methodName)
@@ -883,6 +908,7 @@ class TestCase(unittest.TestCase):
"""
if result is None:
result = self.defaultTestResult()
+ result.pdbclass = self.pdbclass
# if self.capture is True here, it means it was explicitly specified
# in the user's TestCase class. If not, do what was asked on cmd line
self.capture = self.capture or getattr(result, 'capture', False)