<s> """<STR_LIT>""" <EOL> import socket <EOL> import os <EOL> from twisted . trial . unittest import TestCase <EOL> from twisted . internet . tcp import ECONNABORTED <EOL> from twisted . python . win32 import _ErrorFormatter , formatError <EOL> from twisted . python . runtime import platform <EOL> class _MyWindowsException ( OSError ) : <EOL> """<STR_LIT>""" <EOL> class ErrorFormatingTestCase ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> probeErrorCode = ECONNABORTED <EOL> probeMessage = "<STR_LIT>" <EOL> def test_strerrorFormatting ( self ) : <EOL> """<STR_LIT>""" <EOL> formatter = _ErrorFormatter ( None , None , None ) <EOL> message = formatter . formatError ( self . probeErrorCode ) <EOL> self . assertEqual ( message , os . strerror ( self . probeErrorCode ) ) <EOL> def test_emptyErrorTab ( self ) : <EOL> """<STR_LIT>""" <EOL> error = <NUM_LIT:1> <EOL> self . assertNotEqual ( self . probeErrorCode , error ) <EOL> formatter = _ErrorFormatter ( None , None , { error : '<STR_LIT>' } ) <EOL> message = formatter . formatError ( self . probeErrorCode ) <EOL> self . assertEqual ( message , os . strerror ( self . probeErrorCode ) ) <EOL> def test_errorTab ( self ) : <EOL> """<STR_LIT>""" <EOL> formatter = _ErrorFormatter ( <EOL> None , None , { self . probeErrorCode : self . probeMessage } ) <EOL> message = formatter . formatError ( self . probeErrorCode ) <EOL> self . assertEqual ( message , self . probeMessage ) <EOL> def test_formatMessage ( self ) : <EOL> """<STR_LIT>""" <EOL> formatCalls = [ ] <EOL> def formatMessage ( errorCode ) : <EOL> formatCalls . append ( errorCode ) <EOL> return self . probeMessage <EOL> formatter = _ErrorFormatter ( <EOL> None , formatMessage , { self . probeErrorCode : '<STR_LIT>' } ) <EOL> message = formatter . formatError ( self . probeErrorCode ) <EOL> self . assertEqual ( message , self . probeMessage ) <EOL> self . assertEqual ( formatCalls , [ self . probeErrorCode ] ) <EOL> def test_winError ( self ) : <EOL> """<STR_LIT>""" <EOL> winCalls = [ ] <EOL> def winError ( errorCode ) : <EOL> winCalls . append ( errorCode ) <EOL> return _MyWindowsException ( errorCode , self . probeMessage ) <EOL> formatter = _ErrorFormatter ( <EOL> winError , <EOL> lambda error : '<STR_LIT>' , <EOL> { self . probeErrorCode : '<STR_LIT>' } ) <EOL> message = formatter . formatError ( self . probeErrorCode ) <EOL> self . assertEqual ( message , self . probeMessage ) <EOL> def test_fromEnvironment ( self ) : <EOL> """<STR_LIT>""" <EOL> formatter = _ErrorFormatter . fromEnvironment ( ) <EOL> if formatter . winError is not None : <EOL> from ctypes import WinError <EOL> self . assertEqual ( <EOL> formatter . formatError ( self . probeErrorCode ) , <EOL> WinError ( self . probeErrorCode ) . strerror ) <EOL> formatter . winError = None <EOL> if formatter . formatMessage is not None : <EOL> from win32api import FormatMessage <EOL> self . assertEqual ( <EOL> formatter . formatError ( self . probeErrorCode ) , <EOL> FormatMessage ( self . probeErrorCode ) ) <EOL> formatter . formatMessage = None <EOL> if formatter . errorTab is not None : <EOL> from socket import errorTab <EOL> self . assertEqual ( <EOL> formatter . formatError ( self . probeErrorCode ) , <EOL> errorTab [ self . probeErrorCode ] ) <EOL> if platform . getType ( ) != "<STR_LIT:win32>" : <EOL> test_fromEnvironment . skip = "<STR_LIT>" <EOL> def test_correctLookups ( self ) : <EOL> """<STR_LIT>""" <EOL> acceptable = [ socket . errorTab [ ECONNABORTED ] ] <EOL> try : <EOL> from ctypes import WinError <EOL> acceptable . append ( WinError ( ECONNABORTED ) . strerror ) <EOL> except ImportError : <EOL> pass <EOL> try : <EOL> from win32api import FormatMessage <EOL> acceptable . append ( FormatMessage ( ECONNABORTED ) ) <EOL> except ImportError : <EOL> pass <EOL> self . assertIn ( formatError ( ECONNABORTED ) , acceptable ) <EOL> if platform . getType ( ) != "<STR_LIT:win32>" : <EOL> test_correctLookups . skip = "<STR_LIT>" </s>
