a
    	3j9                    @   sn  d Z ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl	m
Z
 ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ e
jZejd
kZdd Zdd Zdd ZG dd dejZG dd dejZ G dd dej!Z"G dd dej#Z$G dd dejZ%G dd de	jZ&G dd dejZ'G dd  d ejZ(e)d!krje	*  dS )"zTests for base_events.py    N)mock)base_events)	constants)utils)support)assert_python_ok)socket_helper)      c                   C   s   t d  d S N)asyncioZset_event_loop_policy r   r   ^/www/server/python_manager/versions/3.9.10/lib/python3.9/test/test_asyncio/test_base_events.pytearDownModule   s    r   c                  C   s`   t jtd} dD ],}tt|r2t| |tt| qt| | qt  | _t | 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   Z	MagicMocksockethasattrsetattrgetattrdelattr
test_utilsZmock_nonblocking_socketreturn_valuegetaddrinfo_is_coroutine)m_socketnamer   r   r   mock_socket_module   s    

r&   c                 C   s   t jdtd| S )Nzasyncio.base_events.socket)Znew_callable)r   patchr&   )fr   r   r   patch_socket0   s
    r)   c                   @   s(   e Zd Zdd Zdd Zedd ZdS )BaseEventTestsc              
   C   s  t j}t j}t j}t j}t j}t j}t j}| |||ddft	
dd||| | |||ddft	
dd||| | |||ddft	
dd||| | |||ddft	
dd||| | |||ddft	
dd||d | |||ddft	
dd||d | t	
dd|dd tjr| t	
dd||| | |||ddft	
dd||| | |||ddft	
dd||| | t	
dd||| | t	
d	d||| d S )
N 1.2.3.4   r-   r.   s   1.2.3.4r   )::3r.   r   r   r/   z::3%lo0)r   r   r   r   r   r   r   r   assertEqualr   _ipaddr_infoassertIsNoner   IPV6_ENABLED)selfZUNSPECINETZINET6STREAMZDGRAMTCPZUDPr   r   r   test_ipaddr_info7   sh    zBaseEventTests.test_ipaddr_infoc              
   C   s   t j}t j}t j}| |||ddftdd ||| | |||ddftdd||| | |||ddftdd||| | |||ddftdd||| | |||ddftdd||| d S )Nr+   r-   r   r-       r,   1   1)r   r   r   r   r0   r   r1   )r4   r5   r6   r7   r   r   r   test_port_parameter_typess   s.    z(BaseEventTests.test_port_parameter_typesc              	   C   s&   |` | tddtjtjtj d S )Nr-   r.   )r   r2   r   r1   r   r   r   r   r4   r$   r   r   r   test_ipaddr_info_no_inet_pton   s    z,BaseEventTests.test_ipaddr_info_no_inet_ptonN)__name__
__module____qualname__r8   r=   r)   r?   r   r   r   r   r*   5   s   <r*   c                       sl  e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,dUdV Z-  Z.S )WBaseEventLoopTestsc                    s<   t    t | _t | j_d| jjj_	| 
| j d S Nr   )supersetUpr   BaseEventLooploopr   Mock	_selectorselectr!   set_event_loopr4   	__class__r   r   rF      s
    

zBaseEventLoopTests.setUpc              	   C   s   t  }| t| jj|| | t| jj|||| | t| jj|| | t| jjg  | t| jj	 | t| jj
|| | t| jj|| | j|||||||}| t |d  W d    n1 s0    Y  d S r   )r   rI   assertRaisesNotImplementedErrorrH   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)r4   mgenr   r   r   test_not_implemented   s<    




z'BaseEventLoopTests.test_not_implementedc                 C   sn   |  | j  | j  | | j  | j  | j  | j }| t| jj | t| jj	| d S r   )
assertFalserH   Z	is_closedclose
assertTruecreate_futurerP   RuntimeErrorrun_foreverrun_until_complete)r4   r(   r   r   r   
test_close   s    



zBaseEventLoopTests.test_closec                 C   sD   t dd d| jd }| j| | | jj | || jj d S )Nc                   S   s   dS NFr   r   r   r   r   <lambda>   r:   z>BaseEventLoopTests.test__add_callback_handle.<locals>.<lambda>r   )r   HandlerH   _add_callbackrY   
_scheduledassertIn_readyr4   hr   r   r   test__add_callback_handle   s    z,BaseEventLoopTests.test__add_callback_handlec                 C   sJ   t dd d| jd }|  | j| | | jj | | jj d S )Nc                   S   s   dS ra   r   r   r   r   r   rb      r:   zHBaseEventLoopTests.test__add_callback_cancelled_handle.<locals>.<lambda>r   )r   rc   rH   cancelrd   rY   re   rg   rh   r   r   r   #test__add_callback_cancelled_handle   s
    z6BaseEventLoopTests.test__add_callback_cancelled_handlec                 C   sR   G dd dt jj}t | j_t | j_| }| j| | 	|| jj
 d S )Nc                   @   s   e Zd Zdd ZdS )zCBaseEventLoopTests.test_set_default_executor.<locals>.DummyExecutorc                 _   s   t dd S )Nz#cannot submit into a dummy executor)rQ   )r4   fnargskwargsr   r   r   submit   s    zJBaseEventLoopTests.test_set_default_executor.<locals>.DummyExecutor.submitN)r@   rA   rB   rp   r   r   r   r   DummyExecutor   s   rq   )
concurrentfuturesThreadPoolExecutorr   rI   rH   rS   rT   set_default_executorassertIs_default_executor)r4   rq   executorr   r   r   test_set_default_executor   s    z,BaseEventLoopTests.test_set_default_executorc                 C   sJ   t  }| t | j| W d    n1 s40    Y  d | j_d S r   )r   rI   assertWarnsDeprecationWarningrH   ru   rw   )r4   rx   r   r   r   .test_set_default_executor_deprecation_warnings   s    *zABaseEventLoopTests.test_set_default_executor_deprecation_warningsc                 C   sD   dd }| j |}| |j| | |tj | || j j d S )Nc                   S   s   d S r   r   r   r   r   r   cb   s    z-BaseEventLoopTests.test_call_soon.<locals>.cb)	rH   	call_soonr0   	_callbackassertIsInstancer   rc   rf   rg   r4   r}   ri   r   r   r   test_call_soon   s
    z!BaseEventLoopTests.test_call_soonc                 C   sH   | j d | td | j d W d    n1 s:0    Y  d S )NTza callable objectr.   )rH   	set_debugassertRaisesRegex	TypeErrorr~   rM   r   r   r   test_call_soon_non_callable   s    z.BaseEventLoopTests.test_call_soon_non_callablec                 C   sH   dd }| j d|}| |tj | || j j | || j j d S )Nc                   S   s   d S r   r   r   r   r   r   r}      s    z.BaseEventLoopTests.test_call_later.<locals>.cb      $@)	rH   
call_laterr   r   TimerHandlerf   re   ZassertNotInrg   r   r   r   r   test_call_later   s
    z"BaseEventLoopTests.test_call_laterc                    s\   g   fdd}t  | j_| jd|d | jd|d t| j |  ddg d S )Nc                    s     |  d S r   )append)argZcallsr   r   r}     s    z>BaseEventLoopTests.test_call_later_negative_delays.<locals>.cbab)r   rI   rH   rS   r   r    run_brieflyr0   )r4   r}   r   r   r   test_call_later_negative_delays  s    z2BaseEventLoopTests.test_call_later_negative_delaysc                    s~    fdd}t   j_d} j | } j||  j } j   j | } ||d |  |d| d S )Nc                      s    j   d S r   rH   stopr   rM   r   r   r}     s    z4BaseEventLoopTests.test_time_and_call_at.<locals>.cb皙?g?g?)	r   rI   rH   rS   timecall_atr^   ZassertGreaterEqualassertLessEqual)r4   r}   delayZwhent0Zdtr   rM   r   test_time_and_call_at  s    

z(BaseEventLoopTests.test_time_and_call_atc                 C   s   dd }| | |rd}| t| || W d    n1 sF0    Y  | t| |d| W d    n1 s~0    Y  | t|$ || d | W d    q1 s0    Y  n*|| |d| || d | d S )Nc                   S   s   d S r   r   r   r   r   r   r}   "  s    z+BaseEventLoopTests.check_thread.<locals>.cbzMNon-thread-safe operation invoked on an event loop other than the current one<   )r   r   r]   r~   r   r   r   )r4   rH   debugr}   msgr   r   r   check_thread!  s    
(*4
zBaseEventLoopTests.check_threadc                    sn   fdd d fdd	}t  j_t  j_|jd |jd |jddd |jddd d S )	Nc              
      s   |   z`|rZt }z,t|  | | W td  |  qftd  |  0 n | | W n2 ty } z| |j	| W Y d }~nd }~0 0 | |j
d  d S r   )waitr   rG   r   rL   r   rZ   	Exceptioncall_soon_threadsafeset_exception
set_result)rH   eventr   create_loopfutZloop2excrM   r   r   check_in_thread5  s    



$z=BaseEventLoopTests.test_check_thread.<locals>.check_in_threadFc                    sV   t  }|  }| |j | ||||f}t j |d}|  | | |  d S )N)targetrn   )		threadingEventr\   r~   setThreadstartr_   join)rH   r   r   r   r   rn   thread)r   r   r   test_threadI  s    
z9BaseEventLoopTests.test_check_thread.<locals>.test_threadT)r   )F)r   rI   rH   rS   rT   )r4   r   r   )r   r4   r   test_check_thread4  s    
z$BaseEventLoopTests.test_check_threadc                 C   s   t t d dd d| jd }t t d dd d| jd }|  t | j_| jj	
| | jj	
| | j  | jjjjd d }| d|  k od	k n  | | |g| jj	 | | jjj d S )
Ng      @c                   S   s   dS NTr   r   r   r   r   rb   d  r:   z3BaseEventLoopTests.test__run_once.<locals>.<lambda>r   r   c                   S   s   dS r   r   r   r   r   r   rb   f  r:   r   g      #@g      %@)r   r   r   	monotonicrH   rk   r   rI   rS   re   r   	_run_oncerJ   rK   	call_argsr[   r0   called)r4   Zh1Zh2tr   r   r   test__run_oncec  s    
 z!BaseEventLoopTests.test__run_oncec                 C   s<   | j d | | j   | j d | | j   d S )NTF)rH   r   r[   Z	get_debugrY   rM   r   r   r   test_set_debugu  s    z!BaseEventLoopTests.test_set_debugc                    s~   d  d fdd}t t d || jf| jd }t | j_| jj	| | j
  |  |  gt| jj d S )NFc                    s   d|  dd  d S )NTc                   S   s   dS r   r   r   r   r   r   rb     r:   zOBaseEventLoopTests.test__run_once_schedule_handle.<locals>.cb.<locals>.<lambda>)r~   rH   handleZ	processedr   r   r}     s    z=BaseEventLoopTests.test__run_once_schedule_handle.<locals>.cbr.   )r   r   r   r   rH   r   rI   rS   re   r   r   r[   r0   listrg   r   r   r   r   test__run_once_schedule_handle{  s    

z1BaseEventLoopTests.test__run_once_schedule_handlec                 C   s  t  | j_| dtj  k o$dk n   dd }d}| jd| d}tdD ]}| jd|}|	  qR|d7 }tdD ]}| jd	|}|	  q~| 
|| tj | | jj| | j  |d8 }| | jj| | t| jj||  tttjtj d }ttj| d}||7 }t|D ]}| jd| q0||7 }t|D ]}| jd|}|	  qV| t| jj||  | j  | t| jj| | td
d | jjD  d S )Nr   g      ?c                   S   s   d S r   r   r   r   r   r   r}     s    zEBaseEventLoopTests.test__run_once_cancelled_event_cleanup.<locals>.cbr.        i  d   c                 S   s   g | ]}|j  qS r   )Z
_cancelled).0xr   r   r   
<listcomp>  r:   zMBaseEventLoopTests.test__run_once_cancelled_event_cleanup.<locals>.<listcomp>)r   rI   rH   rS   r[   r   Z%_MIN_CANCELLED_TIMER_HANDLES_FRACTIONr   rangerk   r   Z_MIN_SCHEDULED_TIMER_HANDLESr0   Z_timer_cancelled_countr   lenre   intmathceilmaxall)r4   r}   Znot_cancelled_countZcancelled_countr   ri   Zadd_cancel_countZadd_not_cancel_countr   r   r   &test__run_once_cancelled_event_cleanup  sd    




z9BaseEventLoopTests.test__run_once_cancelled_event_cleanupc                 C   s   |  t| jjd d S )NZblah)rP   r   rH   r_   rM   r   r   r   "test_run_until_complete_type_error  s    z5BaseEventLoopTests.test_run_until_complete_type_errorc                 C   s2   | j  }|  }| |j | t|j| d S r   )rH   r\   Znew_test_loop
addCleanuprZ   rP   
ValueErrorr_   )r4   taskZ
other_loopr   r   r   test_run_until_complete_loop  s    
z/BaseEventLoopTests.test_run_until_complete_loopc                    s   G dd dt  dd } fdd}t | j_| j| |    | j|d W d    n1 sl0    Y  | j|d d S )	Nc                   @   s   e Zd ZdS )z]BaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.ShowStopperNr@   rA   rB   r   r   r   r   ShowStopper  s   r   c                    s   t | I d H  d S r   r   sleep)r   r   r   r   foo  s    zUBaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.fooc                      s    d S r   r   r   r   r   r   throw  s    zWBaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.throwr   g?)
SystemExitr   rI   rH   rS   r~   rP   r_   )r4   r   r   r   r   r   5test_run_until_complete_loop_orphan_future_close_loop  s    .zHBaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loopc                 C   s   t jddg}| t| jj| jjtj | t| jj| jjtj| | t| jj| jjtjt jd | jt| jj| jjtjg|R ddi | jt| jj| jjtjg|R ddi | jt| jj| jjtjg|R ddi d S )	N-cpass{   universal_newlinesTshellbufsize   )	sys
executablerP   r   rH   r_   Zsubprocess_execr   SubprocessProtocol)r4   rn   r   r   r   !test_subprocess_exec_invalid_args  sJ    
z4BaseEventLoopTests.test_subprocess_exec_invalid_argsc              	   C   s   |  t| jj| jjtjd |  t| jj| jjtjtjddg | j t| jj| jjtjddd | j t| jj| jjtjddd | j t| jj| jjtjddd	 d S )
Nr   r   r   zexit 0T)r   )r   r   )r   )	rP   r   rH   r_   Zsubprocess_shellr   r   r   r   rM   r   r   r   "test_subprocess_shell_invalid_args  s(    z5BaseEventLoopTests.test_subprocess_shell_invalid_argsc                    s  t   j_dd }t d`} j } j|| | fdd  j  |j	j
tdtttfd W d    n1 s0    Y  t db} j } jd|| | fd	d  j  |j	j
tdtttfd W d    n1 s0    Y  d S )
Nc                 S   s   |  d dd  d S )NTr.   r   )r   r   r   r   r   
zero_error,  s    
zHBaseEventLoopTests.test_default_exc_handler_callback.<locals>.zero_errorasyncio.base_events.loggerc                    s
    j  S r   r   r   rM   r   r   rb   4  r:   zFBaseEventLoopTests.test_default_exc_handler_callback.<locals>.<lambda>Exception in callback.*zeroexc_info{Gz?c                    s
    j  S r   r   r   rM   r   r   rb   >  r:   )r   rI   rH   rS   r'   r\   r~   add_done_callbackr^   errorassert_called_withr    MockPatternZeroDivisionErrorMOCK_ANYr   )r4   r   logr   r   rM   r   !test_default_exc_handler_callback)  s(    

$

z4BaseEventLoopTests.test_default_exc_handler_callbackc                    s   t   j_dd }t d}tj|  jd}| fdd  j  d }t	
  tr||jjtdtttfd n|jjtd	d
d W d    n1 s0    Y  d S )Nc                      s   t dI d H  dd  d S )Nr   r.   r   r   r   r   r   r   zero_error_coroG  s    zIBaseEventLoopTests.test_default_exc_handler_coro.<locals>.zero_error_coror   r   c                     s
    j  S r   r   rn   rM   r   r   rb   N  r:   zBBaseEventLoopTests.test_default_exc_handler_coro.<locals>.<lambda>z.*exception was never retrievedr   z(.*exception was never retrieved.*ZeroDivF)r   rI   rH   rS   r'   r   ensure_futurer   r^   r   
gc_collectPY34r   r   r    r   r   r   )r4   r   r   r   r   rM   r   test_default_exc_handler_coroD  s&    
z0BaseEventLoopTests.test_default_exc_handler_coroc                 C   s<   |  td | jd W d    n1 s.0    Y  d S )NzA callable object or Nonespam)r   r   rH   set_exception_handlerrM   r   r   r   test_set_exc_handler_invalid_  s    z/BaseEventLoopTests.test_set_exc_handler_invalidc                    s   dd  fdd} j d t  j _  j   t } j |   j  | | }|	 j t
td||jd |   j d  td2}|  |jj	td	tt
t
fd
 W d    n1 s0    Y  d S )Nc                   S   s   dd  d S Nr.   r   r   r   r   r   r   r   d  s    zBBaseEventLoopTests.test_set_exc_handler_custom.<locals>.zero_errorc                     s    j }  j   | S r   rH   r~   r   )r   r4   r   r   r   run_loopg  s    
z@BaseEventLoopTests.test_set_exc_handler_custom.<locals>.run_loopTz!Exception in callback.*zero_error)	exceptionmessager   Zsource_tracebackr   r   r   )rH   r   r   rI   rS   r2   Zget_exception_handlerr   rv   r   r   r    r   Z_source_traceback
reset_mockr'   r   r   )r4   r  Zmock_handlerr   r   r   r  r   test_set_exc_handler_customc  s8    $z.BaseEventLoopTests.test_set_exc_handler_customc                    s|    fdd}dd }t   j_ j| t d2}|  |jjt	dt
ttfd W d    n1 sn0    Y  d S )Nc                     s"   dd }  j |   j   d S )Nc                   S   s   dd  d S r  r   r   r   r   r   r     s    zTBaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loop.<locals>.zero_errorr  r   rM   r   r   r    s    z@BaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loopc                 S   s   t dd S Nr   )AttributeErrorrH   contextr   r   r   handler  s    z?BaseEventLoopTests.test_set_exc_handler_broken.<locals>.handlerr   z$Unhandled error in exception handlerr   )r   rI   rH   rS   r   r'   r   r   r    r   r  r   )r4   r  r  r   r   rM   r   test_set_exc_handler_broken  s    z.BaseEventLoopTests.test_set_exc_handler_brokenc                    s  d  G  fdddt j}| | j t fdd}td&}|  |jj	ddd W d    n1 sx0    Y  d	d
 }d  
| tdP}|  |jj	tddd | d  | t d d t W d    n1 s0    Y  d S )Nc                       s(   e Zd Ze Ze Z fddZdS )z@BaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loopc                    s   | t dd S r  r   )r4   r  _contextr   r   default_exception_handler  s    zZBaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loop.default_exception_handlerN)r@   rA   rB   r   rI   rJ   rS   r  r   r  r   r   Loop  s   r  c                     s   dd }   |     d S )Nc                   S   s   dd  d S r  r   r   r   r   r   r     s    zXBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loop.<locals>.zero_error)r~   r   r
  r   r   r   r    s    
zDBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loopr   z&Exception in default exception handlerTr   c                 S   s   t dd S )NZhamr  r  r   r   r   custom_handler  s    zJBaseEventLoopTests.test_default_exc_handler_broken.<locals>.custom_handlerz9Exception in default exception.*while handling.*in customr  r  )r   rG   r   rZ   r   rL   r   r'   r   r   r   r    r   rf   rv   typer   )r4   r  r  r   r  r   )r  rH   r   test_default_exc_handler_broken  s2    
$
z2BaseEventLoopTests.test_default_exc_handler_brokenc                 C   sL   |  td | jd W d    n1 s.0    Y  | | j  d S )Nz'task factory must be a callable or Noner.   )r   r   rH   set_task_factoryr2   get_task_factoryrM   r   r   r   test_set_task_factory_invalid  s
    *z0BaseEventLoopTests.test_set_task_factory_invalidc                    s   t  | j_G dd dtj dd } fdd}| | j  | j| | 	| j | | j
| }| t|  | j| | jd  | | j  | j
| }| t|tj | t|  | j| d S )Nc                   @   s   e Zd ZdS )z8BaseEventLoopTests.test_set_task_factory.<locals>.MyTaskNr   r   r   r   r   MyTask  s   r  c                      s   d S r   r   r   r   r   r   coro  s    z6BaseEventLoopTests.test_set_task_factory.<locals>.coroc                    s    || dS Nr   r   rH   r  r  r   r   rb     r:   z:BaseEventLoopTests.test_set_task_factory.<locals>.<lambda>)r   rI   rH   rS   r   Taskr2   r  r  rv   create_taskr[   
isinstancer_   rY   )r4   r  factoryr   r   r   r   test_set_task_factory  s     z(BaseEventLoopTests.test_set_task_factoryc                 C   s   d d}tdd|\}}}| | d td|ddd\}}}| | d td|ddd\}}}| | d	 tdd|dd
\}}}| | d tdddd|\}}}| | d	 d S )N
)zimport asynciozloop = asyncio.get_event_loop()zprint(loop.get_debug())z-Er   s   Falser+   )PYTHONASYNCIODEBUGZPYTHONDEVMODEr;   s   True)r'  z-Xdev)r   r   r0   rstrip)r4   codestsstdoutstderrr   r   r   test_env_var_debug  s*    

z%BaseEventLoopTests.test_env_var_debugc                    st   G dd dt j dd }G  fdddtj}| |  | }t j|d}| |  d|_|  d S )	Nc                   @   s   e Zd ZdS )z3BaseEventLoopTests.test_create_task.<locals>.MyTaskNr   r   r   r   r   r    s   r  c                      s   d S r   r   r   r   r   r   test  s    z1BaseEventLoopTests.test_create_task.<locals>.testc                       s   e Zd Z fddZdS )z6BaseEventLoopTests.test_create_task.<locals>.EventLoopc                    s    |dS r  r   r4   r  r  rH   r   r   r"    s    zBBaseEventLoopTests.test_create_task.<locals>.EventLoop.create_taskN)r@   rA   rB   r"  r   r1  r   r   	EventLoop  s   r2  r   F)	r   r!  r   rG   rL   r   r   Z_log_destroy_pendingrZ   )r4   r/  r2  r  r   r   r1  r   test_create_task  s    
z#BaseEventLoopTests.test_create_taskc              	   C   s`   dd }t  }|j| dd}z&| | d W || |  n|| |  0 d S )Nc                      s   d S r   r   r   r   r   r   r/  $  s    zLBaseEventLoopTests.test_create_named_task_with_default_factory.<locals>.test	test_taskr%   )r   new_event_loopr"  r0   get_namer_   rZ   )r4   r/  rH   r   r   r   r   +test_create_named_task_with_default_factory#  s    


z>BaseEventLoopTests.test_create_named_task_with_default_factoryc              	   C   sr   dd }dd }t  }|| |j| dd}z&| | d W || |  n|| |  0 d S )Nc                 S   s   t j|| dS r  )r   r!  r  r   r   r   task_factory0  s    zSBaseEventLoopTests.test_create_named_task_with_custom_factory.<locals>.task_factoryc                      s   d S r   r   r   r   r   r   r/  3  s    zKBaseEventLoopTests.test_create_named_task_with_custom_factory.<locals>.testr4  r5  )r   r6  r  r"  r0   r7  r_   rZ   )r4   r9  r/  rH   r   r   r   r   *test_create_named_task_with_custom_factory/  s    



z=BaseEventLoopTests.test_create_named_task_with_custom_factoryc                 C   sl   dd }t  | j_t  | j_z| j|  W n tyD   Y n0 | j  t	  | 
| jjj d S )Nc                      s   t d S r   KeyboardInterruptr   r   r   r   raise_keyboard_interruptC  s    zXBaseEventLoopTests.test_run_forever_keyboard_interrupt.<locals>.raise_keyboard_interrupt)r   rI   rH   rS   Zcall_exception_handlerr_   r<  rZ   r   r   rY   r   r4   r=  r   r   r   #test_run_forever_keyboard_interrupt?  s    
z6BaseEventLoopTests.test_run_forever_keyboard_interruptc                    s   dd }t  j_zj|  W n ty8   Y n0  fdd d _zj  j  W n tyz   Y n0 	 j d S )Nc                      s   t d S r   r;  r   r   r   r   r=  U  s    zZBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.raise_keyboard_interruptc                      s   j   d _d S r   )rH   r   r   r   funcr4   r   r   rA  _  s    
zFBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.funcF)
r   rI   rH   rS   r_   r<  r   r~   r^   r[   r>  r   r@  r   %test_run_until_complete_baseexceptionR  s    z8BaseEventLoopTests.test_run_until_complete_baseexceptionc              	      s   t  d d fdd} fddfdd|j_fjjj_tdd	D ]X}d
| 6 jjj	 j
   d W d    q^1 s0    Y  q^d S )Nr   c                    s   | v rj  d S r   rH   r~   )Z
event_list)do_eventdoerevent_sentinelr4   r   r   proc_eventsq  s    zZBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.proc_eventsc                      s    d7  j  d S Nr.   rC  r   )	callcountclear_selectorr4   r   r   rD  v  s    zWBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.do_eventc                      s       djjj_d S rD   )rk   rH   rJ   rK   r!   r   )rE  r4   r   r   rJ  {  s    z]BaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.clear_selectorr.   r	   z	Loop %d/2)objectrH   rS   rJ   rK   r!   r   ZsubTestr~   r   r^   r0   )r4   rG  ir   )rI  rJ  rD  rE  rF  r4   r   2test_single_selecter_event_callback_after_stoppingj  s    
zEBaseEventLoopTests.test_single_selecter_event_callback_after_stoppingc                    sD   d  fdd}t  | j_| j| t| j |  d d S )Nr   c                      s    d7  d S rH  r   r   countr   r   callback  s    z2BaseEventLoopTests.test_run_once.<locals>.callbackr.   )r   rI   rH   rS   r~   r    Zrun_oncer0   )r4   rP  r   rN  r   test_run_once  s    z BaseEventLoopTests.test_run_oncec                 C   s4   t  | j_| j  | j  | jjjd d S Nr   )	r   rI   rH   rS   r   r^   rJ   rK   Zassert_called_once_withrM   r   r   r   test_run_forever_pre_stopped  s    

z/BaseEventLoopTests.test_run_forever_pre_stoppedc                    sF   ddddfdd}| }|    fddt  S )NF)startedstopped	finalizedc               	     s4   d d< zdD ]
} | V  qW d d< n
d d< 0 d S )NTrT  )ZZEROZONEZTWOTHREEZFOURrV  r   item)statusr   r   agen  s
    
z;BaseEventLoopTests.leave_unfinalized_asyncgen.<locals>.agenc                     sL   z   I d H } W n ty&   Y d S 0 | dkr<dd< d S t  d S )NrW  TrU  )	__anext__StopAsyncIterationr   r"  rX  Zaiiter_onerZ  r   r   r_    s    z?BaseEventLoopTests.leave_unfinalized_asyncgen.<locals>.iter_one)	__aiter__r   r"  )r4   r[  Zagr   r^  r   leave_unfinalized_asyncgen  s    
z-BaseEventLoopTests.leave_unfinalized_asyncgenc                 C   s   t  | j_t  | j_t  | j|  }|d sHt	
| j q2| |d  | |d  | |d  t  t	
| j | |d  W d    n1 s0    Y  d S )NrU  rT  rV  )r   rI   rH   rS   rT   r   
disable_gcr_   ra  r    r   r[   rY   r   r4   rZ  r   r   r    test_asyncgen_finalization_by_gc  s    
z3BaseEventLoopTests.test_asyncgen_finalization_by_gcc                 C   s   t  | j_t  | j_| jd t  | j| 	 }|d sTt
| j q>| |d  | |d  | |d  | j| jd tj t
| j | |d  W d    n1 s0    Y  d S )NTrU  rT  rV  )r   rI   rH   rS   rT   r   r   rb  r_   ra  r    r   r[   rY   run_in_executorr   rc  r   r   r   0test_asyncgen_finalization_by_gc_in_other_thread  s    
zCBaseEventLoopTests.test_asyncgen_finalization_by_gc_in_other_thread)/r@   rA   rB   rF   rX   r`   rj   rl   ry   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  r  r  r  r%  r.  r3  r8  r:  r?  rB  rM  rQ  rS  ra  rd  rf  __classcell__r   r   rN   r   rC      sV   			/L$0"rC   c                   @   s:   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdS )MyProtoNFc                 C   s"   d| _ d| _|rt  | _d S NZINITIALr   )statenbytesr   Zget_running_loopr\   done)r4   r\   r   r   r   __init__  s    zMyProto.__init__c                 C   s   || _ d| _|d d S )NZ	CONNECTEDs%   GET / HTTP/1.0
Host: example.com

)	transportrj  writer4   rn  r   r   r   connection_made  s    zMyProto.connection_madec                 C   s   |  j t|7  _ d S r   rk  r   r4   datar   r   r   data_received  s    zMyProto.data_receivedc                 C   s
   d| _ d S )NZEOF)rj  rM   r   r   r   eof_received  s    zMyProto.eof_receivedc                 C   s   d| _ | jr| jd  d S NCLOSEDrj  rl  r   r4   r   r   r   r   connection_lost  s    zMyProto.connection_lost)F)	r@   rA   rB   rl  rm  rq  ru  rv  r{  r   r   r   r   rh    s   
rh  c                   @   s:   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdS )MyDatagramProtoNFc                 C   s   d| _ d| _|r| | _d S ri  )rj  rk  r\   rl  )r4   r\   rH   r   r   r   rm    s    zMyDatagramProto.__init__c                 C   s   || _ d| _d S )NZINITIALIZED)rn  rj  rp  r   r   r   rq    s    zMyDatagramProto.connection_madec                 C   s   |  j t|7  _ d S r   rr  )r4   rt  addrr   r   r   datagram_received  s    z!MyDatagramProto.datagram_receivedc                 C   s   d S r   r   rz  r   r   r   error_received  s    zMyDatagramProto.error_receivedc                 C   s   d| _ | jr| jd  d S rw  ry  rz  r   r   r   r{    s    zMyDatagramProto.connection_lost)FN)	r@   rA   rB   rl  rm  rq  r~  r  r{  r   r   r   r   r|    s   
r|  c                       s  e Zd Z fddZeddd Zedd Zedd	 Z	d
d Z
dd Zdd Zdd Zeeedddd Zeejddd Zdd Zdd Zdd Zdd  Zd!d" Zed#d$ Zd%d& Zeejdeej d'd(ed)d* Z!ed+d, Z"ed-d. Z#ed/d0 Z$d1d2 Z%ed3d4 Z&d5d6 Z'd7d8 Z(d9d: Z)d;d< Z*d=d> Z+d?d@ Z,dAdB Z-dCdD Z.edEdF Z/edGdH Z0edIdJ Z1edKdL Z2dMdN Z3dOdP Z4dQdR Z5edSdT Z6eejdUdVdW Z7edXdY Z8dZd[ Z9ed\d] Z:d^d_ Z;eeed`dadbdc Z<ej=ddde Z>dfdg Z?dhdi Z@djdk ZAdldm ZBedndo ZCedpdq ZDdrds ZEedtdudv ZFdwdx ZGedtdydz ZH  ZIS ){BaseEventLoopWithSelectorTestsc                    s$   t    t | _| | j d S r   )rE   rF   r   ZSelectorEventLooprH   rL   rM   rN   r   r   rF      s    

z$BaseEventLoopWithSelectorTests.setUpzsocket.getnameinfoc                 C   s.   dd |_ | j| jd}| |d d S )Nc                  W   s   dS )N*   r   r   r   r   r   rb   '  r:   zABaseEventLoopWithSelectorTests.test_getnameinfo.<locals>.<lambda>)abcr   r  )side_effectrH   r_   getnameinfor0   )r4   Zm_gairr   r   r   test_getnameinfo%  s    
z/BaseEventLoopWithSelectorTests.test_getnameinfoc                    s   G dd dt j}dd fdd}ddd	g  fd
d}||_|j_j|dd}t}j| W d    n1 s0    Y  	t
|jd d S )Nc                   @   s   e Zd ZdS )zVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.MyProtoNr   r   r   r   r   rh  .  s   rh  c                     s   ddgS Nr   r.      r+   )z107.6.106.82P   r   rn   kwr   r   r   r"   1  s    zZBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfoc                     s   j  | i |S r   rH   r"  rn   kwdsr"   r4   r   r   getaddrinfo_task5  s    z_BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfo_taskr   Zerr1Zerr2c                     s   d7 t   d S rH  )OSErrorr  )errorsidxr   r   _socket;  s    zVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>._socketexample.comr  zMultiple exceptions: err1, err2)r   Protocolr   rH   r"   create_connectionrP   r  r_   r0   strr  )r4   r$   rh  r  r  r  cmr   )r  r"   r  r4   r   &test_create_connection_multiple_errors+  s    *zEBaseEventLoopWithSelectorTests.test_create_connection_multiple_errorsc              	      s   t  }||j_ fdd}| j_t jj jdtj	df  j
tdd} tj	  j| W d    n1 sz0    Y   |jj W d    n1 s0    Y  d S )Nc                     s,    j  }tjtjdddf}||g |S )Nr   r+   )	127.0.0.1r  )rH   r\   r   r   r   r   )rn   r  r   r}  rM   r   r   r"   P  s    
zRBaseEventLoopWithSelectorTests.test_create_connection_timeout.<locals>.getaddrinfosock_connect)r  r  r  )r   rI   r   r!   rH   r"   r'   rK  r   TimeoutErrorr  rh  rP   r_   r[   rZ   r   )r4   r$   sockr"   r  r   rM   r   test_create_connection_timeoutJ  s    *z=BaseEventLoopWithSelectorTests.test_create_connection_timeoutc                 C   s,   | j jtddt d}| t| j j| d S )Nr  r  r  )rH   r  rh  rK  rP   r   r_   r0  r   r   r   %test_create_connection_host_port_sock_  s    
zDBaseEventLoopWithSelectorTests.test_create_connection_host_port_sockc              	   C   s   t  t jt j}|X | jjt|d}| td | j| W d    n1 sT0    Y  W d    n1 sr0    Y  d S Nr  zA Stream Socket was expected)	r   r   r   rH   r  rh  r   r   r_   r4   r  r  r   r   r   !test_create_connection_wrong_sockd  s    z@BaseEventLoopWithSelectorTests.test_create_connection_wrong_sockc              	   C   s   t  t jt j}|X | jjt|d}| td | j| W d    n1 sT0    Y  W d    n1 sr0    Y  d S r  )	r   r   r   rH   create_serverrh  r   r   r_   r  r   r   r   test_create_server_wrong_sockl  s    z<BaseEventLoopWithSelectorTests.test_create_server_wrong_sockc                 C   sP   | j jtdddd}| td | j | W d    n1 sB0    Y  d S Nr  r  r.   )ssl_handshake_timeoutz1ssl_handshake_timeout is only meaningful with ssl)rH   r  rh  r   r   r_   r0  r   r   r   /test_create_server_ssl_timeout_for_plain_sockett  s    zNBaseEventLoopWithSelectorTests.test_create_server_ssl_timeout_for_plain_socketSOCK_NONBLOCKz$no socket.SOCK_NONBLOCK (linux only)c                 C   sv   t  t jt jt jB }|H | jjdd |d}| j|}|  | j|  W d    n1 sh0    Y  d S )Nc                   S   s   d S r   r   r   r   r   r   rb     r:   zRBaseEventLoopWithSelectorTests.test_create_server_stream_bittype.<locals>.<lambda>r  )	r   r   r   r  rH   r  r_   rZ   wait_closed)r4   r  r  srvr   r   r   !test_create_server_stream_bittype|  s    z@BaseEventLoopWithSelectorTests.test_create_server_stream_bittypezno IPv6 supportc              
      sl    fdd}z j |  W nH tyf } z0ttdrP|jtjkrP d n W Y d }~n
d }~0 0 d S )Nc                     s     t. tjdd dd jdI d H } W d    n1 s>0    Y  z, t| jd W |   | 	 I d H  n|   | 	 I d H  0 d S )Nc                   S   s   d S r   r   r   r   r   r   rb     r:   zVBaseEventLoopWithSelectorTests.test_create_server_ipv6.<locals>.main.<locals>.<lambda>::1r   r   )
rz   r{   r   Zstart_serverrH   ZassertGreaterr   socketsrZ   r  )r  rM   r   r   main  s    *zDBaseEventLoopWithSelectorTests.test_create_server_ipv6.<locals>.mainEADDRNOTAVAILzfailed to bind to ::1)rH   r_   r  r   errnor  ZskipTest)r4   r  exr   rM   r   test_create_server_ipv6  s    


z6BaseEventLoopWithSelectorTests.test_create_server_ipv6c              	   C   s|   t  t j}|X | jjt|d}| td | j| W d    n1 sP0    Y  W d    n1 sn0    Y  d S )Nr  zA UDP Socket was expected)r   r   rH   create_datagram_endpointrh  r   r   r_   r  r   r   r   (test_create_datagram_endpoint_wrong_sock  s    zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_wrong_sockc                 C   s"   | j t}| t| j j| d S r   rH   r  rh  rP   r   r_   r0  r   r   r   (test_create_connection_no_host_port_sock  s    zGBaseEventLoopWithSelectorTests.test_create_connection_no_host_port_sockc                    sD   dd   fdd}|j _j tdd}tj j| d S )Nc                     s   g S r   r   r  r   r   r   r"     s    zYBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfoc                     s   j  | i |S r   r  r  r  r   r   r    s    z^BaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfo_taskr  r  )rH   r"   r  rh  rP   r  r_   r4   r  r  r   r  r   %test_create_connection_no_getaddrinfo  s    
zDBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfoc                    sZ   dd   fdd}|j _t j _tj j_j tdd}	tj j
| d S )Nc                     s   dgS r  r   r  r   r   r   r"     s    zVBaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfoc                     s   j  | i |S r   r  r  r  r   r   r    s    z[BaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfo_taskr  r  )rH   r"   r   rI   r  r  r  r  rh  rP   r_   r  r   r  r   "test_create_connection_connect_err  s    

zABaseEventLoopWithSelectorTests.test_create_connection_connect_errc                    s   dd   fdd}|j _t j _tj j_j jtddt	j
d}t j | W d    n1 sv0    Y  d S )Nc                     s   ddgS N)r   r.   r  r+   )0.0.0.1r  )r   r.   r  r+   )z0.0.0.2r  r   r  r   r   r   r"     s    zSBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfoc                     s   j  | i |S r   r  r  r  r   r   r    s    zXBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfo_taskr  r  family)rH   r"   r   rI   r  r  r  r  rh  r   r   rP   r_   r  r   r  r   test_create_connection_multiple  s    

z>BaseEventLoopWithSelectorTests.test_create_connection_multiplec                    s   dd }||j j_dd   fdd}|j_t j_tdjj_	jj
tdd	t jd
d}t}j| W d    n1 s0    Y  t|jd |j jjj d S )Nc                 S   s"   | d dkrt d}d|_|d S )Nr   r  Err)r  strerror)r}  errr   r   r   bind  s    z^BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.bindc                     s   ddgS r  r   r  r   r   r   r"     s    zeBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfoc                     s   j  | i |S r   r  r  r  r   r   r    s    zjBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfo_taskZErr2r  r  Ni  r  
local_addrzMultiple exceptions: )r   r!   r  rH   r"   r   rI   r  r  r  r  rh  r   rP   r_   r[   r  r  
startswithrZ   r   )r4   r$   r  r  r  r  r   r  r   1test_create_connection_multiple_errors_local_addr  s    

*zPBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addrc              	   C   s  |s|` tj|_|jj}t | j_d| jj_t | j_	d| jj	_| j
tjdd}| j|\}}zT|jd |jj\}}| |d |j | |d |j W |  t| j n|  t| j 0 tjrtj|_| j
tjdd}| j|\}}z~|jjd \}	|	d d	 \}
}| |
d
 | |d |jj\}}| |d |j | |d |j W |  t| j n|  t| j 0 d S )NFr-   r  r-   r  r  r  r  r   r   z	::(0\.)*1)r   r   r"   r!   r   rI   rH   _add_readerr#   _add_writerr  r   r  r_   connectr   r   r0   r   r   rZ   r    r   r   r3   r   r  assertRegex)r4   r$   Zallow_inet_ptonr  r  r   p_ro   addresshostportr   r   r   _test_create_connection_ip_addr  sF    

z>BaseEventLoopWithSelectorTests._test_create_connection_ip_addrZaixzDbpo-25545: IPv6 scope id and getaddrinfo() behave differently on AIXc              	   C   s   t j|_|j j}t j|_t | j_d| jj_	t | j_
d| jj
_	| jtjdd}| j|\}}zT|jd |j j\}}| |d |j | |d |j W |  t| j n|  t| j 0 d S )NFz	fe80::1%1r  )zfe80::1r  r   r.   r  r  )r   r"   r!   r   r  r   rI   rH   r  r#   r  r  r   r  r_   r  r   r   r0   r   rZ   r    r   )r4   r$   r  r  r   r  r  ro   r   r   r   !test_create_connection_ipv6_scope  s$    

z@BaseEventLoopWithSelectorTests.test_create_connection_ipv6_scopec                 C   s   |  |d d S r   r  r>   r   r   r   test_create_connection_ip_addr7  s    z=BaseEventLoopWithSelectorTests.test_create_connection_ip_addrc                 C   s   |  |d d S ra   r  r>   r   r   r   #test_create_connection_no_inet_pton;  s    zBBaseEventLoopWithSelectorTests.test_create_connection_no_inet_ptonc           
   
   C   s4  t j|_|j j}t | j_d| jj_t | j_d| jj_dD ]\}}| j	t
jd|}| j|\}}zX|jd|f |j j\}}	| |	d |j | |	d |j W |  t| j q@|  t| j 0 q@dD ]N}| j	t
jd|}| t | j| W d    q1 s$0    Y  qd S )NF))httpr  )s   httpr  r  r  r  )Znonsenses   nonsense)r   r"   r!   r   rI   rH   r  r#   r  r  r   r  r_   r  r   r   r0   r   r   rZ   r    r   rP   r  )
r4   r$   r  Zservicer  r  r   r  r  ro   r   r   r   #test_create_connection_service_name?  s4    



zBBaseEventLoopWithSelectorTests.test_create_connection_service_namec                    sL   dd   fdd}|j _j jtddtjdd}tj j| d S )	Nc                    s   | dkrddgS g S d S )Nr  r  r   )r  rn   r  r   r   r   r"   _  s
    zXBaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfoc                     s   j  | i |S r   r  r  r  r   r   r  f  s    z]BaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfo_taskr  r  r  r  )	rH   r"   r  rh  r   r   rP   r  r_   r  r   r  r   $test_create_connection_no_local_addr^  s    

zCBaseEventLoopWithSelectorTests.test_create_connection_no_local_addrc                    s<   d  fdd}||_ | }| j| }| j| d S )N)z00:01:02:03:04:05r.   c                    s   dddd dffgS )Ni  r.   r+   r   )r  r  rn   r  r}  r   r   r"   v  s    zTBaseEventLoopWithSelectorTests.test_create_connection_bluetooth.<locals>.getaddrinfo)r"   r   rH   r  r_   )r4   r$   r"   r  r  r   r  r    test_create_connection_bluetoothp  s    z?BaseEventLoopWithSelectorTests.test_create_connection_bluetoothc              	      s  t  j_fdd}|jj_t  j_j jj_jjjd  t  j_	G dd d  fdd}|jj	_t j
}t }jj	  jjtddd	|d
}j|\}}|  jj	j||||dd|d jj	  jjtddd	d|d}j|\}}|  jj	j||||dd|d jj	  jjtddd	d|d}j|\}}|  jj	j||||dd|d d S )Nc                     s*    j  }|tjtjtjddfg |S )Nr+   r  )rH   r\   r   r   r   r   SOL_TCP)rn   r  r(   rM   r   r   mock_getaddrinfo  s
    
zkBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>.mock_getaddrinfoc                   @   s    e Zd ZdZdd Zdd ZdS )zqBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMockNc                 S   s   t  S r   )r   rI   )r4   keyr   r   r   get_extra_info  s    zBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.get_extra_infoc                 S   s   | j   d S r   )_sockrZ   rM   r   r   r   rZ     s    zwBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.close)r@   rA   rB   r  r  rZ   r   r   r   r   _SelectorTransportMock  s   r  c                    s   | d    }| |_|S r   )r   r  )r  protocolZ
sslcontextwaiterr  rn  )r  r   r   mock_make_ssl_transport  s    
zrBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>.mock_make_ssl_transport
python.orgr  T)sslr  F)Zserver_sideserver_hostnamer  zperl.com)r  r  r  r+   )r   rI   rH   r"   r  r  r\   r!   r   rR   ANYrK  r  r  rh  r_   rZ   r   )r4   r  r  r  Zhandshake_timeoutr  rn  r  r   )r  r4   r   2test_create_connection_ssl_server_hostname_default  sj    
	
zQBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_defaultc                 C   sP   | j jtdddd}| t| j j| | j jtdddd}| t| j j| d S )Nr  r  r+   )r  r  r0  r   r   r   4test_create_connection_no_ssl_server_hostname_errors  s    zSBaseEventLoopWithSelectorTests.test_create_connection_no_ssl_server_hostname_errorsc                 C   s   | j jtdddd}| t| j j| | j jtd ddd}| t| j j| t }| j jtd d d|d}| |j | t| j j| d S )Nr+   r  T)r  )r  r  )	rH   r  rh  rP   r   r_   r   r   rZ   )r4   r  r  r   r   r   1test_create_connection_ssl_server_hostname_errors  s    zPBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_errorsc                 C   sP   | j jtdddd}| td | j | W d    n1 sB0    Y  d S r  )rH   r  rh  r   r   r_   r0  r   r   r   3test_create_connection_ssl_timeout_for_plain_socket  s    zRBaseEventLoopWithSelectorTests.test_create_connection_ssl_timeout_for_plain_socketc                    sX   t  fdd  fdd}|j_jtdd}tjj|  d S )Nc                     s   | d  g S rR  r   r  )r  r   r   r"     s    zQBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfoc                     s   j  | i |S r   r  r  r  r   r   r    s    zVBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfo_taskr+   r   )	rK  rH   r"   r  rh  rP   r  r_   r2   )r4   r  r   r   )r"   r  r4   r   test_create_server_empty_host  s    z<BaseEventLoopWithSelectorTests.test_create_server_empty_hostc                 C   s,   | j jtddt d}| t| j j| d S )N0.0.0.0r   r  )rH   r  rh  rK  rP   r   r_   r4   r   r   r   r   !test_create_server_host_port_sock  s    
z@BaseEventLoopWithSelectorTests.test_create_server_host_port_sockc                 C   s"   | j t}| t| j j| d S r   )rH   r  rh  rP   r   r_   r  r   r   r   $test_create_server_no_host_port_sock  s    zCBaseEventLoopWithSelectorTests.test_create_server_no_host_port_sockc                 C   sN   t   }| j_| j |_|jd  | jtdd}| 	t
| jj| d S )Nr  r   )r   rI   rH   r"   r\   r!   r   r  rh  rP   r  r_   )r4   r"   r(   r   r   r   !test_create_server_no_getaddrinfo  s
    z@BaseEventLoopWithSelectorTests.test_create_server_no_getaddrinfoc                 C   sB   t j|_|`t |j _| jjtdddd}| 	t
| jj| d S )Nr  r   T
reuse_port)r   r"   SO_REUSEPORTr   rI   r!   rH   r  rh  rP   r   r_   r4   r$   r(   r   r   r    test_create_server_nosoreuseport  s    z?BaseEventLoopWithSelectorTests.test_create_server_nosoreuseportc                 C   sD   t j|_t |j _d|_| jjtdddd}| 	t
| jj| d S )Nr   r  r   Tr  )r   r"   r   rI   r!   r  rH   r  rh  rP   r   r_   r  r   r   r   +test_create_server_soreuseport_only_defined  s    zJBaseEventLoopWithSelectorTests.test_create_server_soreuseport_only_definedc                 C   sn   G dd dt }dg|j_d|j_t  }|j_||j_| j	
tdd}| t | j	j| | |jj d S )Nc                   @   s   e Zd ZdZdS )zHBaseEventLoopWithSelectorTests.test_create_server_cant_bind.<locals>.Errr   N)r@   rA   rB   r  r   r   r   r   r     s   r  )r   r.   r  r+   )r  it'  Fr  r   )r  r"   r!   r#   r   rI   r   r  r  rH   r  rh  rP   r_   r[   rZ   r   r4   r$   r  Zm_sockr   r   r   r   test_create_server_cant_bind  s    z;BaseEventLoopWithSelectorTests.test_create_server_cant_bindc                 C   s6   g |j _d|j _| jjtdd}| t| jj| d S )NF)	localhostr   r  )	r"   r!   r#   rH   r  r|  rP   r  r_   r4   r$   r  r   r   r   )test_create_datagram_endpoint_no_addrinfo-  s    
zHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_addrinfoc                 C   sH   | j jtdd}| t| j j| | j jtdd}| t| j j| d S )Nr  r  )r  r.   r   r	   )rH   r  r|  rP   r   r_   r0  r   r   r   (test_create_datagram_endpoint_addr_error7  s    

zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_addr_errorc                 C   s>   t  | j_t| jj_| jjtjdd}| 	t| jj
| d S )Nr  r   )remote_addr)r   rI   rH   r  r  r  r  r   DatagramProtocolrP   r_   r0  r   r   r   )test_create_datagram_endpoint_connect_errA  s    

zHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_connect_errc                    s   t d| jd t  | j_}g |_| jj fddddd}| j|\}}| |j	 |
  | j j | d j d S )NTr\   rH   c                      s    S r   r   r   r  r   r   rb   P  r:   z^BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_allow_broadcast.<locals>.<lambda>r  )r  allow_broadcastrx  )r|  rH   r   rI   r  r!   r  r_   rY   r   rZ   rl  r0   rj  )r4   r  r  rn  r  r   r  r   -test_create_datagram_endpoint_allow_broadcastJ  s    
zLBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_allow_broadcastc                 C   s^   t j|_t|j _| jjtjt jd}| 	t| jj
| | jjtjdd}| 	t| jj
| d S )Nr  r  r  )r   r"   r  r  rH   r  r   r  r   rP   r_   r   r   r   r   (test_create_datagram_endpoint_socket_err[  s    

zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_socket_errzIPv6 not supported or enabledc                 C   s*   | j jtjddd}| t| j j| d S )Nr  )r  r   )r  r  rH   r  r   r  rP   r   r_   r0  r   r   r   0test_create_datagram_endpoint_no_matching_familyj  s    
zOBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_matching_familyc                 C   sH   t |jjj_| jjtjtj	d}| 
t | jj| | |jjjj d S )Nr  )r  r   r!   setblockingr  rH   r  r   r  r   rP   r_   r[   rZ   r   r   r   r   r   (test_create_datagram_endpoint_setblk_errr  s    

zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_setblk_errc                 C   s$   | j tj}| t| j j| d S r   r  r0  r   r   r   -test_create_datagram_endpoint_noaddr_nofamily}  s    zLBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_noaddr_nofamilyc                 C   sh   G dd dt }tj|_t  }|j_||j_| jj	t
dtjd}| || jj| | |jj d S )Nc                   @   s   e Zd ZdS )zSBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_cant_bind.<locals>.ErrNr   r   r   r   r   r    s   r  r  )r  r  )r  r   r"   r   rI   r!   r  r  rH   r  r|  r   rP   r_   r[   rZ   r   r  r   r   r   'test_create_datagram_endpoint_cant_bind  s    zFBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_cant_bindc                    sj   t  t jt j}|d  jj fdd|d} j|\}}|   j|j  	d|j
 d S )Nr  c                      s   t d jdS NTr  r|  rH   r   rM   r   r   rb     r:   zSBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock.<locals>.<lambda>r  rx  )r   r   r   r  rH   r  r_   rZ   rl  r0   rj  )r4   r  r   rn  r  r   rM   r   "test_create_datagram_endpoint_sock  s    

zABaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockAF_UNIXzNo UNIX Socketsc                    sR    j j fddtjd} j |\}}|   j |j  d|j d S )Nc                      s   t d jdS r  r  r   rM   r   r   rb     r:   zXBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_unix.<locals>.<lambda>r  rx  )	rH   r  r   r  r_   rZ   rl  r0   rj  )r4   r   rn  r  r   rM   r   'test_create_datagram_endpoint_sock_unix  s    
zFBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_unixc                    s   t  v}tjtjtjd}|| |   jj fdd|tjd} j	|\}}|   j	|j
 W d    n1 s0    Y  d S )N)r  c                      s   t d jdS r  r  r   rM   r   r   rb     r:   zaBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_existing_sock_unix.<locals>.<lambda>r  )r    Zunix_socket_pathr   r  r   r  rZ   rH   r  r_   rl  )r4   pathr  r  rn  r  r   rM   r   0test_create_datagram_endpoint_existing_sock_unix  s    


zOBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_existing_sock_unixc                 C   s  G dd d}| j jtd| d}| t| j j| | j jtd| d}| t| j j| | j jtd| d}| t| j j| | j jtd| d}| t| j j| | j jtd| d	}| t| j j| | j jtd
| d}| t| j j| | j jtd
| d}| t| j j| d S )Nc                   @   s   e Zd ZejZdS )z\BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_sockopts.<locals>.FakeSockN)r@   rA   rB   r   r   r  r   r   r   r   FakeSock  s   r  r  )r  r  )r  r  r.   )r  r  )protor  )flagsr  T)r  r  )r	  r  )rH   r  r|  rP   r   r_   )r4   r  r   r   r   r   +test_create_datagram_endpoint_sock_sockopts  s:    zJBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_sockoptsc                    s4   j j fdddd} j |\}}|d}ttd}|rV |tjtj	  |tjtj
 |   j |j  d|j  j j fddd|d	d
} j |\}}|d} |tjtj |r |tjtj	  |tjtj
 |   j |j  d|j d S )Nc                      s   t d jdS r  r  r   rM   r   r   rb     r:   zWBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockopts.<locals>.<lambda>r  r  r   r  rx  c                      s   t d jdS r  r  r   rM   r   r   rb     r:   T)r  r  r	  )rH   r  r_   r  r   r   rY   
getsockoptr   r  SO_BROADCASTrZ   rl  r0   rj  r   r[   )r4   r  rn  r  r  reuseport_supportedr   rM   r   &test_create_datagram_endpoint_sockopts  s`    




zEBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockoptsc                    sT    j j fddddd} t  j | W d    n1 sF0    Y  d S )Nc                      s   t d jdS r  r  r   rM   r   r   rb   	  r:   zbBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_error.<locals>.<lambda>r  Tr  Zreuse_address)rH   r  rP   r   r_   r0  r   rM   r   1test_create_datagram_endpoint_reuse_address_error  s    
zPBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_errorc                    s|    j j fddddd} tD  j |\}}|   j |j  d|j W d    n1 sn0    Y  d S )Nc                      s   t d jdS r  r  r   rM   r   r   rb     r:   zdBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_warning.<locals>.<lambda>r  Fr!  rx  )	rH   r  rz   r{   r_   rZ   rl  r0   rj  )r4   r  rn  r  r   rM   r   3test_create_datagram_endpoint_reuse_address_warning  s    
zRBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_warningc                    s@   |` t |j_ jj fddddd} t jj	| d S )Nc                      s   t  jdS r  r  r   rM   r   r   rb   $  r:   z\BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_nosoreuseport.<locals>.<lambda>r  Tr  r  )
r  r   rI   r   r!   rH   r  rP   r   r_   r   r   rM   r   +test_create_datagram_endpoint_nosoreuseport  s    
zJBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_nosoreuseportc              	      s    fdd}||_ t  |jj_}t  j_d jj_t	td} jj
 fddd|d} j|\}}z:|d |jj|j|j|jd	 W |  t j n|  t j 0 d S )
Nc                     s     d d S )Nz"should not have called getaddrinfo)Zfailr  rM   r   r   r"   ,  s    zYBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.getaddrinfoFr  c                      s   t  jdS r  r  r   rM   r   r   rb   6  r:   zVBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.<lambda>r9   r$  )r  r  r  )r"   r   rI   r   r!   r  rH   r  r#   r   r  r_   r   r   r   r   rZ   r    r   )r4   r$   r"   r  r  r  r   r  r   rM   r   %test_create_datagram_endpoint_ip_addr*  s,    




zDBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addrc                 C   s2   t  }t |j_| jt| | |j	j
 d S r   )r   rI   BlockingIOErroracceptr  rH   _accept_connectionrh  rY   rZ   r   r4   r  r   r   r   test_accept_connection_retryD  s    
z;BaseEventLoopWithSelectorTests.test_accept_connection_retryr   c              
   C   s   t  }d|j_ttjd|j_t  | j	_
t  | j	_| j	t| | |jj | |jj | j	j
d | j	jtjt jt|d d t jt j d S )N
   zToo many open files)r   rI   filenor!   r  r  ZEMFILEr(  r  rH   Z_remove_readerr   r)  rh  r[   r   r   rY   rZ   r   r   ZACCEPT_RETRY_DELAYr  )r4   Zm_logr  r   r   r    test_accept_connection_exceptionK  s    z?BaseEventLoopWithSelectorTests.test_accept_connection_exceptionc              	   C   s  |  t tjdd }W d    n1 s.0    Y  | jd |}| }| |j ||fD ]0}| t	 | j
| W d    n1 s0    Y  | t	 | j| W d    n1 s0    Y  | t	 | jd| W d    n1 s0    Y  | t	( | j| j d | W d    n1 sH0    Y  | t	& | j| jd | W d    qb1 s0    Y  qbd S )Nc                   S   s   d S r   r   r   r   r   r   simple_coroutine_  s    zLBaseEventLoopWithSelectorTests.test_call_coroutine.<locals>.simple_coroutineTr   )rz   r{   r   	coroutinerH   r   r   rZ   rP   r   r~   r   r   r   r   r_   re  )r4   r/  Z	coro_funcZcoro_objrA  r   r   r   test_call_coroutine]  s(    (**.8z2BaseEventLoopWithSelectorTests.test_call_coroutinec                 C   s   dd }dd }t | j | jd d| j_| j|| j | j  |jjd ^}}| 	|t
| d t j|| j| jd	 | j  |jjd ^}}| 	|t
| d
 d S )Nc                 S   s   |    d S r   r   r   r   r   r   stop_loop_cbv  s    zLBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_cbc                    s   |    d S r   r2  r   r   r   r   stop_loop_coroy  s    zNBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_coroTg        r   z4^Executing <Handle.*stop_loop_cb.*> took .* seconds$r   z4^Executing <Task.*stop_loop_coro.*> took .* seconds$)r   rL   rH   r   Zslow_callback_durationr~   r^   warningr   r  tupler   )r4   Zm_loggerr3  r4  fmtrn   r   r   r   test_log_slow_callbackst  s"    

z6BaseEventLoopWithSelectorTests.test_log_slow_callbacks)Jr@   rA   rB   rF   r   r'   r  r)   r  r  r  r  r  r  unittest
skipUnlessr   r   r  r   r3   r  r  r  r  r  r  r  r  ZskipIfr   platformr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r  r  r  r  Zskip_unless_bind_unix_socketr  r  r   r"  r#  r%  r&  r+  r.  r1  r8  rg  r   r   rN   r   r    s   



	

+



I	





	
	







 /


r  c                   @   s   e Zd Zdd ZdS )RunningLoopTestsc                 C   s~   dd }t  }t  }zN| td ||| W d    n1 sJ0    Y  W |  |  n|  |  0 d S )Nc                    s   |    d S r   )r^   r   r   r   r   runner  s    z@RunningLoopTests.test_running_loop_within_a_loop.<locals>.runnerzwhile another loop is running)r   r6  r   r]   r_   rZ   )r4   r=  rH   Z
outer_loopr   r   r   test_running_loop_within_a_loop  s    .
z0RunningLoopTests.test_running_loop_within_a_loopN)r@   rA   rB   r>  r   r   r   r   r<    s   r<  c                       s   e Zd Zdd ZG dd dejZe fddZe fddZ	 fd	d
Z
d(ddZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Z  ZS ))BaseLoopSockSendfileTestss   12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcdei   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )z!BaseLoopSockSendfileTests.MyProtoc                 C   s(   d| _ d| _t | _| | _d | _d S ra   )rT  closed	bytearrayrt  r\   r   rn  )r4   rH   r   r   r   rm    s
    
z*BaseLoopSockSendfileTests.MyProto.__init__c                 C   s   d| _ || _d S r   )rT  rn  rp  r   r   r   rq    s    z1BaseLoopSockSendfileTests.MyProto.connection_madec                 C   s   | j | d S r   )rt  extendrs  r   r   r   ru    s    z/BaseLoopSockSendfileTests.MyProto.data_receivedc                 C   s   d| _ | jd  d | _d S r   )r@  r   r   rn  rz  r   r   r   r{    s    z1BaseLoopSockSendfileTests.MyProto.connection_lostc                    s   | j I d H  d S r   r   rM   r   r   r   r    s    z-BaseLoopSockSendfileTests.MyProto.wait_closedN)r@   rA   rB   rm  rq  ru  r{  r  r   r   r   r   rh    s
   rh  c                    sT   t j| _dt _ttjd}|| j W d    n1 s<0    Y  t 	  d S )Ni @  wb)
r   !SENDFILE_FALLBACK_READBUFFER_SIZE'_BaseLoopSockSendfileTests__old_bufsizeopenr   TESTFNro  DATArE   
setUpClass)clsfprN   r   r   rI    s
    *z$BaseLoopSockSendfileTests.setUpClassc                    s"   | j t_ttj t   d S r   )rE  r   rD  r   unlinkrG  rE   tearDownClass)rJ  rN   r   r   rM    s    z'BaseLoopSockSendfileTests.tearDownClassc                    sJ   ddl m} | | _| | j ttjd| _| | jj	 t
   d S )Nr   )BaseSelectorEventLooprb)Zasyncio.selector_eventsrN  rH   rL   rF  r   rG  filer   rZ   rE   rF   )r4   rN  rN   r   r   rF     s    zBaseLoopSockSendfileTests.setUpFc                 C   s*   t  t jt j}|| | |j |S r   )r   r   r   r  r   rZ   )r4   blockingr  r   r   r   make_socket  s    
z%BaseLoopSockSendfileTests.make_socketc                 C   s   | j |S r   )rH   r_   r0  r   r   r   r    s    z"BaseLoopSockSendfileTests.run_loopc              	      s     j jj fddtjdtjdj	d 
 }tdD ]H}zj| W n& ty   td Y qPY qP0  qqPj|  fdd}|  fS )	Nc                      s    S r   r   r   )r  r   r   rb     r:   z3BaseLoopSockSendfileTests.prepare.<locals>.<lambda>r   r  r,  g      ?c                      sD            jd ur@ j      d S r   )rZ   r  r  rn  r   r  r4   Zserverr  r   r   cleanup  s    

z2BaseLoopSockSendfileTests.prepare.<locals>.cleanup)rR  rh  rH   r  r  r   ZHOSTr   r   r  getsocknamer   r  r  r   r   r   )r4   r}  r  rT  r   rS  r   prepare  s"    


z!BaseLoopSockSendfileTests.preparec              	   C   sx   |   \}}| tjd* | | j|| jdd  W d    n1 sJ0    Y  | |j	d | | j
 d d S )Nsendfile is not availabler   r:   )rV  r   r   SendfileNotAvailableErrorr  rH   Z_sock_sendfile_nativerP  r0   rt  tellr4   r  r  r   r   r   "test__sock_sendfile_native_failure  s    $z<BaseLoopSockSendfileTests.test__sock_sendfile_native_failurec                 C   sx   |   \}}| tjd* | | jj|| jdd W d    n1 sJ0    Y  | | j	 d | |j
d d S )NrW  F)fallbackr   r:   )rV  r   r   rX  r  rH   sock_sendfilerP  r0   rY  rt  rZ  r   r   r   test_sock_sendfile_no_fallback  s    &z8BaseLoopSockSendfileTests.test_sock_sendfile_no_fallbackc                 C   sv   |   \}}| | j|| j}|  | |  | |t| j	 | | j
 t| j	 | |j| j	 d S r   )rV  r  rH   r]  rP  rZ   r  r0   r   rH  rY  rt  r4   r  r  retr   r   r   test_sock_sendfile_fallback  s    z5BaseLoopSockSendfileTests.test_sock_sendfile_fallbackc                 C   sv   |   \}}| | j|| jdd}|  | |  | |d | | j d | |j	| j
dd  d S )Ni  i  r   )rV  r  rH   r]  rP  rZ   r  r0   rY  rt  rH  r_  r   r   r   ,test_sock_sendfile_fallback_offset_and_count  s    zFBaseLoopSockSendfileTests.test_sock_sendfile_fallback_offset_and_countc                 C   s^   | j d | jdd}| td& | | j || j W d    n1 sP0    Y  d S )NT)rQ  zmust be non-blocking)rH   r   rR  r   r   r  r]  rP  r*  r   r   r   test_blocking_socket*  s    z.BaseLoopSockSendfileTests.test_blocking_socketc              	   C   sx   |   }ttjdP}| td$ | | j|| W d    n1 sL0    Y  W d    n1 sj0    Y  d S )Nr  zbinary mode)	rR  rF  r   rG  r   r   r  rH   r]  )r4   r  r(   r   r   r   test_nonbinary_file0  s    z-BaseLoopSockSendfileTests.test_nonbinary_filec                 C   sl   t  t jt j}|d | |j | td& | | j	
|| j W d    n1 s^0    Y  d S )NFzonly SOCK_STREAM type)r   r   r   r  r   rZ   r   r   r  rH   r]  rP  r*  r   r   r   test_nonstream_socket6  s
    
z/BaseLoopSockSendfileTests.test_nonstream_socketc              	   C   sR   |   }| td* | | j|| jdd W d    n1 sD0    Y  d S )N count must be a positive integerr   rO  rR  r   r   r  rH   r]  rP  r*  r   r   r   test_notint_count=  s
    z+BaseLoopSockSendfileTests.test_notint_countc              	   C   sR   |   }| td* | | j|| jdd W d    n1 sD0    Y  d S )Nrf  r   r   rR  r   r   r  rH   r]  rP  r*  r   r   r   test_negative_countC  s
    z-BaseLoopSockSendfileTests.test_negative_countc                 C   sP   |   }| td( | | j|| jd W d    n1 sB0    Y  d S )N%offset must be a non-negative integeroffsetrg  r*  r   r   r   test_notint_offsetI  s
    z,BaseLoopSockSendfileTests.test_notint_offsetc                 C   sP   |   }| td( | | j|| jd W d    n1 sB0    Y  d S )Nrk  r   ri  r*  r   r   r   test_negative_offsetO  s
    z.BaseLoopSockSendfileTests.test_negative_offset)F)r@   rA   rB   rH  r   r  rh  classmethodrI  rM  rF   rR  r  rV  r[  r^  ra  rb  rc  rd  re  rh  rj  rm  rn  rg  r   r   rN   r   r?    s*   	
r?  c                   @   s.   e Zd Zdd Zeeedddd ZdS )TestSelectorUtilsc                 C   sB   | tjtj}| | t| | tjtj}| | d S r   )r  r   r   TCP_NODELAYrY   r   Z_set_nodelayr[   )r4   r  optr   r   r   check_set_nodelayW  s
    

z#TestSelectorUtils.check_set_nodelayrq  zneed socket.TCP_NODELAYc                 C   s   t j t jt jt jd}| | | W d    n1 s:0    Y  t j t jt jt jd}|$ |d | | W d    n1 s0    Y  d S )N)r  r  r  F)r   r   r   r   rs  r  r*  r   r   r   test_set_nodelay`  s    (
z"TestSelectorUtils.test_set_nodelayN)	r@   rA   rB   rs  r9  r:  r   r   rt  r   r   r   r   rp  V  s
   	rp  __main__)+__doc__concurrent.futuresrr   r  r   r   r   r   r   r9  r   r   r   r   Ztest.test_asyncior   r    r/  r   Ztest.support.script_helperr   Ztest.supportr   r  r   version_infor   r   r&   r)   ZTestCaser*   rC   r  rh  r  r|  r  r<  r?  rp  r@   r  r   r   r   r   <module>   sX   
a      T      y 5
