def test_strerrorFormatting(self): """ L{_ErrorFormatter.formatError} should use L{os.strerror} to format error messages if it is constructed without any better mechanism. """ formatter = _ErrorFormatter(None, None, None) message = formatter.formatError(self.probeErrorCode) self.assertEqual(message, os.strerror(self.probeErrorCode))
def test_errorTab(self): """ L{_ErrorFormatter.formatError} should use C{errorTab} if it is supplied and contains the requested error code. """ formatter = _ErrorFormatter(None, None, {self.probeErrorCode: self.probeMessage}) message = formatter.formatError(self.probeErrorCode) self.assertEqual(message, self.probeMessage)
def test_errorTab(self): """ L{_ErrorFormatter.formatError} should use C{errorTab} if it is supplied and contains the requested error code. """ formatter = _ErrorFormatter( None, None, {self.probeErrorCode: self.probeMessage}) message = formatter.formatError(self.probeErrorCode) self.assertEqual(message, self.probeMessage)
def test_emptyErrorTab(self): """ L{_ErrorFormatter.formatError} should use L{os.strerror} to format error messages if it is constructed with only an error tab which does not contain the error code it is called with. """ error = 1 # Sanity check self.assertNotEqual(self.probeErrorCode, error) formatter = _ErrorFormatter(None, None, {error: 'wrong message'}) message = formatter.formatError(self.probeErrorCode) self.assertEqual(message, os.strerror(self.probeErrorCode))
def test_formatMessage(self): """ L{_ErrorFormatter.formatError} should return the return value of C{formatMessage} if it is supplied. """ formatCalls = [] def formatMessage(errorCode): formatCalls.append(errorCode) return self.probeMessage formatter = _ErrorFormatter( None, formatMessage, {self.probeErrorCode: 'wrong message'}) message = formatter.formatError(self.probeErrorCode) self.assertEqual(message, self.probeMessage) self.assertEqual(formatCalls, [self.probeErrorCode])
def test_winError(self): """ L{_ErrorFormatter.formatError} should return the message argument from the exception L{winError} returns, if L{winError} is supplied. """ winCalls = [] def winError(errorCode): winCalls.append(errorCode) return _MyWindowsException(errorCode, self.probeMessage) formatter = _ErrorFormatter( winError, lambda error: 'formatMessage: wrong message', {self.probeErrorCode: 'errorTab: wrong message'}) message = formatter.formatError(self.probeErrorCode) self.assertEqual(message, self.probeMessage)