Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_timeout.cpython-34.pyo

�
f fs,�@s�dZddlZddlZddlmZejd�ZddlZddlZddl	Z	ej
�dd��ZGdd�dej�Z
Gd	d
�d
ej�ZGdd�de�ZGd
d�de�Zdd�Zedkr�e�ndS)z&Unit tests for socket timeout feature.�N)�support�networkcCs>tj|��)tj||tjtj�ddSWdQXdS)z�Resolve an (host, port) to an address.

    We must perform name resolution before timeout tests, otherwise it will be
    performed by connect().
    r�N)r�transient_internet�socketZgetaddrinfo�AF_INET�SOCK_STREAM)�hostZport�r
�6/opt/alt/python34/lib64/python3.4/test/test_timeout.py�resolve_addresssrc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�CreationTestCasez9Test case for socket.gettimeout() and socket.settimeout()cCstjtjtj�|_dS)N)rrr�sock)�selfr
r
r�setUpszCreationTestCase.setUpcCs|jj�dS)N)r�close)rr
r
r�tearDown!szCreationTestCase.tearDowncCs |j|jj�dd�dS)Nztimeout not disabled by default)�assertEqualr�
gettimeout)rr
r
r�testObjectCreation$sz#CreationTestCase.testObjectCreationcCs|jjd�|j|jj�d�|jjd�|j|jj�d�|jjd�|j|jj�d�dS)Ng�z�Ga@�)r�
settimeoutrr)rr
r
r�testFloatReturnValue)sz%CreationTestCase.testFloatReturnValuecCsn|jjd�|jt|jj��td��|jjd�|jt|jj��td��dS)N�g�?g333333@)rrr�typer)rr
r
r�testReturnType4s%zCreationTestCase.testReturnTypecCs�|jjd�|jjd�|jjd�|jjd�|jt|jjd�|jt|jjd�|jt|jjf�|jt|jjg�|jt|jji�|jt|jjd�dS)Nrg�y)rr�assertRaises�	TypeError)rr
r
r�
testTypeCheck<szCreationTestCase.testTypeCheckcCsO|jt|jjd�|jt|jjd�|jt|jjd�dS)Nrg�?���r g�)r�
ValueErrorrr)rr
r
r�testRangeCheckIszCreationTestCase.testRangeCheckcCs�|jjd�|jjd�|j|jj�d�|jjd�|j|jj�d�|jjd�|jjd�|j|jj�d�|jjd�|j|jj�d�dS)N�
rrg)rr�setblockingrr)rr
r
r�testTimeoutThenBlockingOsz(CreationTestCase.testTimeoutThenBlockingcCsv|jjd�|jjd�|j|jj�d�|jjd�|jjd�|j|jj�d�dS)Nrr)rr$rrr)rr
r
r�testBlockingThenTimeout]sz(CreationTestCase.testBlockingThenTimeoutN)
�__name__�
__module__�__qualname__�__doc__rrrrrrr"r%r&r
r
r
rr
s
r
c@s=eZdZdZejZdd�ZeZdd�Z	dS)�TimeoutTestCaseg@cCs
t��dS)N)�NotImplementedError)rr
r
rrsszTimeoutTestCase.setUpc	Gs�|jj|�t|j|�}xwt|�D]\}tj�}y||�Wq/tjk
r�}ztj�|}PWYdd}~Xq/Xq/W|jd�|j|||j	�|j
||d�dS)z�
        Test the specified socket method.

        The method is run at most `count` times and must raise a socket.timeout
        within `timeout` + self.fuzz seconds.
        Nzsocket.timeout was not raisedg�?)rr�getattr�range�timer�timeoutZfailZ
assertLess�fuzzZ
assertGreater)	r�countr0�method�args�iZt1�eZdeltar
r
r�_sock_operationxs
zTimeoutTestCase._sock_operationN)
r'r(r)r1rZHOST�	localhostrrr7r
r
r
rr+hs
	r+c@sveZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�TCPTimeoutTestCasez3TCP test case for socket.socket() timeout functionscCs1tjtjtj�|_tdd�|_dS)Nzwww.python.org.�P)rrrrr�addr_remote)rr
r
rr�szTCPTimeoutTestCase.setUpcCs|jj�dS)N)rr)rr
r
rr�szTCPTimeoutTestCase.tearDownc CsJtdd�}tdd�}d}tjtjtj�}d}|j|�zly|j|�WnTtjk
rzYn@tk
r�}z |jtj	kr�d}nWYdd}~XnXWd|j
�~X|r|jdj|d	|d
||d	|d
��n||_
tj|j
d	��|jd
dd|j
�WdQXdS)
Nzblackhole.snakebite.netiZ�zwhitehole.snakebite.neti[�TrFz�We didn't receive a connection reset (RST) packet from {}:{} within {} seconds, so we're unable to test connect timeout against the corresponding {}:{} (which is configured to silently drop packets).rrg����MbP?�connect)rrrrrr<r0�OSError�errnoZECONNREFUSEDrZskipTest�formatr;rrr7)rZ	blackholeZ	whitehole�skiprr0�errr
r
r�testConnectTimeout�s4
 
	z%TCPTimeoutTestCase.testConnectTimeoutcCsJtj|jd��.|jj|j�|jdddd�WdQXdS)Nrrg�?Zrecvi)rrr;rr<r7)rr
r
r�testRecvTimeout�sz"TCPTimeoutTestCase.testRecvTimeoutcCs=tj|j|j�|jjd�|jddd�dS)N�rg�?Zaccept)r�	bind_portrr8�listenr7)rr
r
r�testAcceptTimeout�sz$TCPTimeoutTestCase.testAcceptTimeoutc
Csutjtjtj��W}tj||j�|jd�|jj|j	��|j
ddddd�WdQXdS)NrD�dg�?�send�Xi@
)rrrrrEr8rFrr<�getsocknamer7)r�servr
r
r�testSend�s

zTCPTimeoutTestCase.testSendc
Cs~tjtjtj��`}tj||j�|jd�|jj|j	��|j
ddddd|j	��WdQXdS)NrDrHg�?ZsendtorJi@
)rrrrrEr8rFrr<rKr7)rrLr
r
r�
testSendtos
zTCPTimeoutTestCase.testSendtoc
Csutjtjtj��W}tj||j�|jd�|jj|j	��|j
ddddd�WdQXdS)NrDrHg�?ZsendallrJi@
)rrrrrEr8rFrr<rKr7)rrLr
r
r�testSendalls

zTCPTimeoutTestCase.testSendallN)r'r(r)r*rrrBrCrGrMrNrOr
r
r
rr9�sT	
r9c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�UDPTimeoutTestCasez3UDP test case for socket.socket() timeout functionscCstjtjtj�|_dS)N)rrZ
SOCK_DGRAMr)rr
r
rrszUDPTimeoutTestCase.setUpcCs|jj�dS)N)rr)rr
r
rrszUDPTimeoutTestCase.tearDowncCs0tj|j|j�|jdddd�dS)Nrg�?Zrecvfromi)rrErr8r7)rr
r
r�testRecvfromTimeoutsz&UDPTimeoutTestCase.testRecvfromTimeoutN)r'r(r)r*rrrQr
r
r
rrPsrPcCs$tjd�tjttt�dS)Nr)rZrequiresZrun_unittestr
r9rPr
r
r
r�	test_main&s

rR�__main__)r*�	functoolsZunittestZtestrZis_resource_enabledZ
skip_expectedr/r>r�	lru_cacherZTestCaser
r+r9rPrRr'r
r
r
r�<module>sM'�