ó
[³XMc           @   s~   d  Z  d d l Z d d l Z d d l m Z d d l m Z d d l m Z m	 Z	 d d l
 m Z d e f d „  ƒ  YZ d S(	   s   
Test strerror
iÿÿÿÿN(   t   TestCase(   t   ECONNABORTED(   t   _ErrorFormattert   formatError(   t   platformt   ErrorFormatingTestCasec           B   s•   e  Z d  Z e Z d Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z e j ƒ  d k rl d	 e _ n  d
 „  Z e j ƒ  d k r“ d	 e _ n  RS(   s3   
    Tests for C{_ErrorFormatter.formatError}.
    s   correct message valuec         C   sD   t  d d d ƒ } | j |  j ƒ } |  j | t j |  j ƒ ƒ d S(   sž   
        L{_ErrorFormatter.formatError} should use L{os.strerror} to format
        error messages if it is constructed without any better mechanism.
        N(   R   t   NoneR   t   probeErrorCodet   assertEqualt   ost   strerror(   t   selft	   formattert   message(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_strerror.pyt   test_strerrorFormatting   s    c         C   sd   d } |  j  |  j | ƒ t d d i d | 6ƒ } | j |  j ƒ } |  j | t j |  j ƒ ƒ d S(   sØ   
        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.
        i   s   wrong messageN(   t   assertNotEqualR   R   R   R   R   R	   R
   (   R   t   errorR   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_strerror.pyt   test_emptyErrorTab#   s
    c         C   sH   t  d d i |  j |  j 6ƒ } | j |  j ƒ } |  j | |  j ƒ d S(   sˆ   
        L{_ErrorFormatter.formatError} should use C{errorTab} if it is supplied
        and contains the requested error code.
        N(   R   R   t   probeMessageR   R   R   (   R   R   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_strerror.pyt   test_errorTab1   s    c            ss   g  ‰ ‡  ‡ f d †  } t  d | i d ˆ  j 6ƒ } | j ˆ  j ƒ } ˆ  j | ˆ  j ƒ ˆ  j ˆ ˆ  j g ƒ d S(   s~   
        L{_ErrorFormatter.formatError} should return the return value of
        C{formatMessage} if it is supplied.
        c            s   ˆ j  |  ƒ ˆ  j S(   N(   t   appendR   (   t	   errorCode(   R   t   formatCalls(    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_strerror.pyt   formatMessageB   s    s   wrong messageN(   R   R   R   R   R   R   (   R   R   R   R   (    (   R   R   s>   /usr/lib/python2.7/dist-packages/twisted/test/test_strerror.pyt   test_formatMessage<   s    c            s`   g  ‰  ‡  ‡ f d †  } t  | d „  i d ˆ j 6ƒ } | j ˆ j ƒ } ˆ j | ˆ j ƒ d S(   sŸ   
        L{_ErrorFormatter.formatError} should return the message argument from
        the exception L{winError} returns, if L{winError} is supplied.
        c            s   ˆ  j  |  ƒ |  ˆ j f S(   N(   R   R   (   R   (   t   winCallsR   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_strerror.pyt   winErrorR   s    c         S   s   d S(   Ns   formatMessage: wrong message(    (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_strerror.pyt   <lambda>W   s    s   errorTab: wrong messageN(   R   R   R   R   R   (   R   R   R   R   (    (   R   R   s>   /usr/lib/python2.7/dist-packages/twisted/test/test_strerror.pyt   test_winErrorL   s    c         C   sù   t  j ƒ  } | j d k	 r` d d l m } |  j | j |  j ƒ | |  j ƒ d ƒ d | _ n  | j	 d k	 r° d d l
 m } |  j | j |  j ƒ | |  j ƒ ƒ d | _	 n  | j d k	 rõ d d l m } |  j | j |  j ƒ | |  j ƒ n  d S(   s›   
        L{_ErrorFormatter.fromEnvironment} should create an L{_ErrorFormatter}
        instance with attributes populated from available modules.
        iÿÿÿÿ(   t   WinErrori   (   t   FormatMessage(   t   errorTabN(   R   t   fromEnvironmentR   R   t   ctypesR   R   R   R   R   t   win32apiR   R   t   socket(   R   R   R   R   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_strerror.pyt   test_fromEnvironment]   s$    t   win32s'   This error lookup only works on Windowsc         C   s¤   t  j t g } y+ d d l m } | j | t ƒ d ƒ Wn t k
 rN n Xy' d d l m } | j | t ƒ ƒ Wn t k
 r‰ n X|  j	 t
 t ƒ | ƒ d S(   s½   
        Given an known-good errno, make sure that formatMessage gives results
        matching either C{socket.errorTab}, C{ctypes.WinError}, or
        C{win32api.FormatMessage}.
        iÿÿÿÿ(   R   i   (   R   N(   R#   R   R   R!   R   R   t   ImportErrorR"   R   t   assertInR   (   R   t
   acceptableR   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_strerror.pyt   test_correctLookups|   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R   R$   R   t   getTypet   skipR)   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_strerror.pyR      s   	
						(   R,   R#   R	   t   twisted.trial.unittestR    t   twisted.internet.tcpR   t   twisted.python.win32R   R   t   twisted.python.runtimeR   R   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_strerror.pyt   <module>   s   