Ë
    ojg  ã                   ó„   — 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 ddl	m
Z
mZ ddlmZ  G d„ d	e«      Z G d
„ de«      Zy)z
Test strerror
é    N)ÚskipIf)ÚECONNABORTED)Úplatform)Ú_ErrorFormatterÚformatError)ÚTestCasec                   ó   — e Zd ZdZy)Ú_MyWindowsExceptionzT
    An exception type like L{ctypes.WinError}, but available on all platforms.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    ú</usr/lib/python3/dist-packages/twisted/test/test_strerror.pyr
   r
      s   „ òr   r
   c                   óº   — e Zd ZdZeZdZd„ Zd„ Zd„ Z	d„ Z
d„ Z e ej                  «       dk7  d	«      d
„ «       Z e ej                  «       dk7  d	«      d„ «       Zy)ÚErrorFormatingTestsz3
    Tests for C{_ErrorFormatter.formatError}.
    zcorrect message valuec                 ó²   — t        ddd«      }|j                  | j                  «      }| j                  |t	        j
                  | j                  «      «       y)zž
        L{_ErrorFormatter.formatError} should use L{os.strerror} to format
        error messages if it is constructed without any better mechanism.
        N)r   r   ÚprobeErrorCodeÚassertEqualÚosÚstrerror©ÚselfÚ	formatterÚmessages      r   Útest_strerrorFormattingz+ErrorFormatingTests.test_strerrorFormatting    sG   € ô
 $ D¨$°Ó5ˆ	Ø×'Ñ'¨×(;Ñ(;Ó<ˆØ×Ñ˜¤"§+¡+¨d×.AÑ.AÓ"BÕCr   c                 óò   — d}| j                  | j                  |«       t        dd|di«      }|j                  | j                  «      }| j	                  |t        j                  | j                  «      «       y)zØ
        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.
        é   Núwrong message)ÚassertNotEqualr   r   r   r   r   r   )r   Úerrorr   r   s       r   Útest_emptyErrorTabz&ErrorFormatingTests.test_emptyErrorTab)   sg   € ð ˆà×Ñ˜D×/Ñ/°Ô7Ü# D¨$°¸Ð0HÓIˆ	Ø×'Ñ'¨×(;Ñ(;Ó<ˆØ×Ñ˜¤"§+¡+¨d×.AÑ.AÓ"BÕCr   c                 ó¸   — t        dd| j                  | j                  i«      }|j                  | j                  «      }| j	                  || j                  «       y)zˆ
        L{_ErrorFormatter.formatError} should use C{errorTab} if it is supplied
        and contains the requested error code.
        N)r   r   ÚprobeMessager   r   r   s      r   Útest_errorTabz!ErrorFormatingTests.test_errorTab6   sT   € ô
 $Ø�$˜×,Ñ,¨d×.?Ñ.?Ð@ó
ˆ	ð ×'Ñ'¨×(;Ñ(;Ó<ˆØ×Ñ˜ $×"3Ñ"3Õ4r   c                 óò   ‡ ‡— g Šˆˆ fd„}t        d|‰ j                  di«      }|j                  ‰ j                  «      }‰ j                  |‰ j                  «       ‰ j                  ‰‰ j                  g«       y)z~
        L{_ErrorFormatter.formatError} should return the return value of
        C{formatMessage} if it is supplied.
        c                 ó>   •— ‰j                  | «       ‰j                  S ©N)Úappendr%   )Ú	errorCodeÚformatCallsr   s    €€r   ÚformatMessagez=ErrorFormatingTests.test_formatMessage.<locals>.formatMessageH   s   ø€ Ø×Ñ˜yÔ)Ø×$Ñ$Ð$r   Nr    ©r   r   r   r   r%   )r   r-   r   r   r,   s   `   @r   Útest_formatMessagez&ErrorFormatingTests.test_formatMessageA   st   ù€ ð
 ˆõ	%ô $Ø�- $×"5Ñ"5°Ð!Gó
ˆ	ð ×'Ñ'¨×(;Ñ(;Ó<ˆØ×Ñ˜ $×"3Ñ"3Ô4Ø×Ñ˜ t×':Ñ':Ð&;Õ<r   c                 óº   ‡ ‡— g Šˆ ˆfd„}t        |d„ ‰ j                  di«      }|j                  ‰ j                  «      }‰ j                  |‰ j                  «       y)zŸ
        L{_ErrorFormatter.formatError} should return the message argument from
        the exception L{winError} returns, if L{winError} is supplied.
        c                 óR   •— ‰j                  | «       t        | ‰j                  «      S r)   )r*   r
   r%   )r+   r   ÚwinCallss    €€r   ÚwinErrorz3ErrorFormatingTests.test_winError.<locals>.winErrorZ   s"   ø€ Ø�O‰O˜IÔ&Ü& y°$×2CÑ2CÓDÐDr   c                  ó   — y)NzformatMessage: wrong messager   )r"   s    r   ú<lambda>z3ErrorFormatingTests.test_winError.<locals>.<lambda>`   s   � r   zerrorTab: wrong messageNr.   )r   r3   r   r   r2   s   `   @r   Útest_winErrorz!ErrorFormatingTests.test_winErrorS   s_   ù€ ð
 ˆõ	Eô $ØÙ8Ø× Ñ Ð";Ð<ó
ˆ	ð
 ×'Ñ'¨×(;Ñ(;Ó<ˆØ×Ñ˜ $×"3Ñ"3Õ4r   Úwin32zTest will run only on Windows.c                 ó&  — t        j                  «       }|j                  �Rddlm} | j                  |j                  | j                  «       || j                  «      j                  «       d|_        |j                  �Hddl
m} | j                  |j                  | j                  «       || j                  «      «       d|_	        |j                  �?ddlm} | j                  |j                  | j                  «      || j                     «       yy)z›
        L{_ErrorFormatter.fromEnvironment} should create an L{_ErrorFormatter}
        instance with attributes populated from available modules.
        Nr   ©ÚWinError©ÚFormatMessage)ÚerrorTab)r   ÚfromEnvironmentr3   Úctypesr:   r   r   r   r   r-   Úwin32apir<   r=   Úsocket)r   r   r:   r<   r=   s        r   Útest_fromEnvironmentz(ErrorFormatingTests.test_fromEnvironmentf   sî   € ô $×3Ñ3Ó5ˆ	à×ÑÐ)Ý'à×ÑØ×%Ñ% d×&9Ñ&9Ó:Ù˜×,Ñ,Ó-×6Ñ6ôð "&ˆIÔà×"Ñ"Ð.Ý.à×ÑØ×%Ñ% d×&9Ñ&9Ó:Ù˜d×1Ñ1Ó2ôð '+ˆIÔ#à×ÑÐ)Ý'à×ÑØ×%Ñ% d×&9Ñ&9Ó:Ø˜×,Ñ,Ñ-õð *r   c                 óJ  — t         j                  t           g}	 ddlm} |j                   |t        «      j                  «       	 ddlm	} |j                   |t        «      «       | j                  t        t        «      |«       y# t        $ r Y ŒMw xY w# t        $ r Y Œ:w xY w)z¼
        Given a known-good errno, make sure that formatMessage gives results
        matching either C{socket.errorTab}, C{ctypes.WinError}, or
        C{win32api.FormatMessage}.
        r   r9   r;   N)rA   r=   r   r?   r:   r*   r   ÚImportErrorr@   r<   ÚassertInr   )r   Ú
acceptabler:   r<   s       r   Útest_correctLookupsz'ErrorFormatingTests.test_correctLookupsˆ   s�   € ô —o‘o¤lÑ3Ð4ˆ
ð	Ý'à×Ñ™h¤|Ó4×=Ñ=Ô>ð	Ý.à×Ñ™m¬LÓ9Ô:ð 	�‰”k¤,Ó/°Õ<øô ò 	Ùð	ûô ò 	Ùð	ús#   š+B Á!B Â	BÂBÂ	B"Â!B"N)r   r   r   r   r   r   r%   r   r#   r&   r/   r6   r   r   ÚgetTyperB   rG   r   r   r   r   r      s‹   „ ñð "€NØ*€LòDòDò	5ò=ò$5ñ& ÐˆH×ÑÓ 'Ñ)Ð+KÓLñó MðñB ÐˆH×ÑÓ 'Ñ)Ð+KÓLñ=ó Mñ=r   r   )r   r   rA   Úunittestr   Útwisted.internet.tcpr   Útwisted.python.runtimer   Útwisted.python.win32r   r   Útwisted.trial.unittestr   ÚOSErrorr
   r   r   r   r   ú<module>rO      s;   ðñó 
Û Ý å -Ý +ß =Ý +ô˜'ô ôE=˜(õ E=r   