o
    Óó·ik&  ã                   @  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                   @  s¼  e Zd ZU dZg 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‘Zd<ed=< dDd@dA„Z dDdBdC„Z!d-S )EÚ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.ÚsignalZ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ÚreturnÚNonec                 C  sJ   | j D ]}|d }|d }|d }|d }|  t||i |¤Žƒ|¡ qd S )Nr   é   é   é   )r   ÚassertEqualÚstr)ÚselfÚentryÚoutputÚ	exceptionÚargsÚkwargs© r   ú]C:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\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©r   r   )"Ú__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~  
 	þüý
ü÷üñëüêäãâ üá&üÛ,üÕ1Ï2Î4üÍ9Ç:Æ;Å<Ä=Ã?üÂD¼E»FºHü¹Nü³S­Uü¬[ü¦` büŸg™iü˜oü’uüŒ{ü† ü �ÿ ü �ù ü �ó ü �í ü �ç
ù 
(	r   c                   @  s.   e Zd ZdZddd„Zddd„Zddd	„Zd
S )ÚSubclassingTestsz=
    Some exceptions are subclasses of other exceptions.
    r   r   c                 C  ó   |   ttjtjƒ¡ dS )zW
        L{error.ConnectionClosed} is a superclass of L{error.ConnectionLost}.
        N)Ú
assertTrueÚ
issubclassr   r0   ÚConnectionClosed©r   r   r   r   Ú-test_connectionLostSubclassOfConnectionClosedÏ   ó   z>SubclassingTests.test_connectionLostSubclassOfConnectionClosedc                 C  r4   )zW
        L{error.ConnectionClosed} is a superclass of L{error.ConnectionDone}.
        N)r5   r6   r   r1   r7   r8   r   r   r   Ú-test_connectionDoneSubclassOfConnectionClosedÕ   r:   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_invalidAddressErrorSubclassOfValueErrorNr#   )r$   r%   r&   r'   r9   r;   r=   r   r   r   r   r3   Ê   s
    

r3   c                   @  sB   e Zd ZdZddd	„Zddd„Zddd„Zddd„Z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.
    ÚerrnoÚintÚexpectedClassútype[error.ConnectError]r   r   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?   rA   r!   Úresultr   r   r   ÚassertErrnoExceptioné   s   
z)GetConnectErrorTests.assertErrnoExceptionú
int | NoneÚmessager   rE   úerror.ConnectErrorc                 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?   rH   rE   rA   r   r   r   rD   õ   s   z+GetConnectErrorTests.assertCorrectExceptionc                 C  sb   |   tjtj¡ |   tjtj¡ |   tjtj¡ t	j
dkr/|   tjtj¡ |   tjtj¡ dS dS )zW
        L{error.getConnectError} converts based on errno for C{socket.error}.
        Úwin32N)rF   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   rC   r(   ÚgaierrorrD   r*   )r   rE   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   rC   rD   r)   )r   r!   rE   r   r   r   Útest_nonTuple  s   
z"GetConnectErrorTests.test_nonTupleN)r?   r@   rA   rB   r   r   )
r?   rG   rH   r   rE   rI   rA   rB   r   r   r#   )	r$   r%   r&   r'   rF   rD   rN   rQ   rS   r   r   r   r   r>   â   s    



r>   )Ú
__future__r   r?   r(   rL   Útypingr   Ztwisted.internetr   Ztwisted.trialr   ZSynchronousTestCaser   r3   r>   r   r   r   r   Ú<module>   s    =