diff options
author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> | 2007-05-15 17:37:17 +0200 |
---|---|---|
committer | Nicolas Chauvat <nicolas.chauvat@logilab.fr> | 2007-05-15 17:37:17 +0200 |
commit | 47147f99d475fcf72f7891a10287b2bb9c9799aa (patch) | |
tree | 943476621b6951a2b76502ae0b1b431f1d7dc4e1 | |
parent | 443e96c72eb3c03179c719dbd8754c25fa36db39 (diff) | |
parent | 9c39b6f0e92b3a0a812a56f5d110bd73704fc4de (diff) | |
download | logilab-common-47147f99d475fcf72f7891a10287b2bb9c9799aa.tar.gz |
do not leak internal rsh reports
-rw-r--r-- | testlib.py | 28 |
1 files changed, 27 insertions, 1 deletions
@@ -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) |