U
    
W[!                     @   s~   d dl mZm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 )    )divisionabsolute_importN)unittest)error)platformTypec                ,   @   s  e Zd ZdZ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g)Zd<d= Zd>d? Z d-S )@StringificationTestsz;Test 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.Z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12c              	   C   s   | j D ]v}|d }|d }z|d }W n tk
r>   d}Y nX z|d }W n tk
rd   i }Y nX | t|||| qd S )Nr             )listOfTests
IndexErrorassertEqualstr)selfentryoutputZ	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   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TimeoutErrorZSSLErrorConnectionLostConnectionDoneZConnectionFdescWentAwayZAlreadyCalledZAlreadyCancelledZProcessDoneZProcessTerminatedZNotConnectingErrorZNotListeningErrorr   r   r!   r   r   r   r   r      s.                    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   s   |  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   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)r0   r1   r   r.   r2   r3   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)r0   r1   r   ZInvalidAddressError
ValueErrorr3   r   r   r   ,test_invalidAddressErrorSubclassOfValueError   s    
z=SubclassingTests.test_invalidAddressErrorSubclassOfValueErrorN)r"   r#   r$   r%   r4   r5   r7   r   r   r   r   r/      s   r/   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.
        Z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__ZosErrorr   )r   r;   messager=   r<   r   r   r   r:      s    z+GetConnectErrorTests.assertCorrectExceptionc                 C   s\   |  tjtj |  tjtj |  tjtj t	dkrX|  tj
tj |  tjtj dS )zW
        L{error.getConnectError} converts based on errno for C{socket.error}.
        Zwin32N)r>   r;   ZENETUNREACHr   r)   ZECONNREFUSEDr*   Z	ETIMEDOUTr+   r   ZWSAECONNREFUSEDZWSAENETUNREACHr3   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   r9   r&   Zgaierrorr:   r(   )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   r9   r:   r'   )r   r    r=   r   r   r   test_nonTuple  s    
z"GetConnectErrorTests.test_nonTupleN)	r"   r#   r$   r%   r>   r:   rA   rC   rE   r   r   r   r   r8      s   	r8   )Z
__future__r   r   r&   r;   Ztwisted.trialr   Ztwisted.internetr   Ztwisted.python.runtimer   ZSynchronousTestCaser   r/   r8   r   r   r   r   <module>   s    &