o
    )Zh6                     @   s   d dl Z d dlmZ d dlmZ d dlZd dlmZmZ d dlm	Z	 d dl
mZmZ G dd deZG d	d
 d
eZG dd deZG dd deZG dd deZG dd deZG dd deZedkrle  dS dS )    N)	timedelta)random)genqueues)TimeoutError)gen_testAsyncTestCasec                   @   s(   e Zd Zdd Zdd Zedd ZdS )QueueBasicTestc                 C   s   t jdd}| tt|t| | tt|t| |  t|t|fD ]"}| 	|
d | d| | d| | d| | d| q*|d  |d  |d  t|t|fD ]}| d| | d	| | d
| qdd S )N   maxsizez<Queuez	maxsize=1z
getters[1]putterstasksgettersz
putters[1]ztasks=2)r   QueueZassertInhexidreprZassertNotInstrget
assertTrue
startswithput)selfqZq_str r   O/var/www/html/lang_env/lib/python3.10/site-packages/tornado/test/queues_test.pytest_repr_and_str   s$   


z QueueBasicTest.test_repr_and_strc                    sF   t   dD ]} | q fddtdD }| g d| d S )N)r
         c                    s   g | ]}   qS r   )
get_nowait.0_r   r   r   
<listcomp>4   s    z-QueueBasicTest.test_order.<locals>.<listcomp>r   )r   r   
put_nowaitrangeassertEqual)r   iitemsr   r$   r   
test_order/   s
   zQueueBasicTest.test_orderc                 c   s    | j ttjd d | j ttjdd tjdd}| |  | |  | 	d|j
 | |d  | |d  | |  | |  |d}| |  | 	d| V  | |  | |  | |  d S )Nr   r   r   r
   )assertRaises	TypeErrorr   r   
ValueErrorr   emptyassertFalsefullr(   r   r   doner   )r   r   Zput2r   r   r   test_maxsize7   s"   
zQueueBasicTest.test_maxsizeN)__name__
__module____qualname__r   r+   r   r4   r   r   r   r   r	      s
    r	   c                   @   s|   e Zd Zedd Zdd Zdd Zedd Zed	d
 Zedd Z	edd Z
edd Zedd Zedd ZdS )QueueGetTestc                 c   s*    t  }|d | d| V  d S Nr   )r   r   r&   r(   r   r   r   r   r   r   test_blocking_getM   s   
zQueueGetTest.test_blocking_getc                 C   &   t  }|d | d|  d S r9   )r   r   r&   r(   r    r:   r   r   r   test_nonblocking_getS   s   
z!QueueGetTest.test_nonblocking_getc                 C   s   t  }| t j|j d S N)r   r   r-   Z
QueueEmptyr    r:   r   r   r   test_nonblocking_get_exceptionX   s   z+QueueGetTest.test_nonblocking_get_exceptionc                 c   sB    t d}|d |d}| d| V  | |V  d S Nr
   r   )r   r   r&   r   r(   r   ZassertIsNoner   r   r   r   r   r   test_get_with_putters\   s   


z"QueueGetTest.test_get_with_puttersc                 c   st    t  }|d | jd|jd | jd|jd | d|jtdddV  | d|jtdddV  d S )Nr   {Gz?r
   {Gz?r   secondstimeout)	r   r   r   io_loop
call_laterr&   r(   r   r   r:   r   r   r   test_blocking_get_waitd   s   
 z#QueueGetTest.test_blocking_get_waitc                 c   sp    t  }|jtddd}| }| t |V  W d    n1 s%w   Y  |d | d|V  d S )NrC   rE   rG   r   )r   r   r   r   r-   r   r&   r(   )r   r   Zget_timeoutr   r   r   r   test_get_timeoutm   s   
zQueueGetTest.test_get_timeoutc                 c   sD    t  }|jtddd}|d tdV  | d|V  d S )NrC   rE   rG   r   rD   )r   r   r   r   r   r   sleepr(   )r   r   r   r   r   r   test_get_timeout_preemptedx   s   
z'QueueGetTest.test_get_timeout_preemptedc                 #   s    t d  fddtdD } d}| dt j tdV  | dt j | 	|
   d | d  V  | dt j |dd  D ]	}| t|j qRd S )Nr
   c                       g | ]}  |td dqS rC   rE   r   r   r"   r)   r$   r   r   r%          zBQueueGetTest.test_get_clears_timed_out_putters.<locals>.<listcomp>
   rD      r   )r   r   r'   r   r(   len_puttersr   rM   r1   r3   r   r-   r   resultr   r   r   Zputterr   r$   r   !test_get_clears_timed_out_putters   s   


z.QueueGetTest.test_get_clears_timed_out_puttersc                 #   s    t    fddtdD }t  }| dt j t	
dV  | dt j | |     | dt j |D ]	}| t|j qEd S )Nc              	      "   g | ]}t  td dqS rP   asyncioensure_futurer   r   r!   r$   r   r   r%          zBQueueGetTest.test_get_clears_timed_out_getters.<locals>.<listcomp>rT   rU   rD   r   )r   r   r'   r]   r^   r   r(   rV   _gettersr   rM   r1   r3   r-   r   rX   r   r   r   getterr   r$   r   !test_get_clears_timed_out_getters   s   
z.QueueGetTest.test_get_clears_timed_out_gettersc                 #   sN    t   tdD ]} | q	 fdd}| V }| |ttd d S )N   c                     s8   g }  2 z3 d H W }|  | |dkr|   S q6 d S )N   )append)resultsr)   r$   r   r   f   s   
z&QueueGetTest.test_async_for.<locals>.f)r   r   r'   r   r(   list)r   r)   rh   rg   r   r$   r   test_async_for   s   zQueueGetTest.test_async_forN)r5   r6   r7   r   r;   r=   r?   rB   rK   rL   rN   rZ   rc   rj   r   r   r   r   r8   L   s&    







r8   c                   @   s   e Zd Zedd Zdd Zedd Zedd Zed	d
 Zedd Z	edd Z
edd Zedd Zedd ZdS )QueuePutTestc                 C   r<   r9   )r   r   r   r(   r    r:   r   r   r   test_blocking_put   s   
zQueuePutTest.test_blocking_putc                 C   s*   t d}|d | t j|jd d S r@   )r   r   r   r-   	QueueFullr&   r:   r   r   r   test_nonblocking_put_exception   s   

z+QueuePutTest.test_nonblocking_put_exceptionc                 c   sR    t  }| }| }|dV  | d|V  |dV  | d|V  d S Nr   r
   )r   r   r   r   r(   r   r   Zget0Zget1r   r   r   test_put_with_getters   s   z"QueuePutTest.test_put_with_gettersc                 c   s^    t  }| }| }|d tjV  | d|V  |d tjV  | d|V  d S ro   )r   r   r   r&   r   momentr(   rp   r   r   r   !test_nonblocking_put_with_getters   s   

z.QueuePutTest.test_nonblocking_put_with_gettersc                 #   st    t d  d  fdd}| jd| | jd|  d dg}| tdd |D  |V  d S )	Nr
   r   c                      s       d S r>   )r   r   r$   r   r   get_and_discard   s   z<QueuePutTest.test_blocking_put_wait.<locals>.get_and_discardrC   rD   c                 s   s    | ]}|  V  qd S r>   )r3   )r"   rh   r   r   r   	<genexpr>   s    z6QueuePutTest.test_blocking_put_wait.<locals>.<genexpr>)r   r   r&   rI   rJ   r   r1   any)r   rt   Zfuturesr   r$   r   test_blocking_put_wait   s   


z#QueuePutTest.test_blocking_put_waitc                 c   s    t d}|d |jdtddd}|d}| t |V  W d    n1 s-w   Y  | d|  | d|	 V  |V  d S )Nr
   r   rC   rE   rG   r   )
r   r   r&   r   r   r-   r   r(   r    r   )r   r   Zput_timeoutr   r   r   r   test_put_timeout   s   



zQueuePutTest.test_put_timeoutc                 c   sH    t d}|d |jdtddd}|  tdV  |V  d S )Nr
   r   rC   rE   rG   rD   )r   r   r&   r   r   r   r   rM   rA   r   r   r   test_put_timeout_preempted   s   


z'QueuePutTest.test_put_timeout_preemptedc                 #   s    t d  fddtdD } d}| dt j tdV  | dt j | 	|
   d | dt j |dd  D ]	}| t|j qId S )Nr
   c                    rO   rP   rQ   rR   r$   r   r   r%      rS   zBQueuePutTest.test_put_clears_timed_out_putters.<locals>.<listcomp>rT   rD   rU   r   )r   r   r'   r   r(   rV   rW   r   rM   r1   r3   r-   r   rX   rY   r   r$   r   !test_put_clears_timed_out_putters   s   


z.QueuePutTest.test_put_clears_timed_out_puttersc                 #   s    t    fddtdD }t  }   | dt j t	
dV  | dt j | |   d | dt j | d|V  |D ]	}| t|j qQd S )Nc              	      r[   rP   r\   r!   r$   r   r   r%     r_   zBQueuePutTest.test_put_clears_timed_out_getters.<locals>.<listcomp>rT      rD   r   r
   )r   r   r'   r]   r^   r   r(   rV   r`   r   rM   r1   r3   r   r-   r   rX   ra   r   r$   r   !test_put_clears_timed_out_getters
  s"   

z.QueuePutTest.test_put_clears_timed_out_gettersc                 c   s    t jdd}| |  | |  |d |d | |  | |  | t j|jd | 	d|
  | |  | |  |dV  |d}| |  | 	d| V  |V  | |  d S )Ng?r   r   r
   r   r   )r   r   r   r0   r1   r2   r&   r-   rm   r(   r    r   r3   r   rA   r   r   r   test_float_maxsize  s$   


zQueuePutTest.test_float_maxsizeN)r5   r6   r7   r   rl   rn   rq   rs   rw   rx   ry   rz   r|   r}   r   r   r   r   rk      s(    

	





rk   c                   @   sJ   e Zd ZejZdd Zedd Zedd Z	edd Z
ed	d
 ZdS )QueueJoinTestc                 C   s   |   }| t|j d S r>   )queue_classr-   r/   	task_doner:   r   r   r   test_task_done_underflow9  s   z&QueueJoinTest.test_task_done_underflowc                 #   sl       tdD ]} | q	d_tj fdd}|  |    V  ttdj d S )Nd   r   c                  3   s8    	    V }  j| 7  _   tt d V  q)NTrC   )r   accumulatorr   r   rM   r   itemr   r   r   r   workerE  s   
z,QueueJoinTest.test_task_done.<locals>.worker)	r   r'   r&   r   r   	coroutinejoinr(   sum)r   r)   r   r   r   r   test_task_done=  s   
zQueueJoinTest.test_task_donec                 c   sx    |   }|d t| }| |  | V  | |  tj	V  | |  |
  | |  d S r9   )r   r&   r]   r^   r   r1   r3   r   r   rr   r   r   )r   r   r   r   r   r   test_task_done_delayS  s   

z"QueueJoinTest.test_task_done_delayc                 c   s"    |   }| V  | V  d S r>   )r   r   r:   r   r   r   test_join_empty_queuea  s   
z#QueueJoinTest.test_join_empty_queuec                 c   sX    |   }|d | t |jtdddV  W d    d S 1 s%w   Y  d S )Nr   rC   rE   rG   )r   r   r-   r   r   r   r:   r   r   r   test_join_timeoutg  s   
"zQueueJoinTest.test_join_timeoutN)r5   r6   r7   r   r   r   r   r   r   r   r   r   r   r   r   r   r~   6  s    


r~   c                   @      e Zd ZejZedd ZdS )PriorityQueueJoinTestc                 c   s    | j dd}|d |d | |  |d |d | d|  | d| V  | d|  | d| V  | |  d S )Nr   r   )r
   a)r   b)r   c)r   d	r   r&   r   r2   r   r(   r    r   r0   r:   r   r   r   r+   r     



z PriorityQueueJoinTest.test_orderN)r5   r6   r7   r   PriorityQueuer   r   r+   r   r   r   r   r   o      r   c                   @   r   )LifoQueueJoinTestc                 c   s    | j dd}|d |d | |  |d |d | d|  | d| V  | d|  | d| V  | |  d S )Nr   r   r
   r   r   r   r:   r   r   r   r+     r   zLifoQueueJoinTest.test_orderN)r5   r6   r7   r   	LifoQueuer   r   r+   r   r   r   r   r     r   r   c                   @   s   e Zd Zedd ZdS )ProducerConsumerTestc                 #   sh    t jddg  tj fdd}tjfdd}|  | V   V  | ttd  d S )Nr   r   c                   3   s    	    V    qr>   )rf   r   r   r   historyr   r   r   consumer  s
   z=ProducerConsumerTest.test_producer_consumer.<locals>.consumerc                  3   s     t dD ]}  | V  qd S )NrT   )r'   r   r   r$   r   r   producer  s   z=ProducerConsumerTest.test_producer_consumer.<locals>.producerrT   )r   r   r   r   r   r(   ri   r'   )r   r   r   r   r   r   test_producer_consumer  s   
z+ProducerConsumerTest.test_producer_consumerN)r5   r6   r7   r   r   r   r   r   r   r     s    r   __main__)r]   datetimer   r   Zunittesttornador   r   Ztornado.genr   Ztornado.testingr   r   r	   r8   rk   r~   r   r   r   r5   mainr   r   r   r   <module>   s$   5e 9