o
    >hk&                     @  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.fooz3An error occurred binding to an interface: foo bar.barz"Couldn't listen on eth0:4242: Foo.eth0i  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.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.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.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.a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$   w/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/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   ConnectingCancelledErrorassertIsaddress)r   r*   er$   r$   r%   test_connectingCancelledError   s   
z2StringificationTests.test_connectingCancelledErrorr   r   )"__name__
__module____qualname____doc__r   	BindErrorCannotListenErrorsocketMessageLengthErrorDNSLookupErrorConnectErrorConnectBindErrorUnknownHostErrorNoRouteErrorConnectionRefusedErrorTCPTimedOutErrorBadFileErrorServiceNameUnknownError	UserErrorTimeoutErrorSSLErrorConnectionLostConnectionDoneConnectionFdescWentAwayAlreadyCalledAlreadyCancelledProcessDoneProcessTerminatedNotConnectingError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   rB   ConnectionClosedr   r$   r$   r%   -test_connectionLostSubclassOfConnectionClosed      z>SubclassingTests.test_connectionLostSubclassOfConnectionClosedc                 C  rM   )zW
        L{error.ConnectionClosed} is a superclass of L{error.ConnectionDone}.
        N)rN   rO   r   rC   rP   rQ   r$   r$   r%   -test_connectionDoneSubclassOfConnectionClosed   rS   z>SubclassingTests.test_connectionDoneSubclassOfConnectionClosedc                 C  s   |  ttjt dS )zP
        L{ValueError} is a superclass of L{error.InvalidAddressError}.
        N)rN   rO   r   InvalidAddressError
ValueErrorrQ   r$   r$   r%   ,test_invalidAddressErrorSubclassOfValueError   s   z=SubclassingTests.test_invalidAddressErrorSubclassOfValueErrorNr-   )r.   r/   r0   r1   rR   rT   rW   r$   r$   r$   r%   rL      s
    

rL   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.
        lalalaN)r   getConnectErrorassertCorrectException)r   rY   r[   r+   resultr$   r$   r%   assertErrnoException   s   
z)GetConnectErrorTests.assertErrnoException
int | Nonemessager'   r`   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__osErrorr"   )r   rY   rc   r`   r[   r$   r$   r%   r_      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)ra   rY   ENETUNREACHr   r:   ECONNREFUSEDr;   	ETIMEDOUTr<   sysplatformWSAECONNREFUSEDWSAENETUNREACHrQ   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.
           helloN)r   r^   r4   gaierrorr_   r9   )r   r`   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   r^   r_   r7   )r   r+   r`   r$   r$   r%   test_nonTuple  s   
z"GetConnectErrorTests.test_nonTupleN)rY   rZ   r[   r\   r   r   )
rY   rb   rc   r'   r`   rd   r[   r\   r   r   r-   )	r.   r/   r0   r1   ra   r_   ro   rs   ru   r$   r$   r$   r%   rX      s    



rX   )
__future__r   rY   r4   rk   typingr   twisted.internetr   twisted.trialr   SynchronousTestCaser   rL   rX   r$   r$   r$   r%   <module>   s    =