o
    U˟i                     @   sl   d dl mZ d dlZd dlmZmZ dZG dd dejZdd Z	G dd	 d	ejZ
ed
kr4e  dS dS )    N)utilsocket皙?c                   @   s\   e Zd Zeddd Zdd Zdd Zee	dr,d	d
 Z
dd Zdd Zdd ZdS dS )Testz4Timing causes the state to often be [start,finished]c                    sV   g   fdd}t |}t td   dgksJ  |  |  g d d S )Nc                      s>   z  d ttd  W n	     d Y   d d S )Nstartg      @exceptfinished)appendgeventsleepDELAY stater   ^/var/www/apps/myagent/mysuperagent/venv/lib/python3.10/site-packages/gevent/tests/test__api.pytest#   s   
z'Test.test_killing_dormant.<locals>.test   r   )r   r   r   )r
   spawnr   r   killassertEqual)selfr   gr   r   r   test_killing_dormant   s   

zTest.test_killing_dormantc                 C   s    dd }|  tjtjd| d S )Nc                   S   s   t jdt jdddS )Ng?r      )timeout_value)r
   with_timeoutr   r   r   r   r   func5   s   z+Test.test_nested_with_timeout.<locals>.funcr   )assertRaisesr
   Timeoutr   r   r   r   r   r   test_nested_with_timeout4   s   zTest.test_nested_with_timeoutc                 C   sp   t ttt jd}t d t |jd }| }t|ts$J |dt	|v s2J t
t	||  d S )Nr   r   Invalid switch)r
   r   r   wrap_errorsAssertionErrorr   switchget
isinstancestrreprr   )r   pswitcherresultr   r   r   test_sleep_invalid_switch9   s   
zTest.test_sleep_invalid_switch
socketpairc                 C   s   t  \}}zEtttt j| }t	 j
t| |d ur&t| | }t|ts3J |dt|v sAJ tt|W |  |  d S |  |  w )Nr!   )r   r-   r
   r   r   r"   r#   	wait_readfilenoget_hublooprun_callbackswitch_Noner   r%   r&   r'   r(   close)r   r   sock1sock2r)   r+   r   r   r   _test_wait_read_invalid_switchD   s"   


z#Test._test_wait_read_invalid_switchc                 C      |  d  d S Nr7   r   r   r   r   test_invalid_switch_NoneT      zTest.test_invalid_switch_Nonec                 C      |  d d S )Nr   r:   r;   r   r   r   test_invalid_switch_0W   r=   zTest.test_invalid_switch_0c                 C   r>   )NgMbP?r:   r;   r   r   r   test_invalid_switch_1Z   r=   zTest.test_invalid_switch_1N)__name__
__module____qualname__	greentestskipOnAppVeyorr   r    r,   hasattrr   r7   r<   r?   r@   r   r   r   r   r      s    

	r   c                 C   r8   r9   )r$   )r   r   r   r   r3   `   r=   r3   c                   @   s   e Zd Zdd Zdd ZdS )
TestTimersc                    sL   dg  fdd}t | |  dg t   t d |  g  d S )Nr   c                      s   t d j t d d S )Ng{Gz?g{Gz?)r
   spawn_laterpopr   r   lstr   r   r   i   s   z)TestTimers.test_timer_fired.<locals>.funcr   )r
   r   r   r   r   r   rJ   r   test_timer_firedf   s   

zTestTimers.test_timer_firedc                    s6   dg  fdd}t | t d |  g  d S )Nr   c                      s   t  j d S r9   )r
   r   rI   r   rJ   r   r   r   {   s   z4TestTimers.test_spawn_is_not_cancelled.<locals>.funcr   )r
   r   r   r   r   r   rJ   r   test_spawn_is_not_cancelledx   s
   

z&TestTimers.test_spawn_is_not_cancelledN)rA   rB   rC   rL   rM   r   r   r   r   rG   d   s    rG   __main__)gevent.testingtestingrD   r
   r   r   r   TestCaser   r3   rG   rA   mainr   r   r   r   <module>   s   C