
    Vhg                         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__     J/home/dcms/DCMS/lib/python3.12/site-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"    OOI&&y$2C2C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     ool34
	'h|4==>	.mL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   