Fixed #20445 -- Raised original exception after command error

This commit is contained in:
Jorge Bastida 2013-05-18 18:04:45 +02:00 committed by Claude Paroz
parent 4280217f31
commit 888c86dcf3
2 changed files with 19 additions and 17 deletions

View file

@ -1305,13 +1305,15 @@ class CommandTypes(AdminScriptTestCase):
sys.stderr = err = StringIO()
try:
command.execute = lambda args: args # This will trigger TypeError
with self.assertRaises(SystemExit):
command.run_from_argv(['', ''])
err_message = err.getvalue()
# Exceptions other than CommandError automatically output the traceback
self.assertIn("Traceback", err_message)
self.assertIn("TypeError", err_message)
# If the Exception is not CommandError it should always
# raise the original exception.
with self.assertRaises(TypeError):
command.run_from_argv(['', ''])
# If the Exception is CommandError and --traceback is not present
# this command should raise a SystemExit and don't print any
# traceback to the stderr.
command.execute = raise_command_error
err.truncate(0)
with self.assertRaises(SystemExit):
@ -1320,12 +1322,12 @@ class CommandTypes(AdminScriptTestCase):
self.assertNotIn("Traceback", err_message)
self.assertIn("CommandError", err_message)
# If the Exception is CommandError and --traceback is present
# this command should raise the original CommandError as if it
# were not a CommandError.
err.truncate(0)
with self.assertRaises(SystemExit):
with self.assertRaises(CommandError):
command.run_from_argv(['', '', '--traceback'])
err_message = err.getvalue()
self.assertIn("Traceback (most recent call last)", err_message)
self.assertIn("CommandError", err_message)
finally:
sys.stderr = old_stderr