U
    2ÜŸjk&  ã                   @  s‚   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
 G dd„ de
jƒZG dd	„ d	e
jƒZG d
d„ de
jƒZdS )é    )ÚannotationsN)ÚSequence)Úerror)Úunittestc                ,   @  sr  e Zd ZU dZdejg i fdejdgi fdejddgi fdejdd	e d
¡fi fdejg i fdejddgi fdej	g i fdej	ddgi fdej
g i fdej
dgi fdej
g ddifdej
ddgi fdejg i fdejdgi fdejddgi fdejg i fdejg i fdejg i fdejg i fdejg i fdejg i fdejg i fdejg i fd ejg i fd!ejg i fd"ejddgi fd#ejg i fd$ejddgi fd%ejg i fd&ejg i fd'ejddgi fd(ejg i fd)ejd*d+gi fd,ejd-gi fd.ejg i fd/ejg d0d1ifd2ejg d3d4ifd5ejg i fd6ejd*d7gi fd8ejg i fd9ejd:d;gi fg)Zd<ed=< d>d?œd@dA„Z d>d?œdBdC„Z!d-S )DÚStringificationTestsz6Test that the exceptions have useful stringifications.z*An error occurred binding to an interface.z/An error occurred binding to an interface: foo.Zfooz3An error occurred binding to an interface: foo bar.Úbarz"Couldn't listen on eth0:4242: Foo.Zeth0i’  ZFoozMessage is too long to send.z%Message is too long to send: foo bar.zDNS lookup failed.zDNS lookup failed: foo bar.z#An error occurred while connecting.z0An error occurred while connecting: someOsError.ZsomeOsErrorz(An error occurred while connecting: foo.Ústringz5An error occurred while connecting: someOsError: foo.zCouldn't bind.zCouldn't bind: someOsError.z Couldn't bind: someOsError: foo.zHostname couldn't be looked up.zNo route to host.z%Connection was refused by other side.zTCP connection timed out.z%File used for UNIX socket is no good.z&Service name given as port is unknown.zUser aborted connection.z'User timeout caused connection failure.zAn SSL error occurred.z=Connection to the other side was lost in a non-clean fashion.zFConnection to the other side was lost in a non-clean fashion: foo bar.zConnection was closed cleanly.z'Connection was closed cleanly: foo bar.zUh.z(Tried to cancel an already-called event.z1Tried to cancel an already-called event: foo bar.z+Tried to cancel an already-cancelled event.z0Tried to cancel an already-cancelled event: x 2.ÚxÚ2zOA process has ended without apparent errors: process finished with exit code 0.NzCA process has ended with a probable error condition: process ended.zUA process has ended with a probable error condition: process ended with exit code 42.ZexitCodeé*   zTA process has ended with a probable error condition: process ended by signal SIGBUS.ÚsignalÚSIGBUSzFThe Connector was not connecting when it was asked to stop connecting.zLThe Connector was not connecting when it was asked to stop connecting: x 13.Z13z?The Port was not listening when it was asked to stop listening.zEThe Port was not listening when it was asked to stop listening: a 12.ÚaZ12z_list[tuple[str, type[Exception], Sequence[str | int | Exception | None], dict[str, str | int]]]ÚlistOfTestsÚNone©Úreturnc                 C  sF   | j D ]:}|d }|d }|d }|d }|  t|||Žƒ|¡ qd S )Nr   é   é   é   )r   ÚassertEqualÚstr)ÚselfÚentryÚoutputÚ	exceptionÚargsÚkwargs© r   ú;/tmp/pip-unpacked-wheel-4b529toj/twisted/test/test_error.pyÚtestThemAll¸   s    
z StringificationTests.testThemAllc                 C  s"   t ƒ }t |¡}|  |j|¡ dS )zP
        L{error.ConnectingCancelledError} has an C{address} attribute.
        N)Úobjectr   ZConnectingCancelledErrorZassertIsÚaddress)r   r"   Úer   r   r   Útest_connectingCancelledErrorÁ   s    
z2StringificationTests.test_connectingCancelledError)"Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Z	BindErrorZCannotListenErrorÚsocketZMessageLengthErrorZDNSLookupErrorÚConnectErrorZConnectBindErrorÚUnknownHostErrorÚNoRouteErrorÚConnectionRefusedErrorÚTCPTimedOutErrorZBadFileErrorZServiceNameUnknownErrorZ	UserErrorÚTimeoutErrorÚSSLErrorÚConnectionLostÚConnectionDoneZConnectionFdescWentAwayZAlreadyCalledZAlreadyCancelledZProcessDoneZProcessTerminatedZNotConnectingErrorZNotListeningErrorr   Ú__annotations__r    r$   r   r   r   r   r      s  
üüüüüüüüüüüüüüüüüüüüüüü€ èù
 (	r   c                   @  s:   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zd
S )ÚSubclassingTestsz=
    Some exceptions are subclasses of other exceptions.
    r   r   c                 C  s   |   ttjtjƒ¡ dS )zW
        L{error.ConnectionClosed} is a superclass of L{error.ConnectionLost}.
        N)Ú
assertTrueÚ
issubclassr   r1   ÚConnectionClosed©r   r   r   r   Ú-test_connectionLostSubclassOfConnectionClosedÏ   s    z>SubclassingTests.test_connectionLostSubclassOfConnectionClosedc                 C  s   |   ttjtjƒ¡ dS )zW
        L{error.ConnectionClosed} is a superclass of L{error.ConnectionDone}.
        N)r5   r6   r   r2   r7   r8   r   r   r   Ú-test_connectionDoneSubclassOfConnectionClosedÕ   s    z>SubclassingTests.test_connectionDoneSubclassOfConnectionClosedc                 C  s   |   ttjtƒ¡ dS )zP
        L{ValueError} is a superclass of L{error.InvalidAddressError}.
        N)r5   r6   r   ZInvalidAddressErrorÚ
ValueErrorr8   r   r   r   Ú,test_invalidAddressErrorSubclassOfValueErrorÛ   s    z=SubclassingTests.test_invalidAddressErrorSubclassOfValueErrorN)r%   r&   r'   r(   r9   r:   r<   r   r   r   r   r4   Ê   s   r4   c                   @  sb   e Zd ZdZddddœdd„Zdd	d
dddœdd„Zddœdd„Zddœdd„Zddœdd„ZdS )ÚGetConnectErrorTestsz¢
    Given an exception instance thrown by C{socket.connect},
    L{error.getConnectError} returns the appropriate high-level Twisted
    exception instance.
    Úintztype[error.ConnectError]r   )ÚerrnoÚexpectedClassr   c                 C  s&   |df}t  |¡}|  |d||¡ dS )zª
        When called with a tuple with the given errno,
        L{error.getConnectError} returns an exception which is an instance of
        the expected class.
        ZlalalaN)r   ÚgetConnectErrorÚassertCorrectException)r   r?   r@   r#   Úresultr   r   r   ÚassertErrnoExceptioné   s    
z)GetConnectErrorTests.assertErrnoExceptionz
int | Noner!   zerror.ConnectError)r?   ÚmessagerC   r@   r   c                 C  s0   |   |j|¡ |   |j|¡ |   |j|f¡ dS )z 
        The given result of L{error.getConnectError} has the given attributes
        (C{osError} and C{args}), and is an instance of the given class.
        N)r   Ú	__class__ZosErrorr   )r   r?   rE   rC   r@   r   r   r   rB   õ   s    z+GetConnectErrorTests.assertCorrectExceptionr   c                 C  s^   |   tjtj¡ |   tjtj¡ |   tjtj¡ t	j
dkrZ|   tjtj¡ |   tjtj¡ dS )zW
        L{error.getConnectError} converts based on errno for C{socket.error}.
        Úwin32N)rD   r?   ZENETUNREACHr   r,   ZECONNREFUSEDr-   Z	ETIMEDOUTr.   ÚsysÚplatformZWSAECONNREFUSEDZWSAENETUNREACHr8   r   r   r   Ú
test_errno  s    
 ÿzGetConnectErrorTests.test_errnoc                 C  s(   t  t dd¡¡}|  dd|t j¡ dS )z
        L{error.getConnectError} converts to a L{error.UnknownHostError} given
        a C{socket.gaierror} instance.
        é   ZhelloN)r   rA   r)   ÚgaierrorrB   r+   )r   rC   r   r   r   Útest_gaierror  s    z"GetConnectErrorTests.test_gaierrorc                 C  s&   t ƒ }t |¡}|  d||tj¡ dS )z�
        L{error.getConnectError} converts to a L{error.ConnectError} given
        an argument that cannot be unpacked.
        N)Ú	Exceptionr   rA   rB   r*   )r   r#   rC   r   r   r   Útest_nonTuple  s    
z"GetConnectErrorTests.test_nonTupleN)	r%   r&   r'   r(   rD   rB   rJ   rM   rO   r   r   r   r   r=   â   s   r=   )Ú
__future__r   r?   r)   rH   Útypingr   Ztwisted.internetr   Ztwisted.trialr   ZSynchronousTestCaser   r4   r=   r   r   r   r   Ú<module>   s    =