Exemplo n.º 1
0
 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))
Exemplo n.º 2
0
 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))
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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))
Exemplo n.º 6
0
 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))
Exemplo n.º 7
0
 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])
Exemplo n.º 8
0
 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])
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
 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)