Your IP : 216.73.216.213


Current Path : /opt/alt/python36/lib64/python3.6/test/test_asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/test/test_asyncio/__pycache__/test_base_events.cpython-36.pyc

3

� f�
�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl	m
Z
ddlZddlmZddlm
Z
ddlmZyddlmZWn ek
r�ddlmZYnXydd	lmZWnJek
�rydd	lmZWn"ek
�r
dd	lmZYnXYnXe
jZejdkZdd
�Zdd�ZGdd�dej�ZGdd�dej�ZGdd�dej �Z!Gdd�dej"�Z#Gdd�dej�Z$Gdd�de	j�Z%Gdd�dej�Z&e'dk�r�e	j(�dS) zTests for base_events.py�N)�mock)�base_events)�	constants)�
test_utils)�support)�test_support)�assert_python_ok��c
Csdtjtd�}x4d
D],}tt|�r4t||tt|��qt||�qWtj�|_tj�|j_	d|j
_|S)N)�spec�AF_INET�AF_INET6�	AF_UNSPEC�IPPROTO_TCP�IPPROTO_UDP�SOCK_STREAM�
SOCK_DGRAM�
SOL_SOCKET�SO_REUSEADDR�	inet_ptonF)
rr
rrrrrrrr)rZ	MagicMock�socket�hasattr�setattr�getattr�delattrrZmock_nonblocking_socket�return_value�getaddrinfo�
_is_coroutine)�m_socket�name�r �G/opt/alt/python36/lib64/python3.6/test/test_asyncio/test_base_events.py�mock_socket_module"s

r"cCstjdtd�|�S)Nzasyncio.base_events.socket)Znew_callable)r�patchr")�fr r r!�patch_socket4sr%c@s(eZdZdd�Zdd�Zedd��ZdS)�BaseEventTestsc	Cs�tj}tj}tj}tj}tj}tj}tj}|j|||ddft	j
dd|||��|j|||dd	ft	j
dd|||��|j|||dd
ft	j
dd|||��|j|||ddft	j
dd|||��|j|||ddft	j
dd||d��|j|||dd
ft	j
dd||d��|jt	j
dd|dd��|jt	j
dd|||��|j|||ddft	j
dd|||��|j|||ddft	j
dd|||��|jt	j
dd|||��|jt	j
dd|||��dS)N��1.2.3.4�s1.2.3.4r�::3z::3%lo0)r(r))r(r))r(r))r(r))r(r))r(r))r*r)rr)r*r)rr)rrrr
rrrr�assertEqualr�_ipaddr_info�assertIsNone)�selfZUNSPEC�INETZINET6�STREAMZDGRAM�TCPZUDPr r r!�test_ipaddr_info;sNzBaseEventTests.test_ipaddr_infocCs�tj}tj}tj}|j|||ddftjdd|||��|j|||dd	ftjdd|||��|j|||dd
ftjdd|||��|j|||ddftjdd|||��|j|||ddftjdd|||��dS)
Nr'�1.2.3.4r�r)�1�1)r3r)r3r)r3r)r3r))r3r))rrrrr+rr,)r.r/r0r1r r r!�test_port_parameter_typesvs$z(BaseEventTests.test_port_parameter_typescCs&|`|jtjddtjtjtj��dS)Nz1.2.3.4r))rr-rr,rrrr)r.rr r r!�test_ipaddr_info_no_inet_pton�s
z,BaseEventTests.test_ipaddr_info_no_inet_ptonN)�__name__�
__module__�__qualname__r2r7r%r8r r r r!r&9s;r&csneZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zejd#�d$d%��Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Z d:d;�Z!d<d=�Z"d>d?�Z#d@dA�Z$dBdC�Z%dDdE�Z&dFdG�Z'dHdI�Z(dJdK�Z)dLdM�Z*dNdO�Z+dPdQ�Z,dRdS�Z-dTdU�Z.�Z/S)V�BaseEventLoopTestscs<t�j�tj�|_tj�|j_f|jjj_	|j
|j�dS)N)�super�setUpr�
BaseEventLoop�loopr�Mock�	_selector�selectr�set_event_loop)r.)�	__class__r r!r>�s


zBaseEventLoopTests.setUpc	Cs�tj�}|jt|jj||�|jt|jj||||�|jt|jj||�|jt|jjg�|jt|jj	�|jt|jj
||�|jt|jj||�|jj|||||||�}|jt��|j
d�WdQRXdS)N)rrA�assertRaises�NotImplementedErrorr@Z_make_socket_transport�_make_ssl_transportZ_make_datagram_transport�_process_events�_write_to_selfZ_make_read_pipe_transportZ_make_write_pipe_transportZ_make_subprocess_transport�send)r.�m�genr r r!�test_not_implemented�s.z'BaseEventLoopTests.test_not_implementedcCsr|j|jj��|jj�|j|jj��|jj�|jj�tj|jd�}|jt|jj	�|jt|jj
|�dS)N)r@)�assertFalser@Z	is_closed�close�
assertTrue�asyncio�FuturerF�RuntimeError�run_forever�run_until_complete)r.r$r r r!�
test_close�s


zBaseEventLoopTests.test_closecCsBtjdd�f|j�}|jj|�|j|jj�|j||jj�dS)NcSsdS)NFr r r r r!�<lambda>�sz>BaseEventLoopTests.test__add_callback_handle.<locals>.<lambda>)rR�Handler@�
_add_callbackrO�
_scheduled�assertIn�_ready)r.�hr r r!�test__add_callback_handle�sz,BaseEventLoopTests.test__add_callback_handlecCsHtjdd�f|j�}|j�|jj|�|j|jj�|j|jj�dS)NcSsdS)NFr r r r r!rX�szHBaseEventLoopTests.test__add_callback_cancelled_handle.<locals>.<lambda>)rRrYr@�cancelrZrOr[r])r.r^r r r!�#test__add_callback_cancelled_handle�s
z6BaseEventLoopTests.test__add_callback_cancelled_handlecCs(tj�}|jj|�|j||jj�dS)N)rrAr@�set_default_executor�assertIsZ_default_executor)r.�executorr r r!�test_set_default_executor�sz,BaseEventLoopTests.test_set_default_executorcCsDtj�}tj�|j_|jj|�|jdtj|df|jjjd�dS)Nr)rrAr@�run_in_executorZgetnameinfor+r�	call_args)r.Zsockaddrr r r!�test_getnameinfo�sz#BaseEventLoopTests.test_getnameinfocCsDdd�}|jj|�}|j|j|�|j|tj�|j||jj�dS)NcSsdS)Nr r r r r!�cb�sz-BaseEventLoopTests.test_call_soon.<locals>.cb)	r@�	call_soonr+Z	_callback�assertIsInstancerRrYr\r])r.rir^r r r!�test_call_soon�s
z!BaseEventLoopTests.test_call_soonc	Cs4|jjd�|jtd��|jjd�WdQRXdS)NTza callable objectr))r@�	set_debug�assertRaisesRegex�	TypeErrorrj)r.r r r!�test_call_soon_non_callable�sz.BaseEventLoopTests.test_call_soon_non_callablecCsHdd�}|jjd|�}|j|tj�|j||jj�|j||jj�dS)NcSsdS)Nr r r r r!ri�sz.BaseEventLoopTests.test_call_later.<locals>.cbg$@)	r@�
call_laterrkrR�TimerHandler\r[ZassertNotInr])r.rir^r r r!�test_call_later�s
z"BaseEventLoopTests.test_call_latercs\g��fdd�}tj�|j_|jjd|d�|jjd|d�tj|j�|j�ddg�dS)	Ncs�j|�dS)N)�append)�arg)�callsr r!ri�sz>BaseEventLoopTests.test_call_later_negative_delays.<locals>.cbr)�a��b������)rrAr@rIrqr�run_brieflyr+)r.rir )rvr!�test_call_later_negative_delays�sz2BaseEventLoopTests.test_call_later_negative_delayscs~�fdd�}tj��j_d}�jj�|}�jj||��jj�}�jj��jj�|}�j||d|��j|d|�dS)Ncs�jj�dS)N)r@�stopr )r.r r!ri	sz4BaseEventLoopTests.test_time_and_call_at.<locals>.cbg�������?g�������?g�������?)	rrAr@rI�time�call_atrUZassertGreaterEqual�assertLessEqual)r.riZdelayZwhenZt0Zdtr )r.r!�test_time_and_call_ats

z(BaseEventLoopTests.test_time_and_call_atcCs�dd�}|j|�|r�d}|jt|��|j|�WdQRX|jt|��|jd|�WdQRX|jt|��|j|j�d|�WdQRXn*|j|�|jd|�|j|j�d|�dS)NcSsdS)Nr r r r r!risz+BaseEventLoopTests.check_thread.<locals>.cbzMNon-thread-safe operation invoked on an event loop other than the current one�<)rmrnrTrjrqr�r)r.r@�debugri�msgr r r!�check_threads
 
zBaseEventLoopTests.check_threadcsn�fdd��d�fdd�	}tj��j_tj��j_|�jd�|�jd�|�jddd�|�jddd�dS)	Ncs�|j�yN|rHtj�}ztj|��j||�Wdtjd�|j�Xn�j||�Wn0tk
r�}z|j|j	|�WYdd}~XnX|j|j
d�dS)N)�waitrr?rRrDr�rP�	Exception�call_soon_threadsafeZ
set_exception�
set_result)r@�eventr��create_loop�futZloop2�exc)r.r r!�check_in_thread/s

 z=BaseEventLoopTests.test_check_thread.<locals>.check_in_threadFcsZtj�}tj|d�}|j|j�|||||f}tj�|d�}|j�|j|�|j	�dS)N)r@)�target�args)
�	threadingZEventrRrSrj�setZThread�startrV�join)r@r�r�r�r�r�Zthread)r�r r!�test_threadCs
z9BaseEventLoopTests.test_check_thread.<locals>.test_threadT)r�)F)rrAr@rIrJ)r.r�r )r�r.r!�test_check_thread.s
z$BaseEventLoopTests.test_check_threadcCs�dd�}tj|jd�}tj�}||j_|jj|�|jjd|�}|j	||�tj�}||j_|jj||�}|j	||�|j
|jj�|j�dS)NcSsdS)Nr r r r r!ri^sz>BaseEventLoopTests.test_run_once_in_executor_plain.<locals>.cb)r@)
rRrSr@rrAZsubmitrrbrfrcrQ�calledr`)r.rir$rd�resr r r!�test_run_once_in_executor_plain]sz2BaseEventLoopTests.test_run_once_in_executor_plaincCs�tjtj�ddd�f|j�}tjtj�ddd�f|j�}|j�tj�|j_|jj	j
|�|jj	j
|�|jj�|jjj
jdd}|jd|ko�dkn|�|j|g|jj	�|j|jjj�dS)	Ng@cSsdS)NTr r r r r!rXrsz3BaseEventLoopTests.test__run_once.<locals>.<lambda>g$@cSsdS)NTr r r r r!rXtsrg#@g%@)rRrrr�	monotonicr@r`rrArIr[rt�	_run_oncerBrCrgrQr+r�)r.Zh1Zh2�tr r r!�test__run_onceqs
 z!BaseEventLoopTests.test__run_oncecCs<|jjd�|j|jj��|jjd�|j|jj��dS)NTF)r@rmrQZ	get_debugrO)r.r r r!�test_set_debug�sz!BaseEventLoopTests.test_set_debugzasyncio.base_events.loggercCs�dd�}|jjd�||jj_tj�|j_|jj�|jt	j
|jjdd�dd�}||jj_|jj�|jt	j
|jjdd�dS)NcSstjd�gS)Ng�������?)r�sleep)�timeoutr r r!�slow_select�s
z>BaseEventLoopTests.test__run_once_logging.<locals>.slow_selectTrcSstjd�gS)Ng����MbP?)rr�)r�r r r!�fast_select�s
z>BaseEventLoopTests.test__run_once_logging.<locals>.fast_select)r@rmrBrCrrArIr�r+�logging�INFO�logrg�DEBUG)r.�m_loggerr�r�r r r!�test__run_once_logging�s



z)BaseEventLoopTests.test__run_once_loggingcs|d�d���fdd�}tjtj�d||jf|j�}tj�|j_|jjj	|�|jj
�|j��|j�gt
|jj��dS)NFcsd�|jdd���dS)NTcSsdS)NTr r r r r!rX�szOBaseEventLoopTests.test__run_once_schedule_handle.<locals>.cb.<locals>.<lambda>)rj)r@)�handle�	processedr r!ri�sz=BaseEventLoopTests.test__run_once_schedule_handle.<locals>.cbr))rRrrrr�r@rrArIr[rtr�rQr+�listr])r.rir^r )r�r�r!�test__run_once_schedule_handle�s

z1BaseEventLoopTests.test__run_once_schedule_handlecCs�tj�|j_|jdtjko$dkn�dd�}d}|jjd|�d}x&td�D]}|jjd|�}|j	�qTW|d7}x&td�D]}|jjd	|�}|j	�q�W|j
||tj�|j|jj
|�|jj�|d8}|j|jj
|�|jt|jj�||�ttjtjtj��d}ttj|d�}||7}x t|�D]}|jjd|��q:W||7}x(t|�D]}|jjd|�}|j	��qdW|jt|jj�||�|jj�|jt|jj�|�|jtd
d�|jjD���dS)Nrg�?cSsdS)Nr r r r r!ri�szEBaseEventLoopTests.test__run_once_cancelled_event_cleanup.<locals>.cbr)i�rxi�dcSsg|]}|j�qSr )Z
_cancelled)�.0�xr r r!�
<listcomp>�szMBaseEventLoopTests.test__run_once_cancelled_event_cleanup.<locals>.<listcomp>)rrAr@rIrQrZ%_MIN_CANCELLED_TIMER_HANDLES_FRACTIONrq�ranger`r�Z_MIN_SCHEDULED_TIMER_HANDLESr+Z_timer_cancelled_countr��lenr[�int�mathZceil�max�all)r.riZnot_cancelled_countZcancelled_countr�r^Zadd_cancel_countZadd_not_cancel_countr r r!�&test__run_once_cancelled_event_cleanup�sN





z9BaseEventLoopTests.test__run_once_cancelled_event_cleanupcCs|jt|jjd�dS)NZblah)rFror@rV)r.r r r!�"test_run_until_complete_type_errorsz5BaseEventLoopTests.test_run_until_complete_type_errorcCs6tj|jd�}|j�}|j|j�|jt|j|�dS)N)r@)	rRrSr@Z
new_test_loop�
addCleanuprPrF�
ValueErrorrV)r.�taskZ
other_loopr r r!�test_run_until_complete_loops
z/BaseEventLoopTests.test_run_until_complete_loopcCs�tjddg}|jt|jj|jjtj�|jt|jj|jjtj|�|jt|jj|jjtjtjd�|jt|jj|jjtjf|�ddi�|jt|jj|jjtjf|�ddi�|jt|jj|jjtjf|�ddi�dS)	Nz-c�pass�{�universal_newlinesT�shell�bufsizei)	�sys�
executablerFror@rVZsubprocess_execrR�SubprocessProtocol)r.r�r r r!�!test_subprocess_exec_invalid_argss&
z4BaseEventLoopTests.test_subprocess_exec_invalid_argscCs�|jt|jj|jjtjd�|jt|jj|jjtjtjddg�|jt|jj|jjtjddd�|jt|jj|jjtjddd�|jt|jj|jjtjddd	�dS)
Nr�z-cr�zexit 0T)r�)r�i)r�)	rFror@rVZsubprocess_shellrRr�r�r�)r.r r r!�"test_subprocess_shell_invalid_args)s
z5BaseEventLoopTests.test_subprocess_shell_invalid_argscs�tj��j_dd�}tjd��Z}tj�jd�}�jj||�|j�fdd���jj	�|j
jtj
d�tttfd�WdQRXtjd��\}tj�jd�}�jjd	||�|j�fd
d���jj	�|j
jtj
d�tttfd�WdQRXdS)NcSs|jd�dddS)NTr)r)r�)r�r r r!�
zero_error@s
zHBaseEventLoopTests.test_default_exc_handler_callback.<locals>.zero_errorzasyncio.base_events.logger)r@cs
�jj�S)N)r@r~)r�)r.r r!rXHszFBaseEventLoopTests.test_default_exc_handler_callback.<locals>.<lambda>zException in callback.*zero)�exc_infog{�G�z�?cs
�jj�S)N)r@r~)r�)r.r r!rXRs)rrAr@rIr#rRrSrj�add_done_callbackrU�error�assert_called_withr�MockPattern�ZeroDivisionError�MOCK_ANYrq)r.r�r�r�r )r.r!�!test_default_exc_handler_callback=s$

z4BaseEventLoopTests.test_default_exc_handler_callbackcs�tj��j_tj�fdd��}tjd��x}tj|��jd�}|j�fdd���jj	�d}t
j�tr�|j
jtjd�tttfd�n|j
jtjd	�d
d�WdQRXdS)Nc3s"tjd�jd�EdHdddS)Ng{�G�z�?)r@r)r)rRr�r@r )r.r r!�zero_error_coro[szIBaseEventLoopTests.test_default_exc_handler_coro.<locals>.zero_error_corozasyncio.base_events.logger)r@cs
�jj�S)N)r@r~)r�)r.r r!rXcszBBaseEventLoopTests.test_default_exc_handler_coro.<locals>.<lambda>z.*exception was never retrieved)r�z(.*exception was never retrieved.*ZeroDivF)rrAr@rIrR�	coroutiner#�
ensure_futurer�rUr�
gc_collect�PY34r�r�rr�r�r�)r.r�r�r�r )r.r!�test_default_exc_handler_coroXs 
z0BaseEventLoopTests.test_default_exc_handler_coroc	Cs(|jtd��|jjd�WdQRXdS)NzA callable object or None�spam)rnror@�set_exception_handler)r.r r r!�test_set_exc_handler_invalidtsz/BaseEventLoopTests.test_set_exc_handler_invalidcs�dd����fdd�}�jjd�tj��j_�j�jj��tj�}�jj|��j�jj�|�|�}|j	�jt
tjd�||j
d��|j��jjd�tjd��(}|�|jj	tjd	�tt
t
fd
�WdQRX|js�t�dS)NcSsdddS)Nr)rr r r r r!r�yszBBaseEventLoopTests.test_set_exc_handler_custom.<locals>.zero_errorcs�jj��}�jj�|S)N)r@rjr�)r�)r.r�r r!�run_loop|s
z@BaseEventLoopTests.test_set_exc_handler_custom.<locals>.run_loopTz!Exception in callback.*zero_error)�	exception�messager�Zsource_tracebackzasyncio.base_events.loggerzException in callback.*zero)r�)r@rmrrArIr-Zget_exception_handlerr�rcr�r�rr�Z_source_traceback�
reset_mockr#r�r�r��AssertionError)r.r�Zmock_handlerr�r�r )r.r�r!�test_set_exc_handler_customxs0z.BaseEventLoopTests.test_set_exc_handler_customcsh�fdd�}dd�}tj��j_�jj|�tjd��(}|�|jjtj	d�t
ttfd�WdQRXdS)Ncs"dd�}�jj|��jj�dS)NcSsdddS)Nr)rr r r r r!r��szTBaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loop.<locals>.zero_error)r@rjr�)r�)r.r r!r��sz@BaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loopcSstd��dS)Nr�)�AttributeError)r@�contextr r r!�handler�sz?BaseEventLoopTests.test_set_exc_handler_broken.<locals>.handlerzasyncio.base_events.loggerz$Unhandled error in exception handler)r�)rrAr@rIr�r#r�r�rr�r�r�)r.r�r�r�r )r.r!�test_set_exc_handler_broken�sz.BaseEventLoopTests.test_set_exc_handler_brokencs�d�G�fdd�dtj�}|��|j�j�tj���fdd�}tjd��}|�|jj	ddd�WdQRXd	d
�}d��j
|�tjd��F}|�|jj	tjd�dd�|j
d��|jt�dd
�t�WdQRXdS)Ncs(eZdZej�Zej�Z�fdd�ZdS)z@BaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loopcs|�td��dS)Nr�)r�)r.r�)�_contextr r!�default_exception_handler�szZBaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loop.default_exception_handlerN)r9r:r;rrArBrIr�r )r�r r!�Loop�sr�csdd�}�j|��j�dS)NcSsdddS)Nr)rr r r r r!r��szXBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loop.<locals>.zero_error)rjr�)r�)r@r r!r��s
zDBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loopzasyncio.base_events.loggerz&Exception in default exception handlerT)r�cSstd��dS)NZham)r�)r@r�r r r!�custom_handler�szJBaseEventLoopTests.test_default_exc_handler_broken.<locals>.custom_handlerz9Exception in default exception.*while handling.*in customr�r�)rr?r�rPrRrDrr#r�r�r�rr�r\rc�typer�)r.r�r�r�r�r )r�r@r!�test_default_exc_handler_broken�s,

z2BaseEventLoopTests.test_default_exc_handler_brokenc	Cs8|jtd��|jjd�WdQRX|j|jj��dS)Nz'task factory must be a callable or Noner))rnror@�set_task_factoryr-�get_task_factory)r.r r r!�test_set_task_factory_invalid�s
z0BaseEventLoopTests.test_set_task_factory_invalidcs�tj�|j_Gdd�dtj��tjdd��}�fdd�}|j|jj��|jj	|�|j
|jj�|�|jj|��}|jt
|���|jj|�|jj	d�|j|jj��|jj|��}|jt
|tj��|jt
|���|jj|�dS)Nc@seZdZdS)z8BaseEventLoopTests.test_set_task_factory.<locals>.MyTaskN)r9r:r;r r r r!�MyTask�sr�cSsdS)Nr r r r r!�coro�sz6BaseEventLoopTests.test_set_task_factory.<locals>.corocs�||d�S)N)r@r )r@r�)r�r r!rX�sz:BaseEventLoopTests.test_set_task_factory.<locals>.<lambda>)rrAr@rIrR�Taskr�r-r�r�rc�create_taskrQ�
isinstancerVrO)r.r��factoryr�r )r�r!�test_set_task_factory�s z(BaseEventLoopTests.test_set_task_factorycCs�djd�}tdd|�\}}}|j|j�d�td|dd	�\}}}|j|j�d�td|d
d	�\}}}|j|j�d�tdd|d
d	�\}}}|j|j�d�dS)
N�
�import asyncio�loop = asyncio.get_event_loop()�print(loop.get_debug())z-Ez-csFalser')ZPYTHONASYNCIODEBUGr5sTrue)r�r�r�)r�rr+�rstrip)r.�code�sts�stdout�stderrr r r!�test_env_var_debugsz%BaseEventLoopTests.test_env_var_debugcszGdd�dtj��tjdd��}G��fdd�dtj�}|��|j��|�}tj|�d�}|j|��d|_|j	�dS)	Nc@seZdZdS)z3BaseEventLoopTests.test_create_task.<locals>.MyTaskN)r9r:r;r r r r!r�sr�cSsdS)Nr r r r r!�test sz1BaseEventLoopTests.test_create_task.<locals>.testcseZdZ��fdd�ZdS)z6BaseEventLoopTests.test_create_task.<locals>.EventLoopcs�|�d�S)N)r@r )r.r�)r�r@r r!r�%szBBaseEventLoopTests.test_create_task.<locals>.EventLoop.create_taskN)r9r:r;r�r )r�r@r r!�	EventLoop$sr�)r@F)
rRr�r�rr?rDr�rkZ_log_destroy_pendingrP)r.r�r�r�r�r )r�r@r!�test_create_tasks
z#BaseEventLoopTests.test_create_taskcCsttjdd��}tj�|j_tj�|j_y|jj|��Wntk
rLYnX|jj	�t
j�|j|jjj
�dS)NcSst�dS)N)�KeyboardInterruptr r r r!�raise_keyboard_interrupt7szXBaseEventLoopTests.test_run_forever_keyboard_interrupt.<locals>.raise_keyboard_interrupt)rRr�rrAr@rIZcall_exception_handlerrVrrPrr�rOr�)r.rr r r!�#test_run_forever_keyboard_interrupt3s
z6BaseEventLoopTests.test_run_forever_keyboard_interruptcs�tjdd��}tj��j_y�jj|��Wntk
r@YnX��fdd��d�_y�jj	���jj
�Wntk
r�YnX�j�j�dS)NcSst�dS)N)rr r r r!rJszZBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.raise_keyboard_interruptcs�jj�d�_dS)NT)r@r~r�r )�funcr.r r!rUs
zFBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.funcF)rRr�rrAr@rIrVrr�rjrUrQ)r.rr )rr.r!�%test_run_until_complete_baseexceptionGsz8BaseEventLoopTests.test_run_until_complete_baseexceptioncs�t��d�d�����fdd�}���fdd����fdd��|�j_�f�jjj_xRtdd	�D]D}�jd
|��,�jj�jj	��jj
��j�d�WdQRXq`WdS)Nrcs�|kr�jj���dS)N)r@rj)Z
event_list)�do_event�doer�event_sentinelr.r r!�proc_eventsgszZBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.proc_eventscs�d7��jj��dS)Nr))r@rjr )�	callcount�clear_selectorr.r r!rlszWBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.do_eventcs�j�f�jjj_dS)N)r`r@rBrCrr )rr.r r!rqsz]BaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.clear_selectorr)r	z	Loop %d/2)�objectr@rIrBrCrr�ZsubTestrjr~rUr+)r.r	�ir )r
rrrrr.r!�2test_single_selecter_event_callback_after_stopping`s
zEBaseEventLoopTests.test_single_selecter_event_callback_after_stoppingcsDd��fdd�}tj�|j_|jj|�tj|j�|j�d�dS)Nrcs�d7�dS)Nr)r r )�countr r!�callback�sz2BaseEventLoopTests.test_run_once.<locals>.callbackr))rrAr@rIrjrZrun_oncer+)r.rr )rr!�
test_run_once~sz BaseEventLoopTests.test_run_oncecCs4tj�|j_|jj�|jj�|jjjjd�dS)Nr)	rrAr@rIr~rUrBrCZassert_called_once_with)r.r r r!�test_run_forever_pre_stopped�s

z/BaseEventLoopTests.test_run_forever_pre_stoppedc�sJdddd���fdd�}|�}|j������fdd���jj����S)NF)�started�stopped�	finalizedcs0d�d<zxd	D]
}|VqWWdd�d<XdS)
NTr�ZERO�ONE�TWO�THREE�FOURr)rrrrrr )�item)�statusr r!�agen�s

z;BaseEventLoopTests.leave_unfinalized_asyncgen.<locals>.agenc�sNy�j�IdH}Wntk
r&dSX|dkr<d�d<dS�jj���dS)NrTr)�	__anext__�StopAsyncIterationr@r�)r)�ai�iter_oner.rr r!r!�sz?BaseEventLoopTests.leave_unfinalized_asyncgen.<locals>.iter_one)�	__aiter__r@r�)r.rZagr )r r!r.rr!�leave_unfinalized_asyncgen�s
z-BaseEventLoopTests.leave_unfinalized_asyncgenc
Cs�tj�|j_tj�|j_tj��||jj|j��}x|dsJt	j
|j�q4W|j|d�|j|d�|j|d�tj
�t	j
|j�|j|d�WdQRXdS)Nrrr)rrAr@rIrJr�
disable_gcrVr#rr|rQrOr�)r.rr r r!� test_asyncgen_finalization_by_gc�s

z3BaseEventLoopTests.test_asyncgen_finalization_by_gccCs�tj�|j_tj�|j_|jjd�tj���|jj|j	��}x|dsVt
j|j�q@W|j|d�|j|d�|j
|d�|jj|jjdtj��t
j|j�|j|d�WdQRXdS)NTrrr)rrAr@rIrJrmrr$rVr#rr|rQrOrfr�)r.rr r r!�0test_asyncgen_finalization_by_gc_in_other_thread�s

zCBaseEventLoopTests.test_asyncgen_finalization_by_gc_in_other_thread)0r9r:r;r>rNrWr_rarerhrlrprsr}r�r�r�r�r�r�rr#r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrr#r%r&�
__classcell__r r )rEr!r<�sT		/L$0"r<c@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)�MyProtoNFcCsd|_d|_|rtj�|_dS)N�INITIALr)�state�nbytesrRrS�done)r.�
create_futurer r r!�__init__�szMyProto.__init__cCs.||_|jdkst|j��d|_|jd�dS)Nr)�	CONNECTEDs%GET / HTTP/1.0
Host: example.com

)�	transportr*r��write)r.r0r r r!�connection_made�szMyProto.connection_madecCs*|jdkst|j��|jt|�7_dS)Nr/)r*r�r+r�)r.�datar r r!�
data_received�szMyProto.data_receivedcCs|jdkst|j��d|_dS)Nr/�EOF)r*r�)r.r r r!�eof_received�szMyProto.eof_receivedcCs0|jdkst|j��d|_|jr,|jjd�dS)Nr/r5�CLOSED)r/r5)r*r�r,r�)r.r�r r r!�connection_lost�szMyProto.connection_lost)F)	r9r:r;r,r.r2r4r6r8r r r r!r(�s
r(c@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)�MyDatagramProtoNFcCs"d|_d|_|rtj|d�|_dS)Nr)r)r@)r*r+rRrSr,)r.r-r@r r r!r.�szMyDatagramProto.__init__cCs$||_|jdkst|j��d|_dS)Nr)�INITIALIZED)r0r*r�)r.r0r r r!r2szMyDatagramProto.connection_madecCs*|jdkst|j��|jt|�7_dS)Nr:)r*r�r+r�)r.r3�addrr r r!�datagram_receivedsz!MyDatagramProto.datagram_receivedcCs|jdkst|j��dS)Nr:)r*r�)r.r�r r r!�error_received
szMyDatagramProto.error_receivedcCs0|jdkst|j��d|_|jr,|jjd�dS)Nr:r7)r*r�r,r�)r.r�r r r!r8
szMyDatagramProto.connection_lost)FN)	r9r:r;r,r.r2r<r=r8r r r r!r9�s
r9cs"eZdZ�fdd�Zedd��Zedd��Zdd�Zd	d
�Zdd�Z	e
jee
d
�d�dd��Ze
jee
d�d�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zedd ��Zd!d"�Zed#d$��Zed%d&��Zed'd(��Zd)d*�Zed+d,��Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Z d7d8�Z!d9d:�Z"ed;d<��Z#ed=d>��Z$ed?d@��Z%edAdB��Z&dCdD�Z'dEdF�Z(edGdH��Z)e
je*j+dI�dJdK��Z,edLdM��Z-dNdO�Z.edPdQ��Z/dRdS�Z0dTdU�Z1dVdW�Z2dXdY�Z3dZd[�Z4ed\d]��Z5ed^d_��Z6d`da�Z7e8j9db�dcdd��Z:dedf�Z;e8j9db�dgdh��Z<�Z=S)i�BaseEventLoopWithSelectorTestscs$t�j�tj�|_|j|j�dS)N)r=r>rR�new_event_loopr@rD)r.)rEr r!r>s

z$BaseEventLoopWithSelectorTests.setUpc
s�Gdd�dtj�}tjdd�����fdd�}d�dd	g���fd
d�}||_|�j_�jj|dd
�}�jt��}�jj	|�WdQRX�j
t|j�d�dS)Nc@seZdZdS)zVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.MyProtoN)r9r:r;r r r r!r(sr(csgEdHdd
gS)Nrxr)�r'�107.6.106.82�P�rArB)rxr)r@r'rC�rArB)rxr)r@r'rDr )r��kwr r r!r!s
zZBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfocstj�||��jd�S)N)r@)rRr�r@)r��kwds)rr.r r!�getaddrinfo_task'sz_BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfo_taskr)Zerr1Zerr2cs�d7�t����dS)Nr))�OSError)r�rE)�errors�idxr r!�_socket-szVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>._socketzexample.comrBzMultiple exceptions: err1, err2rz)
rR�Protocolr�rr@r�create_connectionrFrHrVr+�strr�)r.rr(rGrKr��cmr )rIrrJr.r!�&test_create_connection_multiple_errorsszEBaseEventLoopWithSelectorTests.test_create_connection_multiple_errorscs�tj�}||j_�fdd�}|�j_tjj�jdtj	d��H�jj
tdd�}�jtj	���jj
|�WdQRX�j|jj�WdQRXdS)Ncs0tj�jd�}tjtjdddf}|j|g�|S)N)r@rr'�	127.0.0.1rB)rQrB)rRrSr@rrrr�)r�rEr�r;)r.r r!rBs
zRBaseEventLoopWithSelectorTests.test_create_connection_timeout.<locals>.getaddrinfo�sock_connect)�side_effectz	127.0.0.1rB)rrArrr@rr#rrR�TimeoutErrorrMr(rFrVrQrPr�)r.r�sockrr�r )r.r!�test_create_connection_timeout<sz=BaseEventLoopWithSelectorTests.test_create_connection_timeoutcCs,|jjtddt�d�}|jt|jj|�dS)Nzexample.comrB)rU)r@rMr(rrFr�rV)r.r�r r r!�%test_create_connection_host_port_sockQszDBaseEventLoopWithSelectorTests.test_create_connection_host_port_sockcCsXtjtjtj�}|�:|jjt|d�}|jtd��|jj|�WdQRXWdQRXdS)N)rUzA Stream Socket was expected)	rrrr@rMr(rnr�rV)r.rUr�r r r!�!test_create_connection_wrong_sockVsz@BaseEventLoopWithSelectorTests.test_create_connection_wrong_sockcCsXtjtjtj�}|�:|jjt|d�}|jtd��|jj|�WdQRXWdQRXdS)N)rUzA Stream Socket was expected)	rrrr@�
create_serverr(rnr�rV)r.rUr�r r r!�test_create_server_wrong_sock^sz<BaseEventLoopWithSelectorTests.test_create_server_wrong_sock�
SOCK_NONBLOCKz$no socket.SOCK_NONBLOCK (linux only)cCsbtjtjtjtjB�}|�>|jjdd�|d�}|jj|�}|j�|jj|j��WdQRXdS)NcSsdS)Nr r r r r!rXlszRBaseEventLoopWithSelectorTests.test_create_server_stream_bittype.<locals>.<lambda>)rU)	rrrr[r@rYrVrP�wait_closed)r.rUr��srvr r r!�!test_create_server_stream_bittypefsz@BaseEventLoopWithSelectorTests.test_create_server_stream_bittyper
zno IPv6 supportcsj�fdd�}y�jj|��WnFtk
rd}z*ttd�rR|jtjkrR�jd�n�WYdd}~XnXdS)Nc�sRtjdd�dd�jd�IdH}z�jt|j�d�Wd|j�|j�IdHXdS)NcSsdS)Nr r r r r!rXuszVBaseEventLoopWithSelectorTests.test_create_server_ipv6.<locals>.main.<locals>.<lambda>z::1r)r@)rRZstart_serverr@Z
assertGreaterr�ZsocketsrPr\)r])r.r r!�mainsszDBaseEventLoopWithSelectorTests.test_create_server_ipv6.<locals>.main�
EADDRNOTAVAILzfailed to bind to ::1)r@rVrHr�errnor`ZskipTest)r.r_Zexr )r.r!�test_create_server_ipv6qs	
z6BaseEventLoopWithSelectorTests.test_create_server_ipv6cCsTtjtj�}|�:|jjt|d�}|jtd��|jj|�WdQRXWdQRXdS)N)rUzA UDP Socket was expected)rrr@�create_datagram_endpointr(rnr�rV)r.rUr�r r r!�(test_create_datagram_endpoint_wrong_sock�szGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_wrong_sockcCs"|jjt�}|jt|jj|�dS)N)r@rMr(rFr�rV)r.r�r r r!�(test_create_connection_no_host_port_sock�szGBaseEventLoopWithSelectorTests.test_create_connection_no_host_port_sockcsJtjdd�����fdd�}|�j_�jjtdd�}�jt�jj|�dS)NcsgEdHdS)Nr )r�rEr r r!r�szYBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfocstj�||��jd�S)N)r@)rRr�r@)r�rF)rr.r r!rG�sz^BaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfo_taskzexample.comrB)	rRr�r@rrMr(rFrHrV)r.rGr�r )rr.r!�%test_create_connection_no_getaddrinfo�szDBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfocs`tjdd�����fdd�}|�j_tj��j_t�jj_�jj	t
dd�}�jt�jj|�dS)NcsgEdHdgS)	Nrxr)r@r'�107.6.106.82rB�rgrB)rxr)r@r'rhr )r�rEr r r!r�s
zVBaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfocstj�||��jd�S)N)r@)rRr�r@)r�rF)rr.r r!rG�sz[BaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfo_taskzexample.comrB)
rRr�r@rrrArRrHrSrMr(rFrV)r.rGr�r )rr.r!�"test_create_connection_connect_err�s
zABaseEventLoopWithSelectorTests.test_create_connection_connect_errc	svtjdd�����fdd�}|�j_tj��j_t�jj_�jj	t
ddtjd�}�j
t���jj|�WdQRXdS)Nc_sd	dgS)Nrxr)r@r'�0.0.0.1rB�0.0.0.2�rjrB)rxr)r@r'rl�rkrB)rxr)r@r'rmr )r�rEr r r!r�szSBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfocstj�||��jd�S)N)r@)rRr�r@)r�rF)rr.r r!rG�szXBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfo_taskzexample.comrB)�family)rRr�r@rrrArRrHrSrMr(rrrFrV)r.rGr�r )rr.r!�test_create_connection_multiple�s
z>BaseEventLoopWithSelectorTests.test_create_connection_multiplec
s�dd�}||jj_tjdd�����fdd�}|�j_tj��j_	t
d��jj	_�jjt
dd	tjd
d�}�jt
��}�jj|�WdQRX�jt|j�jd���j|jjjj�dS)NcSs"|ddkrtd�}d|_|�dS)Nrz0.0.0.1�Err)rH�strerror)r;�errr r r!�bind�sz^BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.bindc_sd	dgS)Nrxr)r@r'�0.0.0.1rB�0.0.0.2�rtrB)rxr)r@r'rv�rurB)rxr)r@r'rwr )r�rEr r r!r�szeBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfocstj�||��jd�S)N)r@)rRr�r@)r�rF)rr.r r!rG�szjBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfo_taskZErr2zexample.comrB�)rn�
local_addrzMultiple exceptions: )Nrx)rrrsrRr�r@rrrArRrHrSrMr(rrFrVrQrNr��
startswithrPr�)r.rrsrGr�rOr )rr.r!�1test_create_connection_multiple_errors_local_addr�s

zPBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addrcCsn|s|`tj|_|jj}tj�|j_d|jj_tj�|j_	d|jj	_|jj
tjdd�}|jj
|�\}}z@|jjd
�|jj\}}|j|d|j�|j|d|j�Wd|j�tj|j�Xtj|_|jj
tjdd�}|jj
|�\}}zj|jjd\}	|	dd�\}
}|j|
d	�|j|d�|jj\}}|j|d|j�|j|d|j�Wd|j�tj|j�XdS)NF�1.2.3.4rBrnr�z::1rrxz	::(0\.)*1)r|rB)rrrrrrAr@�_add_readerr�_add_writerrMrRrLrV�connectr�rgr+rrrPrr|r
rn�assertRegex)r.rZallow_inet_ptonrUr�r��p�_�kwargsZaddress�host�portr r r!�_test_create_connection_ip_addr�s<

z>BaseEventLoopWithSelectorTests._test_create_connection_ip_addrcCs|j|d�dS)NT)r�)r.rr r r!�test_create_connection_ip_addr
sz=BaseEventLoopWithSelectorTests.test_create_connection_ip_addrcCs|j|d�dS)NF)r�)r.rr r r!�#test_create_connection_no_inet_ptonszBBaseEventLoopWithSelectorTests.test_create_connection_no_inet_ptonc
Cstj|_|jj}tj�|j_d|jj_tj�|j_d|jj_x�dD]�\}}|jj	t
jd|�}|jj|�\}}zD|j
jd|f�|jj\}}	|j|	d|j�|j|	d|j�Wd|j�tj|j�XqBWx@d
D]8}|jj	t
jd|�}|jt��|jj|�WdQRXq�WdS)NF�httprB�httpz	127.0.0.1rnr��nonsense�nonsense�r�rB�r�rB)r�r�)r�r�)rrrrrAr@r}rr~rMrRrLrVrr�rgr+rrrPrr|rFrH)
r.rrUZservicer�r�r�r�r�r�r r r!�#test_create_connection_service_names,




zBBaseEventLoopWithSelectorTests.test_create_connection_service_namecsRtjdd�����fdd�}|�j_�jjtddtjd	d�}�jt	�jj
|�dS)
Nc_s|dkrd	dgSgSdS)Nzexample.comrxr)r@r'�107.6.106.82rB�r�rB)rxr)r@r'r��r�rB)rxr)r@r'r�r )r�r�rEr r r!r2szXBaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfocstj�||��jd�S)N)r@)rRr�r@)r�rF)rr.r r!rG:sz]BaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfo_taskzexample.comrB�)rnry)Nr�)rRr�r@rrMr(rrrFrHrV)r.rGr�r )rr.r!�$test_create_connection_no_local_addr1s
zCBaseEventLoopWithSelectorTests.test_create_connection_no_local_addrcs<d��fdd�}||_|j�}|jj|��}|jj|�dS)N�00:01:02:03:04:05r)cs$||f�kst�dddd�dffgS)Ni�r)r')r�)r�r�r�rE)r;r r!rJszTBaseEventLoopWithSelectorTests.test_create_connection_bluetooth.<locals>.getaddrinfo)r�r))rrr@rRrV)r.rrrUr�r )r;r!� test_create_connection_bluetoothDsz?BaseEventLoopWithSelectorTests.test_create_connection_bluetoothcsltj��j_�fdd�}|�jj_tj��j_f�jj_tj��j_Gdd�d���fdd�}|�jj_tj}�jjj	��jj
tddd	d
�}�jj|�\}}|j
��jjj||||ddd��jjj	��jj
tddd	d
d�}�jj|�\}}|j
��jjj||||dd
d��jjj	��jj
tddd	dd�}�jj|�\}}|j
��jjj||||ddd�dS)Ncs.tj�jd�}|jtjtjtjddfg�|S)N)r@r'�1.2.3.4rB)r�rB)rRrSr@r�rrrZSOL_TCP)r�rFr$)r.r r!�mock_getaddrinfoVszkBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>.mock_getaddrinfoc@s eZdZdZdd�Zdd�ZdS)zqBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMockNcSstj�S)N)rrA)r.�keyr r r!�get_extra_infodsz�BaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.get_extra_infocSs|jj�dS)N)�_sockrP)r.r r r!rPgszwBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.close)r9r:r;r�r�rPr r r r!�_SelectorTransportMockasr�cs|jd���}||_|S)N)r�r�)rU�protocolZ
sslcontextZwaiterrFr0)r�r r!�mock_make_ssl_transportjs
zrBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>.mock_make_ssl_transportz
python.orgrBT)�sslF)Zserver_side�server_hostnamezperl.com)r�r�r')rrAr@rrSrRrrH�ANYr�rMr(rVrPr�)r.r�r�r�r�r0r�r )r�r.r!�2test_create_connection_ssl_server_hostname_defaultSsF

	
zQBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_defaultcCsP|jjtdddd�}|jt|jj|�|jjtdddd�}|jt|jj|�dS)Nz
python.orgrBr')r�)r@rMr(rFr�rV)r.r�r r r!�4test_create_connection_no_ssl_server_hostname_errors�szSBaseEventLoopWithSelectorTests.test_create_connection_no_ssl_server_hostname_errorscCs�|jjtdddd�}|jt|jj|�|jjtdddd�}|jt|jj|�tj�}|jjtddd|d�}|j|j�|jt|jj|�dS)Nr'rBT)r�)r�rU)	r@rMr(rFr�rVrr�rP)r.r�rUr r r!�1test_create_connection_ssl_server_hostname_errors�s
zPBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_errorscs^t��tj�fdd�����fdd�}|�j_�jjtdd�}�jt�jj	|��j
��dS)Nc?s|d�gEdHdS)Nrr )r�rE)r�r r!r�szQBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfocstj�||��jd�S)N)r@)rRr�r@)r�rF)rr.r r!rG�szVBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfo_taskr'r)rrRr�r@rrYr(rFrHrVr-)r.rGr�r )rr�r.r!�test_create_server_empty_host�sz<BaseEventLoopWithSelectorTests.test_create_server_empty_hostcCs,|jjtddt�d�}|jt|jj|�dS)Nz0.0.0.0r)rU)r@rYr(rrFr�rV)r.r�r r r!�!test_create_server_host_port_sock�sz@BaseEventLoopWithSelectorTests.test_create_server_host_port_sockcCs"|jjt�}|jt|jj|�dS)N)r@rYr(rFr�rV)r.r�r r r!�$test_create_server_no_host_port_sock�szCBaseEventLoopWithSelectorTests.test_create_server_no_host_port_sockcCs<tj�}|j_g|_|jjtdd�}|jt|jj	|�dS)Nz
python.orgr)
rrAr@rrrYr(rFrHrV)r.rr$r r r!�!test_create_server_no_getaddrinfo�sz@BaseEventLoopWithSelectorTests.test_create_server_no_getaddrinfocCsBtj|_|`tj�|j_|jjtdddd�}|j	t
|jj|�dS)Nz0.0.0.0rT)�
reuse_port)rr�SO_REUSEPORTrrArr@rYr(rFr�rV)r.rr$r r r!� test_create_server_nosoreuseport�sz?BaseEventLoopWithSelectorTests.test_create_server_nosoreuseportcCsDtj|_tj�|j_d|_|jjtdddd�}|j	t
|jj|�dS)Nr)z0.0.0.0rT)r�rz)rrrrArr�r@rYr(rFr�rV)r.rr$r r r!�+test_create_server_soreuseport_only_defined�szJBaseEventLoopWithSelectorTests.test_create_server_soreuseport_only_definedcCsnGdd�dt�}d
g|j_d	|j_tj�}|j_||j_|j	j
td
d�}|jt|j	j
|�|j|jj�dS)Nc@seZdZdZdS)zHBaseEventLoopWithSelectorTests.test_create_server_cant_bind.<locals>.Errr�N)r9r:r;rqr r r r!rp�srprxr)r@r'�	127.0.0.1�t'Fz0.0.0.0r�r�r�)rxr)r@r'r�)rHrrrrrArrsrSr@rYr(rFrVrQrPr�)r.rrp�m_sockr�r r r!�test_create_server_cant_bind�s
z;BaseEventLoopWithSelectorTests.test_create_server_cant_bindcCs6g|j_d|j_|jjtdd�}|jt|jj|�dS)NF�	localhostr)ry)r�r)	rrrr@rcr9rFrHrV)r.rr�r r r!�)test_create_datagram_endpoint_no_addrinfo�s
zHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_addrinfocCsH|jjtdd�}|jt|jj|�|jjtdd�}|jt|jj|�dS)Nr�)ryr)rxr	)r�r)rxr	)r@rcr9rFr�rV)r.r�r r r!�(test_create_datagram_endpoint_addr_error�s

zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_addr_errorcCs>tj�|j_t|jj_|jjtjdd�}|j	t|jj
|�dS)N�	127.0.0.1r)�remote_addr)r�r)rrAr@rRrHrSrcrR�DatagramProtocolrFrV)r.r�r r r!�)test_create_datagram_endpoint_connect_errs
zHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_connect_errcCs^tj|_t|j_|jjtjtjd�}|j	t|jj
|�|jjtjdd�}|j	t|jj
|�dS)N)rn�	127.0.0.1r)ry)r�r)rrrHrSr@rcrRr�rrFrV)r.rr�r r r!�(test_create_datagram_endpoint_socket_err
szGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_socket_errzIPv6 not supported or enabledcCs*|jjtjddd�}|jt|jj|�dS)N�	127.0.0.1r�::1)r�ry)r�r)r�r)r@rcrRr�rFr�rV)r.r�r r r!�0test_create_datagram_endpoint_no_matching_familys

zOBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_matching_familycCsHt|jjj_|jjtjtj	d�}|j
t|jj|�|j|jjj
j�dS)N)rn)rHrr�setblockingrSr@rcrRr�rrFrVrQrPr�)r.rr�r r r!�(test_create_datagram_endpoint_setblk_err!szGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_setblk_errcCs$|jjtj�}|jt|jj|�dS)N)r@rcrRr�rFr�rV)r.r�r r r!�-test_create_datagram_endpoint_noaddr_nofamily,szLBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_noaddr_nofamilycCshGdd�dt�}tj|_tj�}|j_||j_|jj	t
dtjd�}|j||jj
|�|j|jj�dS)Nc@seZdZdS)zSBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_cant_bind.<locals>.ErrN)r9r:r;r r r r!rp3srp�	127.0.0.1r)ryrn)r�r)rHrrrrArrsrSr@rcr9rrFrVrQrPr�)r.rrpr�r�r r r!�'test_create_datagram_endpoint_cant_bind1szFBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_cant_bindcsjtjtjtj�}|jd��jj�fdd�|d�}�jj|�\}}|j��jj|j��j	d|j
�dS)N�	127.0.0.1rcstd�jd�S)NT)r-r@)r9r@r )r.r r!rXDszSBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock.<locals>.<lambda>)rUr7)r�r)rrrrsr@rcrVrPr,r+r*)r.rUr�r0r�r )r.r!�"test_create_datagram_endpoint_sock@s

zABaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockcCsGdd�d�}|jjtd|�d�}|jt|jj|�|jjtd|�d�}|jt|jj|�|jjtd|�d�}|jt|jj|�|jjtd|�d	�}|jt|jj|�|jjtd|�d
�}|jt|jj|�|jjtd|�d�}|jt|jj|�|jjtd|�d
�}|jt|jj|�dS)Nc@seZdZejZdS)z\BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_sockopts.<locals>.FakeSockN)r9r:r;rrr�r r r r!�FakeSockLsr��	127.0.0.1r)ryrU)r�rUr))rnrU)�protorU)�flagsrUT)r�rU)�allow_broadcastrU)r�r)r�r)r@rcr9rFr�rV)r.r�r�r r r!�+test_create_datagram_endpoint_sock_sockoptsKs,zJBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_sockoptscs4�jj�fdd�dd�}�jj|�\}}|jd�}ttd�}|rV�j|jtjtj	���j|jtjtj
��|j��jj|j��j
d|j��jj�fd	d�d
|d
d�}�jj|�\}}|jd�}�j|jtjtj��|r��j|jtjtj	���j|jtjtj
��|j��jj|j��j
d|j�dS)Ncstd�jd�S)NT)r-r@)r9r@r )r.r r!rXpszWBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockopts.<locals>.<lambda>�	127.0.0.1r)ryrr�r7cstd�jd�S)NT)r-r@)r9r@r )r.r r!rX�sT)ryr�r�)r�r)r�r)r@rcrVr�rrrO�
getsockoptrr�ZSO_BROADCASTrPr,r+r*rrQ)r.r�r0r�rU�reuseport_supportedr )r.r!�&test_create_datagram_endpoint_sockoptsksH




zEBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockoptsc	s@�jj�fdd�ddd�}�jt���jj|�WdQRXdS)Ncstd�jd�S)NT)r-r@)r9r@r )r.r r!rX�szbBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_error.<locals>.<lambda>�	127.0.0.1rT)ry�
reuse_address)r�r)r@rcrFr�rV)r.r�r )r.r!�1test_create_datagram_endpoint_reuse_address_error�s
zPBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_errorc
sh�jj�fdd�ddd�}�jt��:�jj|�\}}|j��jj|j��jd|j�WdQRXdS)	Ncstd�jd�S)NT)r-r@)r9r@r )r.r r!rX�szdBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_warning.<locals>.<lambda>�	127.0.0.1rF)ryr�r7)r�r)	r@rcZassertWarns�DeprecationWarningrVrPr,r+r*)r.r�r0r�r )r.r!�3test_create_datagram_endpoint_reuse_address_warning�s
zRBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_warningcs@|`tj�|j_�jj�fdd�ddd�}�jt�jj	|�dS)Ncst�jd�S)N)r@)r9r@r )r.r r!rX�sz\BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_nosoreuseport.<locals>.<lambda>�	127.0.0.1rT)ryr�)r�r)
r�rrArrr@rcrFr�rV)r.rr�r )r.r!�+test_create_datagram_endpoint_nosoreuseport�s
zJBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_nosoreuseportcs��fdd�}||_tj�|jj_}tj��j_d�jj_t	td�}�jj
�fdd�d|d	�}�jj|�\}}z&|jd�|jj|j
|j|jd
�Wd|j�tj�j�XdS)
Ncs�jd�dS)Nz"should not have called getaddrinfo)Zfail)r�rE)r.r r!r�szYBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.getaddrinfoFr�cst�jd�S)N)r@)r9r@r )r.r r!rX�szVBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.<lambda>�1.2.3.4r)ryr�)rnr�r�)r�r)r�r)rrrArrrsr@r}rrrcrVr�rrrrPrr|)r.rrrsr�r�r�r�r )r.r!�%test_create_datagram_endpoint_ip_addr�s$




zDBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addrcCs2tj�}t�|j_|jjt|�|j|j	j
�dS)N)rrA�BlockingIOError�acceptrSr@�_accept_connectionr(rOrPr�)r.rUr r r!�test_accept_connection_retry�s
z;BaseEventLoopWithSelectorTests.test_accept_connection_retryzasyncio.base_events.loggercCs�tj�}d|j_ttjd�|j_tj�|j	_
tj�|j	_|j	jt
|�|j|jj�|j|jj�|j	j
jd�|j	jjtjtjt
|ddtj�dS)N�
zToo many open files)rrA�filenorrHraZEMFILEr�rSr@Z_remove_readerrqr�r(rQr�r�rOrPr�rZACCEPT_RETRY_DELAYr�)r.Zm_logrUr r r!� test_accept_connection_exception�sz?BaseEventLoopWithSelectorTests.test_accept_connection_exceptionc'Cstjdd��}|jjd�|}|�}|j|j�x�||fD]�}|jt��|jj|�WdQRX|jt��|jj	|�WdQRX|jt��|jj
d|�WdQRX|jt��|jj|jj�d|�WdQRX|jt��|jj
d|�WdQRXq:WdS)NcSsdS)Nr r r r r!�simple_coroutine�szLBaseEventLoopWithSelectorTests.test_call_coroutine.<locals>.simple_coroutineTr�)rRr�r@rmr�rPrFrorjr�rqr�rrf)r.r�Z	coro_funcZcoro_objrr r r!�test_call_coroutine�s "z2BaseEventLoopWithSelectorTests.test_call_coroutinecCs�dd�}tjdd��}tj|j�|jjd�d|j_|jj||j�|jj�|jj	d^}}|j
|t|�d�tj||j�|jd	�|jj�|jj	d^}}|j
|t|�d
�dS)NcSs|j�dS)N)r~)r@r r r!�stop_loop_cb	szLBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_cbcssfEdH|j�dS)N)r~)r@r r r!�stop_loop_coros
zNBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_coroTgrz4^Executing <Handle.*stop_loop_cb.*> took .* seconds$)r@z4^Executing <Task.*stop_loop_coro.*> took .* seconds$)
rRr�rDr@rmZslow_callback_durationrjrUZwarningrgr��tupler�)r.r�r�r�Zfmtr�r r r!�test_log_slow_callbackss

z6BaseEventLoopWithSelectorTests.test_log_slow_callbacks)>r9r:r;r>r%rPrVrWrXrZ�unittest�
skipUnlessrrr^rbrdrerfriror{r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rZIPV6_ENABLEDr�r�r�r�r�r�r�r�r�r�r�r�rr#r�r�r�r'r r )rEr!r>sd!

 )=	

	 /r>c@seZdZdd�ZdS)�RunningLoopTestscCs`tjdd��}tj�}tj�}z*|jtd��|j||��WdQRXWd|j�|j�XdS)NcSs|j�dS)N)rU)r@r r r!�runner)sz@RunningLoopTests.test_running_loop_within_a_loop.<locals>.runnerzwhile another loop is running)rRr�r?rnrTrVrP)r.r�r@Z
outer_loopr r r!�test_running_loop_within_a_loop(sz0RunningLoopTests.test_running_loop_within_a_loopN)r9r:r;r�r r r r!r�&sr�c@s.eZdZdd�Zejeed�d�dd��ZdS)�TestSelectorUtilscCsB|jtjtj�}|j|�tj|�|jtjtj�}|j|�dS)N)r�rr�TCP_NODELAYrOrZ_set_nodelayrQ)r.rUZoptr r r!�check_set_nodelay:s


z#TestSelectorUtils.check_set_nodelayr�zneed socket.TCP_NODELAYcCsntjtjtjtjd�}|�|j|�WdQRXtjtjtjtjd�}|�|jd�|j|�WdQRXdS)N)rnr�r�F)rrrrr�r�)r.rUr r r!�test_set_nodelayCs


z"TestSelectorUtils.test_set_nodelayN)	r9r:r;r�r�r�rrr�r r r r!r�9s	r��__main__)r	r
))�__doc__rar�r��osrr�r�rr�rrRrrrr�r�ImportErrorrZtest.support.script_helperrZtest.script_helperZasyncio.test_supportr�r��version_infor�r"r%ZTestCaser&r<rLr(r�r9r>r�r�r9r_r r r r!�<module>sd
`G