o
    b"                     @   sn   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 )    N)error)platformType)unittestc                   @   s6  e Zd ZdZg dejfdejdgfdejddgfdejdd	ed
ffdejfdejddgfdej	fdej	ddgfdej
fdej
dgfdej
g ddifdej
ddgfdejfdejdgfdejddgfdejfdejfdejfdejfdejfdejfdejfdejfd ejfd!ejfd"ejddgfd#ejfd$ejddgfd%ejfd&ejfd'ejddgfd(ejfd)ejd*d+gfd,ejd-gfd.ejfd/ejg d0d1ifd2ejg d3d4ifd5ejfd6ejd*d7gfd8ejfd9ejd:d;gfZd<d= Zd>d? Z d-S )@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12c              	   C   s   | j D ];}|d }|d }z|d }W n ty   d}Y nw z|d }W n ty0   i }Y nw | t||i || qd S )Nr             )listOfTests
IndexErrorassertEqualstr)selfentryoutput	exceptionargskwargsr   r   9/usr/lib/python3/dist-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)!__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   r$   r*   r   r   r   r#   r      s(   
#'(*./01234568<@BGJLPRW\`flpuyr   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	SubclassingTestsz=
    Some exceptions are subclasses of other exceptions.
    c                 C      |  ttjtj dS )zW
        L{error.ConnectionClosed} is a superclass of L{error.ConnectionLost}.
        N)
assertTrue
issubclassr   r?   ConnectionClosedr   r   r   r#   -test_connectionLostSubclassOfConnectionClosed      z>SubclassingTests.test_connectionLostSubclassOfConnectionClosedc                 C   rI   )zW
        L{error.ConnectionClosed} is a superclass of L{error.ConnectionDone}.
        N)rJ   rK   r   r@   rL   rM   r   r   r#   -test_connectionDoneSubclassOfConnectionClosed   rO   z>SubclassingTests.test_connectionDoneSubclassOfConnectionClosedc                 C   s   |  ttjt dS )zP
        L{ValueError} is a superclass of L{error.InvalidAddressError}.
        N)rJ   rK   r   InvalidAddressError
ValueErrorrM   r   r   r#   ,test_invalidAddressErrorSubclassOfValueError   s   z=SubclassingTests.test_invalidAddressErrorSubclassOfValueErrorN)r+   r,   r-   r.   rN   rP   rS   r   r   r   r#   rH      s
    rH   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Z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.
    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   errnoexpectedClassr)   resultr   r   r#   assertErrnoException   s   
z)GetConnectErrorTests.assertErrnoExceptionc                 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   rX   messagerZ   rY   r   r   r#   rW      s   z+GetConnectErrorTests.assertCorrectExceptionc                 C   s`   |  tjtj |  tjtj |  tjtj t	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)r[   rX   ENETUNREACHr   r7   ECONNREFUSEDr8   	ETIMEDOUTr9   r   WSAECONNREFUSEDWSAENETUNREACHrM   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   rV   r1   gaierrorrW   r6   )r   rZ   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   rV   rW   r4   )r   r)   rZ   r   r   r#   test_nonTuple   s   
z"GetConnectErrorTests.test_nonTupleN)	r+   r,   r-   r.   r[   rW   re   ri   rk   r   r   r   r#   rT      s    
rT   )rX   r1   twisted.internetr   twisted.python.runtimer   twisted.trialr   SynchronousTestCaser   rH   rT   r   r   r   r#   <module>   s    