def test_trapReturns(self): """ The C{trap} method is like C{check} in that it returns the passed exception type that matches the failure's value. """ failure = SynchronousFailure(RuntimeError()) self.assertEquals(failure.trap(ZeroDivisionError, RuntimeError), RuntimeError)
def test_check(self): """ Check accepts multiple exception types, and returns the exception type which matched. """ failure = SynchronousFailure(RuntimeError()) self.assertEquals(failure.check(ZeroDivisionError, RuntimeError), RuntimeError)
def test_getExceptionFromEnvironment(self): """ SynchronousFailure infers the current exception and traceback from the environment. """ try: 1/0 except: failure = SynchronousFailure() self.assertTrue(failure.check(ZeroDivisionError))
def test_raiseException(self): """ C{raiseException} raises the original exception, including traceback. """ try: 1/0 except: failure = SynchronousFailure() try: failure.raiseException() except ZeroDivisionError, e: tb = traceback.extract_tb(sys.exc_info()[2]) innerline = tb[-1][-1]
def test_passInException(self): """ SynchronousFailure takes an Exception instance as its parameter. """ failure = SynchronousFailure(RuntimeError("hello")) self.assertTrue(failure.check(RuntimeError))