From d7a16ecfcb76d50702375b3dbb66669e59818ddc Mon Sep 17 00:00:00 2001 From: Brad Warren Date: Thu, 1 Oct 2015 15:39:55 -0700 Subject: [PATCH] Added tests and documentation --- letsencrypt/error_handler.py | 5 +++-- letsencrypt/tests/error_handler_test.py | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/letsencrypt/error_handler.py b/letsencrypt/error_handler.py index 1292f2bc5..8b0eb7c8b 100644 --- a/letsencrypt/error_handler.py +++ b/letsencrypt/error_handler.py @@ -22,8 +22,8 @@ class ErrorHandler(object): """Registers functions to be called if an exception or signal occurs. This class allows you to register functions that will be called when - an exception or signal is encountered. The class works best as a - context manager. For example: + an exception (excluding SystemExit) or signal is encountered. The + class works best as a context manager. For example: with ErrorHandler(cleanup_func): do_something() @@ -50,6 +50,7 @@ class ErrorHandler(object): self.set_signal_handlers() def __exit__(self, exec_type, exec_value, trace): + # SystemExit is ignored to properly handle forks that don't exec if exec_type not in (None, SystemExit): logger.debug("Encountered exception:\n%s", "".join( traceback.format_exception(exec_type, exec_value, trace))) diff --git a/letsencrypt/tests/error_handler_test.py b/letsencrypt/tests/error_handler_test.py index 66acac930..c92f12435 100644 --- a/letsencrypt/tests/error_handler_test.py +++ b/letsencrypt/tests/error_handler_test.py @@ -1,5 +1,6 @@ """Tests for letsencrypt.error_handler.""" import signal +import sys import unittest import mock @@ -50,6 +51,14 @@ class ErrorHandlerTest(unittest.TestCase): self.init_func.assert_called_once_with() bad_func.assert_called_once_with() + def test_sysexit_ignored(self): + try: + with self.handler: + sys.exit(0) + except SystemExit: + pass + self.assertFalse(self.init_func.called) + if __name__ == "__main__": unittest.main() # pragma: no cover