a
    xd/                     @   s   d dl Z ddlmZmZ d dlZd dlmZm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S )    N   )wait_all_tasks_blockedassert_checkpoints)open_memory_channelEndOfChannelc                     s4  t t td W d    n1 s(0    Y  t t td W d    n1 sZ0    Y  td\} }t|  t| | d t   | dI d H  W d    n1 s0    Y  t t	j
 | d  W d    n1 s0    Y  t ( | I d H dksJ W d    n1 s,0    Y  | dksHJ t t	j
 |  W d    n1 st0    Y  | d |  I d H  t t	j  | dI d H  W d    n1 s0    Y  t t	j | d W d    n1 s0    Y  t t	j |   W d    n1 s80    Y  |  I d H  | dksbJ t t | I d H  W d    n1 s0    Y  | I d H  t t	j | I d H  W d    n1 s0    Y  t t	j | I d H  W d    n1 s0    Y  | I d H  d S )Ng      ?r      lastztoo late)pytestraises	TypeErrorr   
ValueErrorreprsend_nowaitr   sendtrio
WouldBlockreceivereceive_nowaitacloseClosedResourceErrorcloner   )sr r   O/var/www/html/Ranjet/env/lib/python3.9/site-packages/trio/tests/test_channel.pytest_channel   sF    &&
.(8(
0*(...r   c                    sb   t d\}}td}| I d H  W d    n1 s:0    Y  |jsNJ |dI d H  d S )Nr   
   zTest for PR #553)r   r   Zmove_on_afterr   Zcancelled_caughtr   )Zautojump_clockr   r   Ztimeout_scoper   r   r   test_5533   s
    ,
r   c               
      s   dd } t d\}}t 4 I d H }|4 I d H 6 tdD ]}|| | | q<W d   I d H  q~1 I d H st0    Y  g }|2 z3 d H W }|| q6 |  |ttdksJ W d   I d H  q1 I d H s0    Y  d S )Nc              	      sh   | 4 I d H B t d| d|d  D ]}| |I d H  q$W d   I d H  qd1 I d H sZ0    Y  d S )N   r   )ranger   )send_channelijr   r   r   producer<   s    z1test_channel_multiple_producers.<locals>.producerr   r      )	r   r   open_nurseryr    
start_soonr   appendsortlist)r$   r!   receive_channelnurseryr"   gotvaluer   r   r   test_channel_multiple_producers;   s    >r/   c               
      s$  t  g   fdd} t 4 I d H }td\}}|4 I d H \ tdD ]}|| || qNt I d H  tdD ]}||I d H  qvW d   I d H  q1 I d H s0    Y  W d   I d H  q1 I d H s0    Y  t tdksJ t dksJ t  t tdks J d S )Nc                    s,   | 2 z 3 d H W } |  | q6 d S N)addr(   )r+   r"   r.   ZreceivedZsuccessful_receiversr   r   consumerV   s    
z1test_channel_multiple_consumers.<locals>.consumerr      r   )	setr   r&   r   r    r'   r   r   len)r3   r,   r!   r+   r"   r   r2   r   test_channel_multiple_consumersR   s    fr7   c               	      s6  dd } t d\}}t 4 I d H @}|| |tj t I d H  | I d H  W d   I d H  qz1 I d H sp0    Y  ttj |	d  W d    n1 s0    Y  ttj  |
d I d H  W d    n1 s0    Y  tt |  W d    n1 s0    Y  tt | I d H  W d    n1 sP0    Y  t d\}}t 4 I d H B}|| |tj t I d H  | I d H  W d   I d H  q1 I d H s0    Y  ttj |	d  W d    n1 s0    Y  ttj  |
d I d H  W d    n1 s<0    Y  dd }t d\}}t 4 I d H >}||| t I d H  | I d H  W d   I d H  q1 I d H s0    Y  ttj |  W d    n1 s0    Y  ttj | I d H  W d    n1 s(0    Y  d S )Nc                    s>   t |  | d I d H  W d    n1 s00    Y  d S r0   r
   r   r   r   expectr   r   r   
send_blockj   s    z%test_close_basics.<locals>.send_blockr   c                    s>   t tj |  I d H  W d    n1 s00    Y  d S r0   r
   r   r   r   r   r   r   r   r   receive_block   s    z(test_close_basics.<locals>.receive_block)r   r   r&   r'   r   r   r   r
   r   r   r   r   r   r   BrokenResourceErrorr;   r   r   r,   r>   r   r   r   test_close_basicsi   sB    8(.(.<*0<(rA   c               	      s$  dd } t d\}}t 4 I d H :}|| |tj t I d H  |  W d   I d H  qt1 I d H sj0    Y  ttj |	d  W d    n1 s0    Y  ttj  |
d I d H  W d    n1 s0    Y  tt |  W d    n1 s0    Y  tt | I d H  W d    n1 sJ0    Y  t d\}}t 4 I d H <}|| |tj t I d H  |  W d   I d H  q1 I d H s0    Y  ttj |	d  W d    n1 s0    Y  ttj  |
d I d H  W d    n1 s00    Y  dd }t d\}}t 4 I d H 8}||| t I d H  |  W d   I d H  q1 I d H s0    Y  ttj |  W d    n1 s0    Y  ttj | I d H  W d    n1 s0    Y  d S )Nc                    s>   t |  | d I d H  W d    n1 s00    Y  d S r0   r8   r9   r   r   r   r;      s    z#test_close_sync.<locals>.send_blockr   c                    s>   t tj |  I d H  W d    n1 s00    Y  d S r0   r<   r=   r   r   r   r>      s    z&test_close_sync.<locals>.receive_block)r   r   r&   r'   r   r   closer
   r   r   r   r   r   r   r?   r@   r   r   r   test_close_sync   sB    2(.(.6*06(rC   c                     s  t d\} }| }| }| d  | I d H  | W d    n1 sN0    Y  ttj |  W d    n1 s0    Y  ttj |  W d    n1 s0    Y  | d  | I d H  ttj | d  W d    n1 s0    Y  d S )Nr   )	r   r   r   r   r
   r   r   r   r?   )r   r   r2Zr3r   r   r   $test_receive_channel_clone_and_close   s    
&&
rE   c               	      s   t d\ }    fdd}fdd}t 4 I d H Z}|| || t I d H    I d H  |  I d H dksJ W d   I d H  q1 I d H s0    Y  d S )Nr   c                      s@   t tj   dI d H  W d    n1 s20    Y  d S )NZnope)r
   r   r   r   r   r   )s1r   r   send_will_close   s    z9test_close_multiple_send_handles.<locals>.send_will_closec                      s     dI d H  d S Nok)r   r   )s2r   r   send_will_succeed   s    z;test_close_multiple_send_handles.<locals>.send_will_succeedrI   )r   r   r   r&   r'   r   r   r   )r   rG   rK   r,   r   )rF   rJ   r    test_close_multiple_send_handles   s    

rL   c               	      s   t d\}     fdd}fdd}t 4 I d H T}|| || t I d H    I d H  | dI d H  W d   I d H  q1 I d H s0    Y  d S )Nr   c                      s>   t tj   I d H  W d    n1 s00    Y  d S r0   r<   r   )r1r   r   receive_will_close  s    z?test_close_multiple_receive_handles.<locals>.receive_will_closec                      s      I d H dksJ d S rH   r   r   )rD   r   r   receive_will_succeed  s    zAtest_close_multiple_receive_handles.<locals>.receive_will_succeedrI   )r   r   r   r&   r'   r   r   r   )r   rN   rP   r,   r   )rM   rD   r   #test_close_multiple_receive_handles  s    

rQ   c                     s   t td\} }| ( tdD ]}| | qW d    n1 sB0    Y  g }|2 z3 d H W }|| qT6 |ttdksJ d S )Ninfr   )r   floatr    r   r(   r*   )r   r   r"   r-   r   r   r   test_inf_capacity  s    *rT   c               	      s|  t d\} }|  | ks J |  }|jdks6J |jdksDJ |jdksRJ |jdks`J |jdksnJ |jdks|J | d  |  jdksJ | 	 }|  jdksJ | 
 I d H  | jdksJ |	 }| jdksJ |
 I d H  | jdksJ t 4 I d H |}|d  |  jdks>J ||jd  ||jd  t I d H  |  jdkszJ |j  W d   I d H  q1 I d H s0    Y  |  jdksJ z|  qW n tjy   Y n0 t 4 I d H N}||j t I d H  |  jdks,J |j  W d   I d H  qd1 I d H sZ0    Y  |  jdksxJ d S )Nr   r   r   )r   
statisticsZcurrent_buffer_usedmax_buffer_sizeZopen_send_channelsZopen_receive_channelsZtasks_waiting_sendZtasks_waiting_receiver   r   r   r   r&   r'   r   r   Zcancel_scopecancelr   r   r   )r   r   statsrJ   rD   r,   r   r   r   test_statistics*  sL    

88rY   c               	      s  t d\} }| d | dks&J | d | dks@J d   fdd}t 4 I d H l}||| t I d H  | d ttj	 |  W d    n1 s0    Y  W d   I d H  q1 I d H s0    Y   dksJ t d\} }| d ttj	 | d  W d    n1 s20    Y  t 4 I d H }|| j
d t I d H  | dkszJ ttj	 | d W d    n1 s0    Y  | I d H dksJ W d   I d H  q1 I d H s0    Y  d S )Nr   r   c                    s   |   I d H  d S r0   rO   r=   resultr   r   
do_receivek  s    z)test_channel_fairness.<locals>.do_receiver   )r   r   r   r   r&   r'   r   r
   r   r   r   r   )r   r   r\   r,   r   rZ   r   test_channel_fairness\  s2    


P
**r]   c               	      s@  t d\} }ttj |  W d    n1 s60    Y  ttj | d W d    n1 sl0    Y  dd }t 4 I d H b}||| d t	 & |
 I d H dksJ W d    n1 s0    Y  W d   I d H  q1 I d H s0    Y  ttj |  W d    n1 s20    Y  d S )Nr   r   c                    s:   t    | |I d H  W d    n1 s,0    Y  d S r0   )r   r   )r   vr   r   r   do_send  s    z test_unbuffered.<locals>.do_send)r   r
   r   r   r   r   r   r&   r'   r   r   )r   r   r_   r,   r   r   r   test_unbuffered  s    &(`r`   )r
   Ztestingr   r   r   r   r   r   r   r/   r7   rA   rC   rE   rL   rQ   rT   rY   r]   r`   r   r   r   r   <module>   s    +772+