Your IP : 216.73.216.52


Current Path : /opt/alt/python37/lib64/python3.7/test/test_asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/test/test_asyncio/__pycache__/test_unix_events.cpython-37.pyc

B

� f�@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddl
mZddlmZe
jdkr�e
�d��ddlZddlmZddlmZdd	lmZdd
lmZddlmZejZdd
�Ze
�ed�Gdd�dej��Z e
�e!ed�d�Gdd�dej��Z"e
�e!ed�d�Gdd�dej��Z#Gdd�dej�Z$Gdd�dej�Z%Gdd�de
j�Z&Gdd �d e
j�Z'e�(d!d"�Z)Gd#d$�d$�Z*Gd%d&�d&e*ej�Z+Gd'd(�d(e*ej�Z,Gd)d*�d*e
j�Z-Gd+d,�d,e
j�Z.e/d-k�re
�0�dS).zTests for unix_events.py.�N)�mock)�supportZwin32z	UNIX only)�log)�base_events)�events)�unix_events)�utilscCs"|jdkrdS|j��d|_dS)N)Z_pipe�close)�	transport�r�G/opt/alt/python37/lib64/python3.7/test/test_asyncio/test_unix_events.py�close_pipe_transport"s

r
zSignals are not supportedcsFeZdZ�fdd�Zdd�Zdd�Zdd�Ze�d	�d
d��Z	e�d	�dd
��Z
e�d	�dd��Ze�d	�dd��Ze�d	�e�d�dd���Z
e�d	�e�d�dd���Ze�d	�dd��Ze�d	�dd��Ze�d	�e�d�dd���Ze�d	�dd��Ze�d	�dd ��Ze�d	�d!d"��Ze�d#�e�d	�d$d%���Z�ZS)&�SelectorEventLoopSignalTestscs$t���t��|_|�|j�dS)N)�super�setUp�asyncio�SelectorEventLoop�loop�set_event_loop)�self)�	__class__rrr.s

z"SelectorEventLoopSignalTests.setUpcCs.|�t|jjd�|�t|jjtjd�dS)N�1�)�assertRaises�	TypeErrorrZ
_check_signal�
ValueError�signal�NSIG)rrrr�test_check_signal3sz.SelectorEventLoopSignalTests.test_check_signalcCs|j�tjd�dS)Nr)r�_handle_signalrr)rrrr�test_handle_signal_no_handler9sz:SelectorEventLoopSignalTests.test_handle_signal_no_handlercCshtjt��dt��d�}|��||jjtjd<t��|j_	|j�
tjd�|jj	�tjd�dS)Nr)rr)r�Handler�Mock�cancelr�_signal_handlersrr�remove_signal_handlerr�assert_called_with)r�hrrr�$test_handle_signal_cancelled_handler<szASelectorEventLoopSignalTests.test_handle_signal_cancelled_handlerzasyncio.unix_events.signalcCs.tj|_t|j_|�t|jjtj	dd��dS)NcSsdS)NTrrrrr�<lambda>M�zRSelectorEventLoopSignalTests.test_add_signal_handler_setup_error.<locals>.<lambda>)
rrr�
set_wakeup_fd�side_effectr�RuntimeErrorr�add_signal_handler�SIGINT)r�m_signalrrr�#test_add_signal_handler_setup_errorEsz@SelectorEventLoopSignalTests.test_add_signal_handler_setup_errorcCsTtj|_dd�}|}|�}|�|j�x(||fD]}|�td|jjtj|�q0WdS)Nc�sdS)Nrrrrr�simple_coroutineSsz^SelectorEventLoopSignalTests.test_add_signal_handler_coroutine_error.<locals>.simple_coroutinez1coroutines cannot be used with add_signal_handler)	rr�
addCleanupr	�assertRaisesRegexrrr.r/)rr0r2Z	coro_funcZcoro_obj�funcrrr�'test_add_signal_handler_coroutine_errorOszDSelectorEventLoopSignalTests.test_add_signal_handler_coroutine_errorcCsPtj|_dd�}|j�tj|�|jj�tj�}|�|tj	�|�
|j|�dS)NcSsdS)NTrrrrrr)dr*zFSelectorEventLoopSignalTests.test_add_signal_handler.<locals>.<lambda>)rrrr.�SIGHUPr$�get�assertIsInstancerr!�assertEqualZ	_callback)rr0�cbr'rrr�test_add_signal_handler`sz4SelectorEventLoopSignalTests.test_add_signal_handlercCsLtj|_dd�}||_Gdd�dt�}||j_|�||jjtjdd��dS)NcSs|dkrt��dS)N���)r)�fdrrrr+nszYSelectorEventLoopSignalTests.test_add_signal_handler_install_error.<locals>.set_wakeup_fdc@seZdZejZdS)zOSelectorEventLoopSignalTests.test_add_signal_handler_install_error.<locals>.ErrN)�__name__�
__module__�__qualname__�errnoZEFAULTrrrr�ErrssrCcSsdS)NTrrrrrr)zr*zTSelectorEventLoopSignalTests.test_add_signal_handler_install_error.<locals>.<lambda>)	rrr+�OSErrorr,rrr.r/)rr0r+rCrrr�%test_add_signal_handler_install_errorjszBSelectorEventLoopSignalTests.test_add_signal_handler_install_errorzasyncio.base_events.loggercCsntj|_Gdd�dt�}||j_dd�|jjtj<|�t|jj	tj
dd��|�|jj
�|�d|jj�dS)Nc@seZdZejZdS)zPSelectorEventLoopSignalTests.test_add_signal_handler_install_error2.<locals>.ErrN)r?r@rArB�EINVALrrrrrC�srCcSsdS)NTrrrrrr)�r*zUSelectorEventLoopSignalTests.test_add_signal_handler_install_error2.<locals>.<lambda>cSsdS)NTrrrrrr)�r*r)rrrDr,rr$r7rr-r.r/�assertFalse�info�calledr:r+�
call_count)r�	m_loggingr0rCrrr�&test_add_signal_handler_install_error2|szCSelectorEventLoopSignalTests.test_add_signal_handler_install_error2cCs\Gdd�dt�}||j_tj|_|�t|jjtjdd��|�	|j
j�|�d|j
j�dS)Nc@seZdZejZdS)zPSelectorEventLoopSignalTests.test_add_signal_handler_install_error3.<locals>.ErrN)r?r@rArBrFrrrrrC�srCcSsdS)NTrrrrrr)�r*zUSelectorEventLoopSignalTests.test_add_signal_handler_install_error3.<locals>.<lambda>�)rDrr,rrr-rr.r/rGrHrIr:r+rJ)rrKr0rCrrr�&test_add_signal_handler_install_error3�szCSelectorEventLoopSignalTests.test_add_signal_handler_install_error3cCsltj|_|j�tjdd��|�|j�tj��|�|jj�|�|jj�|�	tj|j
f|jjd�dS)NcSsdS)NTrrrrrr)�r*zISelectorEventLoopSignalTests.test_remove_signal_handler.<locals>.<lambda>r)rrrr.r7�
assertTruer%r+rIr:�SIG_DFL�	call_args)rr0rrr�test_remove_signal_handler�sz7SelectorEventLoopSignalTests.test_remove_signal_handlercCs�tj|_tj|_|j�tjdd��t�|jjtj<|j�	�|�
|j�tj��|�|jj
�|�
|jj
�|�tj|jf|jjd�dS)NcSsdS)NTrrrrrr)�r*zKSelectorEventLoopSignalTests.test_remove_signal_handler_2.<locals>.<lambda>r)rrr/rr.�objectr$r7r+�
reset_mockrOr%rGrIr:�default_int_handlerrQ)rr0rrr�test_remove_signal_handler_2�s

z9SelectorEventLoopSignalTests.test_remove_signal_handler_2cCsBtj|_|j�tjdd��t|j_|j�tj�|�	|j
�dS)NcSsdS)NTrrrrrr)�r*zWSelectorEventLoopSignalTests.test_remove_signal_handler_cleanup_error.<locals>.<lambda>)rrrr.r7rr+r,r%rOrH)rrKr0rrr�(test_remove_signal_handler_cleanup_error�s
zESelectorEventLoopSignalTests.test_remove_signal_handler_cleanup_errorcCs<tj|_|j�tjdd��t|j_|�t|jjtj�dS)NcSsdS)NTrrrrrr)�r*zOSelectorEventLoopSignalTests.test_remove_signal_handler_error.<locals>.<lambda>)	rrrr.r7rDr,rr%)rr0rrr� test_remove_signal_handler_error�s
z=SelectorEventLoopSignalTests.test_remove_signal_handler_errorcCsLtj|_|j�tjdd��Gdd�dt�}||j_|�t|jj	tj�dS)NcSsdS)NTrrrrrr)�r*zPSelectorEventLoopSignalTests.test_remove_signal_handler_error2.<locals>.<lambda>c@seZdZejZdS)zKSelectorEventLoopSignalTests.test_remove_signal_handler_error2.<locals>.ErrN)r?r@rArBrFrrrrrC�srC)
rrrr.r7rDr,rr-r%)rr0rCrrr�!test_remove_signal_handler_error2�sz>SelectorEventLoopSignalTests.test_remove_signal_handler_error2cCs|tj|_|j�tjdd��|j�tjdd��|�t|jj�d�|j	�
�|j��|�t|jj�d�|j	�d�dS)NcSsdS)NTrrrrrr)�r*z9SelectorEventLoopSignalTests.test_close.<locals>.<lambda>cSsdS)NTrrrrrr)�r*rMrr=)
rrrr.r7�SIGCHLDr:�lenr$r+rTr	�assert_called_once_with)rr0rrr�
test_close�s

z'SelectorEventLoopSignalTests.test_closezasyncio.unix_events.sysc	Cs�tj|_|j�tjdd��|�t|jj�d�d|j_	|j�
�|�td��|j�
�WdQRX|�t|jj�d�|�|jj�dS)NcSsdS)NTrrrrrr)�r*zGSelectorEventLoopSignalTests.test_close_on_finalizing.<locals>.<lambda>rTz skipping signal handlers removalr)rrrr.r7r:r[r$�
is_finalizing�return_valuerT�assertWarnsRegex�ResourceWarningr	rGrI)rr0Zm_sysrrr�test_close_on_finalizing�s
z5SelectorEventLoopSignalTests.test_close_on_finalizing)r?r@rArrr r(r�patchr1r6r<rErLrNrRrVrWrXrYr]rb�
__classcell__rr)rrr+s*	




r�AF_UNIXzUNIX Sockets are not supportedcs�eZdZ�fdd�Zejdd��Zejdd��Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
e�eed�d�ejdd���Zdd�Zdd�Ze�d�dd��Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Z�ZS)(� SelectorEventLoopUnixSocketTestscs$t���t��|_|�|j�dS)N)rrrrrr)r)rrrrs

z&SelectorEventLoopUnixSocketTests.setUpc	Csvt���d}t�tj�}|�|�|�d�|��|j�dd�|�}|j�	|�}|��|j�	|�
��WdQRXdS)NrcSsdS)Nrrrrrr)r*z]SelectorEventLoopUnixSocketTests.test_create_unix_server_existing_path_sock.<locals>.<lambda>)�
test_utils�unix_socket_path�socketre�bindZlistenr	r�create_unix_server�run_until_complete�wait_closed)r�path�sock�coro�srvrrr�*test_create_unix_server_existing_path_socks


zKSelectorEventLoopUnixSocketTests.test_create_unix_server_existing_path_sockc	CsXt���F}t�|�}|j�dd�|�}|j�|�}|��|j�|���WdQRXdS)NcSsdS)Nrrrrrr)r*zRSelectorEventLoopUnixSocketTests.test_create_unix_server_pathlib.<locals>.<lambda>)	rgrh�pathlib�Pathrrkrlr	rm)rrnZsrv_cororqrrr�test_create_unix_server_pathlibs

z@SelectorEventLoopUnixSocketTests.test_create_unix_server_pathlibc
CsVt���D}t�|�}|j�dd�|�}|�t��|j�|�WdQRXWdQRXdS)NcSsdS)Nrrrrrr)r*zVSelectorEventLoopUnixSocketTests.test_create_unix_connection_pathlib.<locals>.<lambda>)	rgrhrsrtr�create_unix_connectionr�FileNotFoundErrorrl)rrnrprrr�#test_create_unix_connection_pathlibs


zDSelectorEventLoopUnixSocketTests.test_create_unix_connection_pathlibc
CsPt���>}|j�dd�|j�}|�td��|j�|�WdQRXWdQRXdS)NcSsdS)Nrrrrrr)'r*z`SelectorEventLoopUnixSocketTests.test_create_unix_server_existing_path_nonsock.<locals>.<lambda>zAddress.*is already in use)�tempfile�NamedTemporaryFilerrk�namer4rDrl)r�filerprrr�-test_create_unix_server_existing_path_nonsock%s

zNSelectorEventLoopUnixSocketTests.test_create_unix_server_existing_path_nonsockc	Cs>|jjdd�ddd�}|�td��|j�|�WdQRXdS)NcSsdS)Nrrrrrr)-r*zSSelectorEventLoopUnixSocketTests.test_create_unix_server_ssl_bool.<locals>.<lambda>�spamT)rn�sslz"ssl argument must be an SSLContext)rrkr4rrl)rrprrr� test_create_unix_server_ssl_bool,s
zASelectorEventLoopUnixSocketTests.test_create_unix_server_ssl_boolc	Cs<|jjdd�dd�}|�td��|j�|�WdQRXdS)NcSsdS)Nrrrrrr)4r*zXSelectorEventLoopUnixSocketTests.test_create_unix_server_nopath_nosock.<locals>.<lambda>)rnz#path was not specified, and no sock)rrkr4rrl)rrprrr�%test_create_unix_server_nopath_nosock3szFSelectorEventLoopUnixSocketTests.test_create_unix_server_nopath_nosockc
CsVt��}|�@|jjdd�d|d�}|�td��|j�|�WdQRXWdQRXdS)NcSsdS)Nrrrrrr)<r*zXSelectorEventLoopUnixSocketTests.test_create_unix_server_path_inetsock.<locals>.<lambda>)rnroz"A UNIX Domain Stream.*was expected)rirrkr4rrl)rrorprrr�%test_create_unix_server_path_inetsock9szFSelectorEventLoopUnixSocketTests.test_create_unix_server_path_inetsockc
Cs^t�tjtj�}|�@|jjdd�d|d�}|�td��|j�|�WdQRXWdQRXdS)NcSsdS)Nrrrrrr)Er*zUSelectorEventLoopUnixSocketTests.test_create_unix_server_path_dgram.<locals>.<lambda>)rnroz"A UNIX Domain Stream.*was expected)rireZ
SOCK_DGRAMrrkr4rrl)rrorprrr�"test_create_unix_server_path_dgramBszCSelectorEventLoopUnixSocketTests.test_create_unix_server_path_dgram�
SOCK_NONBLOCKz$no socket.SOCK_NONBLOCK (linux only)c	Cs�t�tjtjtjB�}t���}|j}WdQRXzX|�J|�|�|jj	dd�d|d�}|j�
|�}|��|j�
|���WdQRXWdt
�|�XdS)NcSsdS)Nrrrrrr)Vr*z^SelectorEventLoopUnixSocketTests.test_create_unix_server_path_stream_bittype.<locals>.<lambda>)rnro)rire�SOCK_STREAMr�ryrzr{rjrrkrlr	rm�os�unlink)rror|�fnrprqrrr�+test_create_unix_server_path_stream_bittypeKs

zLSelectorEventLoopUnixSocketTests.test_create_unix_server_path_stream_bittypec	Cs>|jjdd�ddd�}|�td��|j�|�WdQRXdS)NcSsdS)Nrrrrrr)_r*zfSelectorEventLoopUnixSocketTests.test_create_unix_server_ssl_timeout_with_plain_sock.<locals>.<lambda>r~r)rn�ssl_handshake_timeoutz1ssl_handshake_timeout is only meaningful with ssl)rrkr4rrl)rrprrr�3test_create_unix_server_ssl_timeout_with_plain_sock^szTSelectorEventLoopUnixSocketTests.test_create_unix_server_ssl_timeout_with_plain_sockc
CsTt��}|�>|jjdd�|d�}|�td��|j�|�WdQRXWdQRXdS)NcSsdS)Nrrrrrr)ir*z\SelectorEventLoopUnixSocketTests.test_create_unix_connection_path_inetsock.<locals>.<lambda>)roz"A UNIX Domain Stream.*was expected)rirrvr4rrl)rrorprrr�)test_create_unix_connection_path_inetsockfszJSelectorEventLoopUnixSocketTests.test_create_unix_connection_path_inetsockzasyncio.unix_events.socketc	Cs�t��}||j_t|j_|jjdd�dd�}|�	t��|j�
|�WdQRX|�|jj
�t|j_|jjdd�dd�}|�	t��|j�
|�WdQRX|�|jj
�dS)NcSsdS)Nrrrrrr)vr*zUSelectorEventLoopUnixSocketTests.test_create_unix_server_bind_error.<locals>.<lambda>z/test)rncSsdS)Nrrrrrr)|r*)rr"rir_rDrjr,rrkrrlrOr	rI�MemoryError)rZm_socketrorprrr�"test_create_unix_server_bind_erroroszCSelectorEventLoopUnixSocketTests.test_create_unix_server_bind_errorc	CsB|jjdd�tjt�d�}|�td��|j�|�WdQRXdS)NcSsdS)Nrrrrrr)�r*zXSelectorEventLoopUnixSocketTests.test_create_unix_connection_path_sock.<locals>.<lambda>)rozpath and sock can not be)rrvr��devnullrSr4rrl)rrprrr�%test_create_unix_connection_path_sock�szFSelectorEventLoopUnixSocketTests.test_create_unix_connection_path_sockc	Cs:|j�dd�d�}|�td��|j�|�WdQRXdS)NcSsdS)Nrrrrrr)�r*z\SelectorEventLoopUnixSocketTests.test_create_unix_connection_nopath_nosock.<locals>.<lambda>zno path and sock were specified)rrvr4rrl)rrprrr�)test_create_unix_connection_nopath_nosock�s
zJSelectorEventLoopUnixSocketTests.test_create_unix_connection_nopath_nosockc	Cs@|jjdd�tjdd�}|�td��|j�|�WdQRXdS)NcSsdS)Nrrrrrr)�r*z_SelectorEventLoopUnixSocketTests.test_create_unix_connection_nossl_serverhost.<locals>.<lambda>r~)Zserver_hostnamez"server_hostname is only meaningful)rrvr�r�r4rrl)rrprrr�,test_create_unix_connection_nossl_serverhost�s
zMSelectorEventLoopUnixSocketTests.test_create_unix_connection_nossl_serverhostc	Cs@|jjdd�tjdd�}|�td��|j�|�WdQRXdS)NcSsdS)Nrrrrrr)�r*z_SelectorEventLoopUnixSocketTests.test_create_unix_connection_ssl_noserverhost.<locals>.<lambda>T)rz/you have to pass server_hostname when using ssl)rrvr�r�r4rrl)rrprrr�,test_create_unix_connection_ssl_noserverhost�s

zMSelectorEventLoopUnixSocketTests.test_create_unix_connection_ssl_noserverhostc	Cs>|jjdd�ddd�}|�td��|j�|�WdQRXdS)NcSsdS)Nrrrrrr)�r*zjSelectorEventLoopUnixSocketTests.test_create_unix_connection_ssl_timeout_with_plain_sock.<locals>.<lambda>r~r)rnr�z1ssl_handshake_timeout is only meaningful with ssl)rrvr4rrl)rrprrr�7test_create_unix_connection_ssl_timeout_with_plain_sock�szXSelectorEventLoopUnixSocketTests.test_create_unix_connection_ssl_timeout_with_plain_sock)r?r@rArrZskip_unless_bind_unix_socketrrrurxr}r�r�r�r��unittest�
skipUnless�hasattrrir�r�r�rrcr�r�r�r�r�r�rdrr)rrrf�s(
						rf�sendfilezsendfile is not supportedcs�eZdZddZGdd�dej�Ze�fdd��Ze�fdd��Z	�fd	d
�Z
d&dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Z�ZS)'�&SelectorEventLoopUnixSockSendfileTestss�12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcdeic@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)z.SelectorEventLoopUnixSockSendfileTests.MyProtocCs2d|_d|_t�|_|��|_d|_|��|_dS)NF)�started�closed�	bytearray�data�
create_future�futr
�_ready)rrrrr�__init__�s
z7SelectorEventLoopUnixSockSendfileTests.MyProto.__init__cCsd|_||_|j�d�dS)NT)r�r
r��
set_result)rr
rrr�connection_made�sz>SelectorEventLoopUnixSockSendfileTests.MyProto.connection_madecCs|j�|�dS)N)r��extend)rr�rrr�
data_received�sz<SelectorEventLoopUnixSockSendfileTests.MyProto.data_receivedcCsd|_|j�d�dS)NT)r�r�r�)r�excrrr�connection_lost�sz>SelectorEventLoopUnixSockSendfileTests.MyProto.connection_lostc�s|jIdHdS)N)r�)rrrrrm�sz:SelectorEventLoopUnixSockSendfileTests.MyProto.wait_closedN)r?r@rAr�r�r�r�rmrrrr�MyProto�s
r�c	s2ttjd��}|�|j�WdQRXt���dS)N�wb)�openr�TESTFN�write�DATAr�
setUpClass)�cls�fp)rrrr��sz1SelectorEventLoopUnixSockSendfileTests.setUpClasscst�tj�t���dS)N)rr�r�r�
tearDownClass)r�)rrrr��sz4SelectorEventLoopUnixSockSendfileTests.tearDownClasscs@t��|_|�|j�ttjd�|_|�|jj	�t
���dS)N�rb)r�new_event_looprrr�rr�r|r3r	rr)r)rrrr�s

z,SelectorEventLoopUnixSockSendfileTests.setUpTcCsRt�tjtj�}|�d�|�tjtjd�|�tjtjd�|rN|�|j	�|S)NFi)
riZAF_INETr�ZsetblockingZ
setsockoptZ
SOL_SOCKETZ	SO_SNDBUFZ	SO_RCVBUFr3r	)r�cleanuprorrr�make_socket�s
z2SelectorEventLoopUnixSockSendfileTests.make_socketcCs|j�|�S)N)rrl)rrprrr�run_loop�sz/SelectorEventLoopUnixSockSendfileTests.run_loopcs����}���j��t��}�jdd�}|�tj|f����jj�fdd�|d������j�	|tj|f�����j
����fdd�}��|�|�fS)NF)r�cs�S)Nrr)�protorrr)�r*z@SelectorEventLoopUnixSockSendfileTests.prepare.<locals>.<lambda>)rocs2�j�����������������dS)N)r
r	r�rmr)r�r�serverrrr��s
z?SelectorEventLoopUnixSockSendfileTests.prepare.<locals>.cleanup)r�r�rrZfind_unused_portrjZHOSTr�Z
create_serverZsock_connectr�r3)rroZportZsrv_sockr�r)r�rr�r�prepare�s

z.SelectorEventLoopUnixSockSendfileTests.preparec
Csp|��\}}tjdgd��:|�tjd�� |�|j�||j	dd��WdQRXWdQRX|�
|j	��d�dS)Nzasyncio.unix_events.os)�specz$os[.]sendfile[(][)] is not availabler)r�rrcr4r�SendfileNotAvailableErrorr�r�_sock_sendfile_nativer|r:�tell)rror�rrr� test_sock_sendfile_not_available�szGSelectorEventLoopUnixSockSendfileTests.test_sock_sendfile_not_availablec	CsZ|��\}}t�}|�tjd��|�|j�||dd��WdQRX|�|j	�
�d�dS)Nznot a regular filer)r�rSr4rr�r�rr�r:r|r�)rror��frrr�test_sock_sendfile_not_a_fileszDSelectorEventLoopUnixSockSendfileTests.test_sock_sendfile_not_a_filec	Cs\|��\}}t��}|�tjd��|�|j�||dd��WdQRX|�	|j
��d�dS)Nznot a regular filer)r��io�BytesIOr4rr�r�rr�r:r|r�)rror�r�rrr�test_sock_sendfile_iobufferszBSelectorEventLoopUnixSockSendfileTests.test_sock_sendfile_iobufferc	Csd|��\}}t��}d|j_|�tjd��|�|j	�
||dd��WdQRX|�|j�
�d�dS)Nr=znot a regular filer)r�rr"�filenor_r4rr�r�rr�r:r|r�)rror�r�rrr�#test_sock_sendfile_not_regular_fileszJSelectorEventLoopUnixSockSendfileTests.test_sock_sendfile_not_regular_filec
Cs�|��\}}|j��}|j��}|j�|d||ddt|j�d�|��t	�
tj��|�
|�WdQRX|�t��|jj�|�WdQRXdS)Nr)r�rr�r|r��_sock_sendfile_native_implr[r�r#�
contextlib�suppressrZCancelledErrorr�r�KeyError�	_selector�get_key)rror�r�r�rrr�test_sock_sendfile_cancel1s

zASelectorEventLoopUnixSockSendfileTests.test_sock_sendfile_cancel1c
Cs�|��\}}|j��}|j��}|j�|d||ddt|j�d�|��|j�||��||ddt|j�d�|�	t
��|jj�|�WdQRXdS)Nr)
r�rr�r|r�r�r[r�r#rr�r�r�)rror�r�r�rrr�test_sock_sendfile_cancel2+s

zASelectorEventLoopUnixSockSendfileTests.test_sock_sendfile_cancel2cCs�|��\}}|j��}t��}d|j_tjdt�d��&|j	�
|d||ddt|j�d�WdQRX|j	j
�|�}|�|�|j�tj�dS)NFzos.sendfile)r,r)r�r|r�rr"Z	cancelledr_rc�BlockingIOErrorrr�r[r�r�r��assertIsNotNoneZadd_done_callbackr\�ANY)rror�r�r��keyrrr�!test_sock_sendfile_blocking_error8s

zHSelectorEventLoopUnixSockSendfileTests.test_sock_sendfile_blocking_errorcCs�|��\}}|j��}|j��}tjdt�d��&|j�|d||ddt	|j
�d�WdQRX|�t��|jj
�|�WdQRX|��}|�|tj�|�d|j���dS)Nzos.sendfile)r,r)r�r|r�rr�rrcrDr�r[r�rr�r�r��	exceptionr9rr�r:r�)rror�r�r�r�rrr�&test_sock_sendfile_os_error_first_callEs

zMSelectorEventLoopUnixSockSendfileTests.test_sock_sendfile_os_error_first_callcCs�|��\}}|j��}|j��}t�}tjd|d��*|j�||��||ddt	|j
�d�WdQRX|�t��|jj
�|�WdQRX|��}|�||�|�d|j���dS)Nzos.sendfile)r,i�)r�r|r�rr�rDrrcr�r[r�rr�r�r�r��assertIsr:r�)rror�r�r��errr�rrr�%test_sock_sendfile_os_error_next_callSs

zLSelectorEventLoopUnixSockSendfileTests.test_sock_sendfile_os_error_next_callcCs�|��\}}|j��}|j��}t��}tjd|d��*|j�	||��||ddt
|j�d�WdQRX|�t
��|jj�|�WdQRX|��}|�||�|�d|j���dS)Nzos.sendfile)r,i�)r�r|r�rr�rr�rrcr�r[r�rr�r�r�r�r�r:r�)rror�r�r�r�r�rrr�test_sock_sendfile_exceptionds

zCSelectorEventLoopUnixSockSendfileTests.test_sock_sendfile_exception)T)r?r@rAr�r�Protocolr��classmethodr�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�rdrr)rrr��s$
				



r�cs
eZdZ�fdd�Zd(dd�Zdd�Ze�d�d	d
��Ze�d�dd��Z	e�d�d
d��Z
e�d�e�d�dd���Ze�d�dd��Ze�d�dd��Z
e�d�dd��Ze�d�dd��Ze�d�dd��Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Z�ZS))�UnixReadPipeTransportTestscs�t���|��|_t�tj�|_t	j
tjd�|_
d|j
j_t	�d�}|��|�|j�t	�d�}|��}t	�
�}tj|_||_|�|j�dS)N)�spec_set�zos.set_blockingzos.fstat)rr�
new_test_looprrg�make_test_protocolrr��protocolrr"r��	RawIOBase�piper�r_rc�startr3�stop�stat�S_IFIFO�st_mode)r�blocking_patcher�
fstat_patcher�m_fstat�st)rrrrxs




z UnixReadPipeTransportTests.setUpNcCs(tj|j|j|j|d�}|�t|�|S)N)�waiter)rZ_UnixReadPipeTransportrr�r�r3r
)rr�r
rrr�read_pipe_transport�s
z.UnixReadPipeTransportTests.read_pipe_transportcCsVtj|jd�}|j|d�}|j�|�|jj�|�|j�d|j	�|�
|���dS)N)r)r�r�)r�Futurerr�rlr�r�r&�
assert_reader�_read_ready�assertIsNone�result)rr��trrrr�	test_ctor�sz$UnixReadPipeTransportTests.test_ctorzos.readcCs6|��}d|_|��|�d|j�|jj�d�dS)Nsdatar�)r�r_r�r&�max_sizer�r�)r�m_readr�rrr�test__read_ready�s
z+UnixReadPipeTransportTests.test__read_readycCs\|��}d|_|��|�d|j�|�|jj�t�	|j�|j
j��|j
j�d�dS)Nr*r�)
r�r_r�r&r�rGr�readersrg�run_brieflyr�Zeof_receivedr�)rr�r�rrr�test__read_ready_eof�sz/UnixReadPipeTransportTests.test__read_ready_eofcCsD|��}t|_|��|�d|j�t�|j�|�	|j
jj�dS)Nr�)
r�r�r,r�r&r�rgr�rrGr�r�rI)rr�r�rrr�test__read_ready_blocked�sz3UnixReadPipeTransportTests.test__read_ready_blockedzasyncio.log.logger.errorcCs^|��}t�}||_t��|_|��|�d|j�|j�|�|jt	�
d�tttfd�dS)Nr�z;Fatal read error on pipe transport
protocol:.*
transport:.*)�exc_info)r�rDr,rr"�_closer�r&r�rgZMockPattern�MOCK_ANY)rr��m_logexcr�r�rrr�test__read_ready_error�s
z1UnixReadPipeTransportTests.test__read_ready_errorcCs8|��}t��}|j�d|�|��|�|jj�dS)Nr�)r�rr"r�
add_reader�
pause_readingrGr�)rr�r��mrrr�test_pause_reading�s
z-UnixReadPipeTransportTests.test_pause_readingcCs,|��}|��|��|j�d|j�dS)Nr�)r�r�resume_readingrr�r�)rr�r�rrr�test_resume_reading�sz.UnixReadPipeTransportTests.test_resume_readingcCs*|��}t��|_|��|j�d�dS)N)r�rr"r�r	r&)rr�r�rrrr]�s
z%UnixReadPipeTransportTests.test_closecCs2|��}d|_t��|_|��|�|jj�dS)NT)r��_closingrr"r�r	rGrI)rr�r�rrr�test_close_already_closing�s

z5UnixReadPipeTransportTests.test_close_already_closingcCsR|��}t�}|�|�|�|���|�|jj�t�	|j�|j
j�|�dS)N)
r�rSr�rO�
is_closingrGrr�rgr�r�r�r&)rr�r�r�rrr�test__close�s
z&UnixReadPipeTransportTests.test__closecCsd|��}|�|j�|�|j�d}|�|�|jj�|�|jj	��|�
|j�|�
|j�dS)N)r�r��	_protocol�_loop�_call_connection_lostr�r�r&r�r	r�)rr�r�rrr�test__call_connection_lost�s
z5UnixReadPipeTransportTests.test__call_connection_lostcCsf|��}|�|j�|�|j�t�}|�|�|jj�|�|j	j
��|�|j�|�|j�dS)N)r�r�rrrDr
r�r�r&r�r	r�)rr�r�rrr�#test__call_connection_lost_with_err�s
z>UnixReadPipeTransportTests.test__call_connection_lost_with_errcCs4|��}|��t�|j�|�|j�|��dS)N)r�r	rgr�rr�rr)rr�rrr�!test_pause_reading_on_closed_pipes
z<UnixReadPipeTransportTests.test_pause_reading_on_closed_pipecCs|��}|��|��dS)N)r�r)rr�rrr�!test_pause_reading_on_paused_pipesz<UnixReadPipeTransportTests.test_pause_reading_on_paused_pipecCs4|��}|��t�|j�|�|j�|��dS)N)r�r	rgr�rr�rr)rr�rrr�"test_resume_reading_on_closed_pipes
z=UnixReadPipeTransportTests.test_resume_reading_on_closed_pipecCs|��}|��dS)N)r�r)rr�rrr�"test_resume_reading_on_paused_pipe sz=UnixReadPipeTransportTests.test_resume_reading_on_paused_pipe)N)r?r@rArr�r�rrcr�r�r�rrrr]rr
rrrrrrrdrr)rrr�vs&
		



r�cs~eZdZ�fdd�Zd7dd�Zdd�Zdd	�Ze�d
�dd��Z	e�d
�d
d��Z
e�d
�dd��Ze�d
�dd��Ze�d
�dd��Z
e�d�e�d
�dd���Ze�d
�dd��Zdd�Ze�d
�dd��Ze�d
�dd��Ze�d
�d d!��Ze�d
�d"d#��Ze�d$�e�d
�d%d&���Ze�d
�d'd(��Ze�d
�d)d*��Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Z�ZS)8�UnixWritePipeTransportTestscs�t���|��|_t�tj�|_t	j
tjd�|_
d|j
j_t	�d�}|��|�|j�t	�d�}|��}t	�
�}tj|_||_|�|j�dS)N)r�r�zos.set_blockingzos.fstat)rrr�rrgr�rZBaseProtocolr�rr"r�r�r�r�r_rcr�r3r�r��S_IFSOCKr�)rr�r�r�r�)rrrr)s




z!UnixWritePipeTransportTests.setUpNcCs(tj|j|j|j|d�}|�t|�|S)N)r�)rZ_UnixWritePipeTransportrr�r�r3r
)rr�r
rrr�write_pipe_transport;s
z0UnixWritePipeTransportTests.write_pipe_transportcCsXtj|jd�}|j|d�}|j�|�|jj�|�|j�d|j	�|�
d|���dS)N)r)r�r�)rr�rrrlr�r�r&r�r�r:r�)rr�r�rrrr�Bsz%UnixWritePipeTransportTests.test_ctorcCs|��}|�|���dS)N)rrOZ
can_write_eof)rr�rrr�test_can_write_eofKsz.UnixWritePipeTransportTests.test_can_write_eofzos.writecCsF|��}d|_|�d�|�dd�|�|jj�|�t�|j	�dS)N�sdatar�)
rr_r�r&rGr�writersr:r��_buffer)r�m_writer�rrr�
test_writeOs
z&UnixWritePipeTransportTests.test_writecCsB|��}|�d�|�|j�|�|jj�|�td�|j�dS)Nr*)	rr�rGrIrrr:r�r)rrr�rrr�test_write_no_dataXs

z.UnixWritePipeTransportTests.test_write_no_datacCs>|��}d|_|�d�|j�d|j�|�td�|j�dS)NrMsdatar�sta)	rr_r�r�
assert_writer�_write_readyr:r�r)rrr�rrr�test_write_partial`s

z.UnixWritePipeTransportTests.test_write_partialcCs^|��}|j�d|j�td�|_|�d�|�|j�|j�	d|j�|�
td�|j�dS)Nr�sprevioussdataspreviousdata)rr�
add_writerrr�rr�rGrIrr:)rrr�rrr�test_write_bufferhs

z-UnixWritePipeTransportTests.test_write_buffercCsP|��}t�|_|�d�|�dtd��|j�d|j�|�	td�|j
�dS)Nsdatar�)rr�r,r�r&r�rrrr:r)rrr�rrr�test_write_againrs
z,UnixWritePipeTransportTests.test_write_againzasyncio.unix_events.loggercCs�|��}t�}||_t��|_|�d�|�dd�|�|j	j
�|�t�|j
�|j�|d�|�d|j�|�d�|�d|j�|�d�|�d�|�d�|�d�|j�d�|��dS)Nsdatar�z#Fatal write error on pipe transportrrMz=pipe closed by peer or os.write(pipe, data) raised exception.)rrDr,rr"Z_fatal_errorr�r&rGrrr:r�r�
_conn_lost�warningr	)rrZm_logr�r�rrr�test_write_err{s*






z*UnixWritePipeTransportTests.test_write_errcCsD|��}|��|�d�|�|jd�|�d�|�|jd�dS)NsdatarrM)rr�r�r:r$)rrr�rrr�test_write_close�s

z,UnixWritePipeTransportTests.test_write_closecCsX|��}|��|�|jj�|�|jj�|�|���t�	|j�|j
j�d�dS)N)
rr�rGrr�rrOr	rgr�r�r�r&)rr�rrrr��sz,UnixWritePipeTransportTests.test__read_readycCsR|��}|j�d|j�td�|_d|_|��|�|jj�|�	t�|j�dS)Nr�sdatar)
rrr!rr�rr_rGrr:)rrr�rrr�test__write_ready�s
z-UnixWritePipeTransportTests.test__write_readycCsV|��}|j�d|j�td�|_d|_|��|j�d|j�|�td�|j�dS)Nr�sdata��a)	rrr!rr�rr_rr:)rrr�rrr�test__write_ready_partial�s
z5UnixWritePipeTransportTests.test__write_ready_partialcCsh|��}|j�d|j�td�|_t�|_|��|�dtd��|j�	d|j�|�
td�|j�dS)Nr�sdata)rrr!rr�rr�r,r&rr:)rrr�rrr�test__write_ready_again�s
z3UnixWritePipeTransportTests.test__write_ready_againcCsf|��}|j�d|j�td�|_d|_|��|�dtd��|j�d|j�|�	td�|j�dS)Nr�sdatar)
rrr!rr�rr_r&rr:)rrr�rrr�test__write_ready_empty�s
z3UnixWritePipeTransportTests.test__write_ready_emptyzasyncio.log.logger.errorcCs�|��}|j�d|j�td�|_t�|_}|��|�|jj	�|�|jj
�|�t�|j�|�|�
��|��|�d|j�t�|j�|jj�|�dS)Nr�sdatar)rrr!rr�rrDr,rGrr�r:rOr	Zassert_not_calledr$rgr�r�r�r&)rrr�r�r�rrr�test__write_ready_err�s
z1UnixWritePipeTransportTests.test__write_ready_errcCs�|��}|j�d|j�d|_td�|_d|_|��|�|jj	�|�|jj
�|�t�|j�|jj
�d�|jj��dS)Nr�Tsdatar)rrr!rrr�rr_rGrr�r:r�r�r&r�r	)rrr�rrr�test__write_ready_closing�s
z5UnixWritePipeTransportTests.test__write_ready_closingcCs�|��}|j�d|j�|j�d|j�ddg|_|��|�|j	�|�|jj
�|�|jj�|�g|j�|�
|���t�|j�|jj�d�dS)Nr�sdasta)rrr!rrr�r�abortrGrIr�rr:rOr	rgr�r�r�r&)rrr�rrr�
test_abort�s
z&UnixWritePipeTransportTests.test_abortcCsd|��}|�|j�|�|j�d}|�|�|jj�|�|jj	��|�
|j�|�
|j�dS)N)rr�rrr
r�r�r&r�r	r�)rr�r�rrrrs
z6UnixWritePipeTransportTests.test__call_connection_lostcCsf|��}|�|j�|�|j�t�}|�|�|jj�|�|j	j
��|�|j�|�|j�dS)N)rr�rrrDr
r�r�r&r�r	r�)rr�r�rrrrs
z?UnixWritePipeTransportTests.test__call_connection_lost_with_errcCs0|��}t��|_|��|j��|��dS)N)rrr"�	write_eofr	r&)rr�rrrr]s


z&UnixWritePipeTransportTests.test_closecCs2|��}t��|_d|_|��|�|jj�dS)NT)rrr"r2rr	rGrI)rr�rrr�test_close_closing$s

z.UnixWritePipeTransportTests.test_close_closingcCsJ|��}|��|�|���|�|jj�t�|j�|j	j
�d�dS)N)rr2rOr	rGrr�rgr�r�r�r&)rr�rrr�test_write_eof+sz*UnixWritePipeTransportTests.test_write_eofcCs:|��}dg|_|��|�|���|�|jjj�dS)Nsdata)	rrr2rOr	rGr�r�rI)rr�rrr�test_write_eof_pending3s
z2UnixWritePipeTransportTests.test_write_eof_pending)N)r?r@rArrr�rrrcrrr r"r#r&r'r�r(r+r,r-r.r/r1rrr]r3r4r5rdrr)rrr's6
		
	
	



	rc@seZdZdd�ZdS)�AbstractChildWatcherTestscCsvt��}t��}|�t|j||�|�t|j|�|�t|j|�|�t|j	�|�t|j
�|�t|j|||�dS)N)rr"rZAbstractChildWatcherr�NotImplementedError�add_child_handler�remove_child_handler�attach_loopr	�	__enter__�__exit__)rr��watcherrrr�test_not_implemented=s

z.AbstractChildWatcherTests.test_not_implementedN)r?r@rAr>rrrrr6;sr6c@seZdZdd�ZdS)�BaseChildWatcherTestscCs$t��}t��}|�t|j|�dS)N)rr"rZBaseChildWatcherrr7Z_do_waitpid)rr�r=rrrr>Psz*BaseChildWatcherTests.test_not_implementedN)r?r@rAr>rrrrr?Nsr?�WaitPidMocks)�waitpid�	WIFEXITED�WIFSIGNALED�WEXITSTATUS�WTERMSIGcs eZdZej�ejd�Z�fdd�Z	dd�Z
dd�Zdd	�Zd
d�Z
dd
�Zdd�Zdd�Zdd�Zedd��Zedd��Zedd��Zedd��Zedd��Zedd��Zed d!��Zed"d#��Zed$d%��Zed&d'��Zed(d)��Zed*d+��Zed,d-��Zed.d/��Zed0d1��Z �Z!S)2�ChildWatcherTestsMixinr%c	sZt���|��|_d|_i|_tj�|jd�� |_	|�
�|_|j�|j�WdQRXdS)NFr.)
rrr�r�running�zombiesrrcrS�m_add_signal_handler�create_watcherr=r:)r)rrrrds


zChildWatcherTestsMixin.setUpcCsrt|jtj�s|dkr"|�|d�y&|dkr6|j��S||j�|�fSWntk
r\YnX|j	rhdSt
��dS)Nr=r)rr)�
isinstancer=r�SafeChildWatcherZ
assertGreaterrH�popitem�popr�rG�ChildProcessError)r�pid�flagsrrrrAos
zChildWatcherTestsMixin.waitpidcCs|d|j|<dS)Ni�)rH)rrP�
returncoderrr�
add_zombie~sz!ChildWatcherTestsMixin.add_zombiecCs|dkS)Ni�r)r�statusrrrrB�sz ChildWatcherTestsMixin.WIFEXITEDcCsd|kodkSS)Ni�i�r)rrTrrrrC�sz"ChildWatcherTestsMixin.WIFSIGNALEDcCs|�|�|��|dS)Ni�)rOrB)rrTrrrrD�sz"ChildWatcherTestsMixin.WEXITSTATUScCs|�|�|��d|S)Ni�)rOrC)rrTrrrrE�szChildWatcherTestsMixin.WTERMSIGcCs|j�tj|jj�dS)N)rIr\rrZr=�	_sig_chld)rrrr�test_create_watcher�sz*ChildWatcherTestsMixin.test_create_watchercs�fdd�}|S)Nc
s�dd�}|d|j��|}|d|j��d}|d|j��L}|d|j��4}|d|j��}�|t|||||��WdQRXWdQRXWdQRXWdQRXWdQRXdS)NcSstj||tjd�S)N)�wrapsZnew_callable)rrcr")�target�wrapperrrrrc�szIChildWatcherTestsMixin.waitpid_mocks.<locals>.wrapped_func.<locals>.patchzos.WTERMSIGzos.WEXITSTATUSzos.WIFSIGNALEDzos.WIFEXITEDz
os.waitpid)rErDrCrBrAr@)rrcZ
m_WTERMSIGZ
m_WEXITSTATUSZ
m_WIFSIGNALEDZm_WIFEXITEDZ	m_waitpid)r5rr�wrapped_func�sz:ChildWatcherTestsMixin.waitpid_mocks.<locals>.wrapped_funcr)r5rZr)r5r�
waitpid_mocks�sz$ChildWatcherTestsMixin.waitpid_mocksc	Cst��}|j� d|_|j�d|ddd�WdQRX|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�|j��|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�d|_|�dd�|j��|�
|jj�|�
|j	j�|�|j
j�|�ddddd�|j��|j��|j	��|��|�dd�|j�|j��WdQRX|�|j�|�|j
j�|j��|j��|j	��|j��|j��|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�dS)	NT�*�	�
�F��
)rr"r=rGr8rGrIrBrCrDrErUrSrOr\rT�ignore_warningsrH�clear)rr�callbackrrr�test_sigchld�sR









z#ChildWatcherTestsMixin.test_sigchldc	Cs�t��}t��}|j�d|_|j�d|dd�WdQRX|�|j�|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�|j�|j�d|dd�WdQRX|�|j�|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�|j��|�|j�|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�|�dd�|j��|�
dddd�|�|j�|�|jj�|�|j	j�|�|j
j�|j��|j��|j
��|��|j��|�|j�|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�|�dd	�d
|_|j��|�
dd	dd�|�|j�|�|jj�|�|j	j�|�|j
j�|j��|j��|j	��|��|�dd�|�dd�|j�|j��WdQRX|�|j�|�|j�|�|j
j�|j��|j��|j	��|j��|j��|�|j�|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�dS)
NT�+���,������lFr_�)rr"r=rGr8rGrIrBrCrDrErUrSr\rOrTrbrHrc)rr�	callback1�	callback2rrr�test_sigchld_two_children�s�














z0ChildWatcherTestsMixin.test_sigchld_two_childrenc	Csnt��}t��}|j�d|_|j�d|dd�WdQRX|�|j�|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�|j�|j�d|dd�WdQRX|�|j�|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�|j��|�|j�|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�|�dd�|�dd	�d
|_|j��|�
dddd�|�
dd	dd�|�|jj�|�|jj�|�|j	j�|�|j
j�|j��|j��|j
��|j	��|��|��|�dd�|�dd�|j�|j��WdQRX|�|j�|�|j�|�|j
j�dS)
NT�-�rh�.i{rk�N���Fr_rn)rr"r=rGr8rGrIrBrCrDrErUrSr\rOrTrb)rrrorprrr�.test_sigchld_two_children_terminating_togetherIsb





zEChildWatcherTestsMixin.test_sigchld_two_children_terminating_togetherc	Cs�t��}|j�.|�dd�|j��|j�d|dd�WdQRX|�dddd�|��|�dd�|j�|j��WdQRX|�	|j
�dS)N�2rrr`r=)rr"r=rSrUr8r\rTrbrGrI)rrrdrrr�test_sigchld_race_condition�s
z2ChildWatcherTestsMixin.test_sigchld_race_conditionc	Cs�t��}t��}|j�d|_|j�d|d�WdQRX|�|j�|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�|j�|j�d|d�WdQRX|�|j�|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�d|_|�dd�|j��|�
ddd�|�|j�|�|jj�|�|j	j�|�|j
j�|j��|j��|j
��|��|�dd�|j�|j��WdQRX|�|j�|�|j�|�|j
j�dS)NT�3��Fi����ra)rr"r=rGr8rGrIrBrCrDrErSrUr\rOrTrb)rrrorprrr�test_sigchld_replace_handler�sJ



z3ChildWatcherTestsMixin.test_sigchld_replace_handlerc	Cst��}|j�d|_|j�d|d�WdQRX|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�|j�d�|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�d|_|�dd�|j
�|j��WdQRX|�|j�dS)NT�4i�F�c)rr"r=rGr8rGrIrBrCrDrEr9rSrbrU)rrrdrrr�test_sigchld_remove_handler�s(z2ChildWatcherTestsMixin.test_sigchld_remove_handlerc	Cs(t��}|j�d|_|j�d|d�WdQRX|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�d|jd<d|_|j��|�
ddd�|�|jj�|�|jj�|�|j	j�|�|j
j�|��|j��|j��|�dd�|j�|j��WdQRX|�|j�dS)NT�5i��i�F�e)rr"r=rGr8rGrIrBrCrDrErHrUr\rOrTrSrb)rrrdrrr�test_sigchld_unknown_status�s0



z2ChildWatcherTestsMixin.test_sigchld_unknown_statusc	Cst��}t��}t��}|j�<d|_|j�d|d�|j�d|d�|j�d|d�WdQRX|�|j�d��|�|j�d��|�|j�d��|�|j�d��|�dd�|�dd�|�dd�d	|_|j	�|j�
�WdQRX|�|j�|�|j�|�ddd�dS)
NT�6r�7rM�8r)rF)
rr"r=rGr8rOr9rGrSrbrUrIr\)rrrorp�	callback3rrr�test_remove_child_handlers*z0ChildWatcherTestsMixin.test_remove_child_handlerc	Cstt��}|j�d|_|j�d|�WdQRXt|j_tj�	t
jd��$}|�|j�
�d�|�|j�WdQRXdS)NT�9�error)rr"r=rGr8rrAr,rcrSr�loggerr:rUrOrI)rrrdZm_errorrrr� test_sigchld_unhandled_exception?s
z7ChildWatcherTestsMixin.test_sigchld_unhandled_exceptionc	Cs�t��}|j�d|_|j�d|�WdQRX|�|j�|�|jj�|�|jj�|�|j	j�|�|j
j�d|_|�dd�t�
dtj�|j
��|j�|j��WdQRXt|jtj�r�|�|j�n|�dd�dS)NT�:Fr�)rr"r=rGr8rGrIrBrCrDrErSr�rA�WNOHANGrTrbrUrKr�FastChildWatcherr\)rrrdrrr�#test_sigchld_child_reaped_elsewhereQs$
z:ChildWatcherTestsMixin.test_sigchld_child_reaped_elsewherec
Cs�t��}t��}|j�\|j�Jd|_|�dd�|�dd�|j��|j�d|�|j�d|�WdQRXWdQRX|�dd�|�	|j
�dS)NTiOrgiQrsiP)rr"rbr=rGrSrUr8r\rGrI)rrrorprrr�,test_sigchld_unknown_pid_during_registrationts
"zCChildWatcherTestsMixin.test_sigchld_unknown_pid_during_registrationc
Cs�t��}|j�d|_|j�d|�WdQRX|j}|��|_tjj}||d��J}||jd��2}|j�	|j�|�
tj�|�
tj|jj
�WdQRXWdQRXd|_|�dd�|j�
�|�
dd�dS)NT�<r%r.Fr])rr"r=rGr8rr�rcrSr:r\rrZrUrS)rrrd�old_looprcZm_old_removeZ	m_new_addrrr�
test_set_loop�s$
"
z$ChildWatcherTestsMixin.test_set_loopc
Cs�t��}t��}t��}|j�6d|_|j�d|�|j�d|�|j�d|�WdQRX|j}d|_tj�|d��6}|�t	d��|j�
d�WdQRX|�tj
�WdQRX|�dd�|�dd�|�|j�|�|j�|�|j�|��|_tj�|jd	��J}|j�
|j�|�tj
|jj�|�dd�|�dd�|�|j�WdQRX|��|��d
|_|�dd�|j��|�|j�|�|j�|�dd�dS)NT�=�>inr%zA loop is being detached�rvr.Fr{)rr"r=rGr8rrcrSr`�RuntimeWarningr:r\rrZrSrGrIr�rUrT)rrrorpr�r��m_remove_signal_handlerrIrrr�test_set_loop_race_condition�sN



z3ChildWatcherTestsMixin.test_set_loop_race_conditionc
Cs�t��}|j��d|_|�dd�|�dd�|j��|j�d|�|j�d|�|�t|jj	�d�t
|jtj�r�|�t|jj
�d�tj�|jd��F}|j��|�tj�|�|jj	�t
|jtj�r�|�|jj
�WdQRXWdQRXdS)	NT�?r]�Ark�@rr%)rr"r=rGrSrUr8r:r[Z
_callbacksrKrr�Z_zombiesrcrSrr	r\rrZrG)rrror�rrrr]�s(

z!ChildWatcherTestsMixin.test_closec
CsDt��}|���*}|�td��|�d|�WdQRXWdQRXdS)Nz/the child watcher does not have a loop attached�d)rr"rJr4r-r8)rrrdr=rrr�,test_add_child_handler_with_no_loop_attacheds
zCChildWatcherTestsMixin.test_add_child_handler_with_no_loop_attached)"r?r@rArrcrSrr�rbrrArSrBrCrDrErVr[rerqrwryr}r�r�r�r�r�r�r�r�r]r�rdrr)rrrF`s2=hE5 %!#> rFc@seZdZdd�ZdS)�SafeChildWatcherTestscCst��S)N)rrL)rrrrrJsz$SafeChildWatcherTests.create_watcherN)r?r@rArJrrrrr�sr�c@seZdZdd�ZdS)�FastChildWatcherTestscCst��S)N)rr�)rrrrrJsz$FastChildWatcherTests.create_watcherN)r?r@rArJrrrrr�sr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�PolicyTestscCst��S)N)rZDefaultEventLoopPolicy)rrrr�
create_policyszPolicyTests.create_policycCsX|��}|�|j�|��}|�|tj�|�|j|�|�||���|�|j�dS)N)	r�r��_watcher�get_child_watcherr9rrLr�r)r�policyr=rrr�test_get_child_watchersz"PolicyTests.test_get_child_watchercCs<|��}t��}|�|�|�|j|�|�||���dS)N)r�rr�Zset_child_watcherr�r�r�)rr�r=rrr� test_get_child_watcher_after_set+s

z,PolicyTests.test_get_child_watcher_after_setcCsL|��}|��}|�|j�|��}|�|tj�|�|j	|�|�
�dS)N)r��get_event_loopr�r�r�r9rrLr�rr	)rr�rr=rrr�-test_get_child_watcher_with_mainloop_existing3sz9PolicyTests.test_get_child_watcher_with_mainloop_existingcs6��fdd�}����tj|d�}|��|��dS)NcsR�����������tj����}��|tj���|j	�����
�dS)N)rr�r9r�rZAbstractEventLoopr�rLr�rr	)r=)r�rrrr�As
z4PolicyTests.test_get_child_watcher_thread.<locals>.f)rX)r��	threadingZThreadr��join)rr�Zthr)r�rr�test_get_child_watcher_thread?s
z)PolicyTests.test_get_child_watcher_threadcCsr|��}|��}|��}|�|j|�|��}|�|�|�|j|�|�d�|�|jd�|��|��dS)N)r�r�r�r�rr�rr	)rr�rr=Znew_looprrr�,test_child_watcher_replace_mainloop_existingSs

z8PolicyTests.test_child_watcher_replace_mainloop_existingN)	r?r@rAr�r�r�r�r�r�rrrrr�sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestFunctionalcCst��|_t�|j�dS)N)rr�rr)rrrrrjs
zTestFunctional.setUpcCs|j��t�d�dS)N)rr	rr)rrrr�tearDownns
zTestFunctional.tearDownc	s��fdd�}dd�}|���j�t�|�WdQRX|���j�t�|�WdQRX|���j�t��WdQRX|���j�t��WdQRXdS)Ncs��td�S)NzInvalid file object)r4rr)rrr�
assert_raisessszFTestFunctional.test_add_reader_invalid_argument.<locals>.assert_raisescSsdS)Nrrrrrr)vr*zATestFunctional.test_add_reader_invalid_argument.<locals>.<lambda>)rrrSr!�
remove_reader�
remove_writer)rr�r;r)rr� test_add_reader_invalid_argumentrsz/TestFunctional.test_add_reader_invalid_argumentcsR�fdd�����fdd�}t��\�}z�j�|��Wd���|��XdS)Ncs��td�S)Nz'File descriptor .* is used by transport)r4r-r)rrrr��szLTestFunctional.test_add_reader_or_writer_transport_fd.<locals>.assert_raisesc	�sD�jjdd��d�IdH\}}�zdd�}����j��|�WdQRX����j����|�WdQRX����j���WdQRX����j�����WdQRX����j��|�WdQRX����j����|�WdQRX����j���WdQRX����j�����WdQRXWd|��XdS)NcSst��S)N)rr�rrrrr)�r*zWTestFunctional.test_add_reader_or_writer_transport_fd.<locals>.runner.<locals>.<lambda>)rocSsdS)Nrrrrrr)�r*)rZcreate_connectionrr�r�r!r�r	)r�Zprr;)r��rsockrrr�runner�s*zETestFunctional.test_add_reader_or_writer_transport_fd.<locals>.runner)riZ
socketpairrrlr	)rr�Zwsockr)r�r�rr�&test_add_reader_or_writer_transport_fd�sz5TestFunctional.test_add_reader_or_writer_transport_fdN)r?r@rArr�r�r�rrrrr�hsr��__main__)1�__doc__�collectionsr�rBr�r�rsrrir��sysryr�r�rZtestr�platformZSkipTestrrrrrZtest.test_asynciorrgr�r�r
r�ZTestCaserr�rfr�r�rr6r?�
namedtupler@rFr�r�r�r�r?�mainrrrr�<module>sr

	
R
)
N2	5NF