def testTranslateDeferredError(self): """If the decorated function returns a Deferred, the error should still be translated.""" def f(): return defer.fail(ivfs.VFSError('error message')) f = sftp.translateErrors(f) d = f() return self.assertFailure(d, SFTPError)
def testTranslateDeferredError2(self): """If the decorated function returns a Deferred that hasn't fired immediately, the error should still be translated.""" d = defer.Deferred() def f(): return d f = sftp.translateErrors(f) d2 = f() d.errback(ivfs.VFSError("foo")) return self.assertFailure(d2, SFTPError)
def assertTranslation(self, error, code): """Asserts that the translate_error decorator translates 'error' to an SFTPError with a code of 'code'.""" message = 'test error message' def f(): raise error(message) f = sftp.translateErrors(f) e = self.assertRaises(SFTPError, f) self.assertEqual(code, e.code) self.assertEqual(message, e.message)