Beispiel #1
0
    def test_stderr(self):
        """Unhandled exceptions are also sent to stderr."""
        fh = cStringIO.StringIO()

        # call
        orig_stderr = sys.stderr
        sys.stderr = fh
        exc = self._get_exception_data()
        try:
            exception_handler(*exc)
        finally:
            sys.stderr = orig_stderr

        # check
        shown = fh.getvalue()
        self.assertTrue("Traceback" in shown)
        self.assertTrue("ZeroDivisionError" in shown)
Beispiel #2
0
    def test_logs(self):
        """Unhandled exceptions logs in error."""
        # set up logger
        handler = MementoHandler()
        handler.setLevel(logging.DEBUG)
        l = logging.getLogger('magicicada')

        # call
        l.addHandler(handler)
        self.addCleanup(l.removeHandler, handler)
        exc = self._get_exception_data()
        try:
            exception_handler(*exc)
        finally:
            l.removeHandler(handler)

        # check
        self.assertTrue(handler.check_error("Unhandled exception",
                                            "ZeroDivisionError"))