Cleanup recent generalization in post mortem debugger

Remove unnecessary default arguments and constants in
the post mortem debugger code.

Also remove exception internationalization in testing code.

Change-Id: I66ba3248a7ff502fa92e1c46f40e280c503524a2
This commit is contained in:
Miguel Ángel Ajo 2014-11-28 18:00:04 +01:00 committed by Miguel Angel Ajo
parent 988bd650d2
commit 13120bbd27
2 changed files with 10 additions and 12 deletions

View File

@ -16,25 +16,23 @@
import functools import functools
import traceback import traceback
DEFAULT_DEBUGGER = 'pdb'
def get_exception_handler(debugger_name):
def get_exception_handler(debugger_name=None): debugger = _get_debugger(debugger_name)
debugger = _get_debugger(debugger_name or DEFAULT_DEBUGGER)
return functools.partial(_exception_handler, debugger) return functools.partial(_exception_handler, debugger)
def _get_debugger(debugger_name): def _get_debugger(debugger_name):
try: try:
debugger = __import__(debugger_name) debugger = __import__(debugger_name)
if 'post_mortem' in dir(debugger):
return debugger
except ImportError: except ImportError:
raise ValueError( raise ValueError("can't import %s module as a post mortem debugger" %
_("can't import %s module as a post mortem debugger") % debugger_name)
debugger_name) if 'post_mortem' in dir(debugger):
raise ValueError( return debugger
_("%s is not a supported post mortem debugger") % debugger_name) else:
raise ValueError("%s is not a supported post mortem debugger" %
debugger_name)
def _exception_handler(debugger, exc_info): def _exception_handler(debugger, exc_info):

View File

@ -34,7 +34,7 @@ class TestTesttoolsExceptionHandler(base.BaseTestCase):
with mock.patch.object(post_mortem_debug, with mock.patch.object(post_mortem_debug,
'get_ignored_traceback', 'get_ignored_traceback',
return_value=mock.Mock()): return_value=mock.Mock()):
post_mortem_debug.get_exception_handler()(exc_info) post_mortem_debug.get_exception_handler('pdb')(exc_info)
# traceback will become post_mortem_debug.FilteredTraceback # traceback will become post_mortem_debug.FilteredTraceback
filtered_exc_info = (exc_info[0], exc_info[1], mock.ANY) filtered_exc_info = (exc_info[0], exc_info[1], mock.ANY)