
    g6                         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e      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zedk(  r ej*                          yy)    N)	timedelta)random)genqueues)TimeoutError)gen_testAsyncTestCasec                   (    e Zd Zd Zd Zed        Zy)QueueBasicTestc                    t        j                  d      }| j                  t        t	        |            t        |             | j                  t        t	        |            t        |             |j                          t        |      t        |      fD ]j  }| j                  |j                  d             | j                  d|       | j                  d|       | j                  d|       | j                  d|       l |j                  d        |j                  d        |j                  d        t        |      t        |      fD ]8  }| j                  d|       | j                  d	|       | j                  d
|       : y )N   maxsizez<Queuez	maxsize=1z
getters[1]putterstasksgettersz
putters[1]ztasks=2)r   QueueassertInhexidreprassertNotInstrget
assertTrue
startswithput)selfqq_strs      M/var/www/openai/venv/lib/python3.12/site-packages/tornado/test/queues_test.pytest_repr_and_strz QueueBasicTest.test_repr_and_str   s   LL#c"Q%j$q'*RUSV,	!Wc!f_EOOE,,X67MM+u-MM,.Y.We, % 	
d	d	d!Wc!f_EY.MM,.MM)U+ %    c                     t        j                         }dD ]  }|j                  |        t        d      D cg c]  }|j	                          }}| j                  g d|       y c c}w )N)r         r%   )r   r   
put_nowaitrange
get_nowaitassertEqual)r   r   i_itemss        r!   
test_orderzQueueBasicTest.test_order/   sW    LLNALLO  */q2A2E* 3s   A(c              #     K   | j                  t        t        j                  d        | j                  t        t        j                  d       t        j                  d      }| j                  |j                                | j                  |j                                | j                  d|j                         | j                  |j                  d      j                                | j                  |j                  d      j                                | j                  |j                                | j                  |j                                |j                  d      }| j                  |j                                | j                  d|j                                | j                  |j                                | j                  |j                                | j                  |j                                y w)Nr   r&   r   r   )assertRaises	TypeErrorr   r   
ValueErrorr   emptyassertFalsefullr*   r   r   doner   )r   r   put2s      r!   test_maxsizezQueueBasicTest.test_maxsize7   sK    )V\\4@*fllB?LL#	""AII&a(a(#!uuQx%1557],		$#!s   HH	N)__name__
__module____qualname__r"   r.   r   r9    r#   r!   r   r      s     ,.+ " "r#   r   c                       e Zd Zed        Zd Zd Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zed
        Zy)QueueGetTestc              #      K   t        j                         }|j                  d       | j                  d|j	                                y wNr   )r   r   r'   r*   r   r   r   s     r!   test_blocking_getzQueueGetTest.test_blocking_getM   s4     LLN	Q1557],s   A	Ac                     t        j                         }|j                  d       | j                  d|j	                                y rA   )r   r   r'   r*   r)   rB   s     r!   test_nonblocking_getz!QueueGetTest.test_nonblocking_getS   s.    LLN	QALLN+r#   c                     t        j                         }| j                  t         j                  |j                         y N)r   r   r1   
QueueEmptyr)   rB   s     r!   test_nonblocking_get_exceptionz+QueueGetTest.test_nonblocking_get_exceptionX   s'    LLN&++Q\\:r#   c              #      K   t        j                  d      }|j                  d       |j                  d      }| j	                  d|j                                | j                  |       y wNr   r   )r   r   r'   r   r*   r   assertIsNoner   r   r   s      r!   test_get_with_puttersz"QueueGetTest.test_get_with_putters\   sS     LLO	QeeAh1557],9&   A.A0c              #     K   t        j                         }|j                  d       | j                  j	                  d|j
                  d       | j                  j	                  d|j
                  d       | j                  d|j                  t        d                   | j                  d|j                  t        d                   y w)Nr   {Gz?r   {Gz?r&   secondstimeout)	r   r   r   io_loop
call_laterr'   r*   r   r   rB   s     r!   test_blocking_get_waitz#QueueGetTest.test_blocking_get_waitd   s     LLN	aallA6allA615511E5#FFH15511E5#FFHs   CCc              #   2  K   t        j                         }|j                  t        d            }|j                         }| j	                  t
              5  | d d d        |j                  d       | j                  d|       y # 1 sw Y   /xY ww)NrQ   rS   rU   r   )r   r   r   r   r1   r   r'   r*   )r   r   get_timeoutr   s       r!   test_get_timeoutzQueueGetTest.test_get_timeoutm   sq     LLNeeId$;e<eeg|, - 	
Q3Y(	 -,s   ABB.BBBc              #      K   t        j                         }|j                  t        d            }|j	                  d       t        j                  d       | j                  d|       y w)NrQ   rS   rU   r   rR   )r   r   r   r   r   r   sleepr*   )r   r   r   s      r!   test_get_timeout_preemptedz'QueueGetTest.test_get_timeout_preemptedx   sQ     LLNeeId3e4	aiio3Y(rO   c           	   #     K   t        j                  d      }t        d      D cg c]  }|j                  |t	        d              }}|j                  d      }| j                  dt        |j                               t        j                  d       | j                  dt        |j                               | j                  |j                                |j                  d       | j                  d|j                                | j                  dt        |j                               |dd  D ]"  }| j                  t        |j                         $ y c c}w w)Nr   
   rQ   rS   rR      r   )r   r   r(   r   r   r*   len_puttersr   r^   r5   r7   r   r1   r   resultr   r   r+   r   r   putters         r!   !test_get_clears_timed_out_puttersz.QueueGetTest.test_get_clears_timed_out_putters   s     LLO>CBiHi155Id34iHeeBiS_-iioS_-$	b	1557],C

O,abkFlFMM: " Is   #E##EDE#c           
   #     K   t        j                         }t        d      D cg c]0  }t        j                  |j                  t        d                  2 }}t        j                  |j                               }| j                  dt        |j                               t        j                  d       | j                  dt        |j                               | j                  |j                                |j                          | j                  dt        |j                               |D ]"  }| j                  t        |j                          $ y c c}w w)Nra   rQ   rS   rb   rR   r&   )r   r   r(   asyncioensure_futurer   r   r*   rc   _gettersr   r^   r5   r7   r1   r   re   r   r   r,   r   r   getters         r!   !test_get_clears_timed_out_gettersz.QueueGetTest.test_get_clears_timed_out_getters   s     LLNKPQS9
KTaG!!!%%	$(?"@A9 	 
 ##AEEG,S_-iioS_-$	C

O,FlFMM: 
s   "E 5EDE c              #      K   t        j                         t        d      D ]  }j                  |        fd} |       }| j	                  |t        t        d                   y w)N   c                  d   K   g } 2 3 d {   }| j                  |       |dk(  s | c S 7 6 y w)N   )append)resultsr+   r   s     r!   fz&QueueGetTest.test_async_for.<locals>.f   s6     G #aq!6"N#1s    0.,.00.0)r   r   r(   r   r*   list)r   r+   rv   ru   r   s       @r!   test_async_forzQueueGetTest.test_async_for   sS     LLNqAEE!H 	# )$uQx.1s   A)A,N)r:   r;   r<   r   rC   rE   rI   rN   rY   r\   r_   rh   ro   rx   r=   r#   r!   r?   r?   L   s    - -
,
; ' ' I I ) ) ) ) ; ; ; ; 2 2r#   r?   c                       e Zd Zed        Zd Zed        Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zed
        Zy)QueuePutTestc                     t        j                         }|j                  d       | j                  d|j	                                y rA   )r   r   r   r*   r)   rB   s     r!   test_blocking_putzQueuePutTest.test_blocking_put   s.    LLN	aALLN+r#   c                     t        j                  d      }|j                  d       | j                  t         j                  |j
                  d       y rK   )r   r   r   r1   	QueueFullr'   rB   s     r!   test_nonblocking_put_exceptionz+QueuePutTest.test_nonblocking_put_exception   s6    LLO	a&**ALL!<r#   c              #     K   t        j                         }|j                         }|j                         }|j                  d       | j	                  d|       |j                  d       | j	                  d|       y wNr   r   )r   r   r   r   r*   r   r   get0get1s       r!   test_put_with_gettersz"QueuePutTest.test_put_with_getters   se     LLNuuwuuweeAh4Z)eeAh4Z)s   BBc              #   P  K   t        j                         }|j                         }|j                         }|j                  d       t        j
                   | j                  d|       |j                  d       t        j
                   | j                  d|       y wr   )r   r   r   r'   r   momentr*   r   s       r!   !test_nonblocking_put_with_gettersz.QueuePutTest.test_nonblocking_put_with_getters   su     LLNuuwuuw	Qjj4Z)	Qjj4Z)s   B$B&c              #   b  K   t        j                  d      j                  d       fd}| j                  j	                  d|       | j                  j	                  d|       j                  d      j                  d      g}| j                  t        d |D                     | y w)Nr   r   c                  &     j                          y rG   )r   )r   s   r!   get_and_discardz<QueuePutTest.test_blocking_put_wait.<locals>.get_and_discard   s    EEGr#   rQ   rR   c              3   <   K   | ]  }|j                           y wrG   )r7   ).0rv   s     r!   	<genexpr>z6QueuePutTest.test_blocking_put_wait.<locals>.<genexpr>   s     7w!QVVXws   )r   r   r'   rW   rX   r   r5   any)r   r   futuresr   s      @r!   test_blocking_put_waitz#QueuePutTest.test_blocking_put_wait   s     LLO	Q	 	o6o6558QUU1X&7w778s   B,B/c              #     K   t        j                  d      }|j                  d       |j                  dt	        d            }|j                  d      }| j                  t              5  | d d d        | j                  d|j                                | j                  d|j                                | y # 1 sw Y   PxY ww)Nr   r   rQ   rS   rU   r&   )
r   r   r'   r   r   r1   r   r*   r)   r   )r   r   put_timeoutr   s       r!   test_put_timeoutzQueuePutTest.test_put_timeout   s     LLO	QeeAy'>e?eeAh|, - 	ALLN+1557], 	 -,s   A*C,C 1AC C	Cc              #      K   t        j                  d      }|j                  d       |j                  dt	        d            }|j                          t        j                  d       | y w)Nr   r   rQ   rS   rU   rR   )r   r   r'   r   r   r   r   r^   rM   s      r!   test_put_timeout_preemptedz'QueuePutTest.test_put_timeout_preempted   sQ     LLO	QeeAy6e7	iio	s   A0A2c           	   #     K   t        j                  d      }t        d      D cg c]  }|j                  |t	        d              }}|j                  d      }| j                  dt        |j                               t        j                  d       | j                  dt        |j                               | j                  |j                                |j                  d       | j                  dt        |j                               |dd  D ]"  }| j                  t        |j                         $ y c c}w w)Nr   ra   rQ   rS   rR   rb   r&   )r   r   r(   r   r   r*   rc   rd   r   r^   r5   r7   r1   r   re   rf   s         r!   !test_put_clears_timed_out_puttersz.QueuePutTest.test_put_clears_timed_out_putters   s     LLO>CBiHi155Id34iHeeBiS_-iioS_-$	b	C

O,abkFlFMM: " Is   #E#D<C9Ec           
   #     K   t        j                         }t        d      D cg c]0  }t        j                  |j                  t        d                  2 }}t        j                  |j                               }|j                          | j                  dt        |j                               t        j                  d       | j                  dt        |j                               | j                  |j                                |j                  d       | j                  dt        |j                               | j                  d|       |D ]"  }| j                  t         |j"                         $ y c c}w w)Nra   rQ   rS      rR   r   r   )r   r   r(   rj   rk   r   r   r*   rc   rl   r   r^   r5   r7   r   r1   r   re   rm   s         r!   !test_put_clears_timed_out_gettersz.QueuePutTest.test_put_clears_timed_out_getters
  s    LLNKPQS9
KTaG!!!%%	$(?"@A9 	 
 ##AEEG,	S_-iioS_-$	aC

O,3Y(FlFMM: 
s   "F5F D,Fc              #     K   t        j                  d      }| j                  |j                                | j	                  |j                                |j                  d       |j                  d       | j	                  |j                                | j                  |j                                | j                  t         j                  |j                  d       | j                  d|j                                | j	                  |j                                | j	                  |j                                |j                  d       |j                  d      }| j	                  |j                                | j                  d|j                                | | j                  |j                                y w)Ng?r   r   r   r&   r%   )r   r   r   r4   r5   r6   r'   r1   r~   r*   r)   r   r7   r   rM   s      r!   test_float_maxsizezQueuePutTest.test_float_maxsize  s/     LL%	""	Q	Q#!&**ALL!<ALLN+#"eeAheeAh$1557],	!s   GG	N)r:   r;   r<   r   r|   r   r   r   r   r   r   r   r   r   r=   r#   r!   rz   rz      s    , ,
=
 * * 
* 
*       ; ; ; ;" " "r#   rz   c                   j    e Zd Zej                  Zd Zed        Zed        Z	ed        Z
ed        Zy)QueueJoinTestc                 d    | j                         }| j                  t        |j                         y rG   )queue_classr1   r3   	task_donerB   s     r!   test_task_done_underflowz&QueueJoinTest.test_task_done_underflow9  s$    *akk2r#   c              #   N   K    j                         t        d      D ]  }j                  |        d _        t        j
                   fd       } |         |        j                           j                  t        t        d             j                         y w)Nd   r   c               3      K   	 j                         } xj                  | z  c_        j                          t        j                  t               dz         Zw)NrQ   )r   accumulatorr   r   r^   r   )itemr   r   s    r!   workerz,QueueJoinTest.test_task_done.<locals>.workerE  sK     UUW}  D( ii400	 s   AA)	r   r(   r'   r   r   	coroutinejoinr*   sum)r   r+   r   r   s   `  @r!   test_task_donezQueueJoinTest.test_task_done=  s     sALLO  		1 
	1 	ffhU3Z$*:*:;s   B!B%c              #     K   | j                         }|j                  d       t        j                  |j	                               }| j                  |j                                |j                          | j                  |j                                t        j                   | j                  |j                                |j                          | j                  |j                                y wrA   )r   r'   rj   rk   r   r5   r7   r   r   r   r   r   )r   r   r   s      r!   test_task_done_delayz"QueueJoinTest.test_task_done_delayS  s      	Q$$QVVX.%eeg%jj%			$s   C6C8c              #   t   K   | j                         }|j                          |j                          y wrG   )r   r   rB   s     r!   test_join_empty_queuez#QueueJoinTest.test_join_empty_queuea  s*     ffhffhs   68c              #      K   | j                         }|j                  d       | j                  t              5  |j	                  t        d             d d d        y # 1 sw Y   y xY ww)Nr   rQ   rS   rU   )r   r   r1   r   r   r   rB   s     r!   test_join_timeoutzQueueJoinTest.test_join_timeoutg  sN     	a|,&&4!8&99 -,,s   7A-A!	A-!A*&A-N)r:   r;   r<   r   r   r   r   r   r   r   r   r   r=   r#   r!   r   r   6  s`    ,,K3 < <* % %  
 : :r#   r   c                   4    e Zd Zej                  Zed        Zy)PriorityQueueJoinTestc              #   <  K   | j                  d      }|j                  d       |j                  d       | j                  |j                                |j	                  d       |j	                  d       | j                  d|j                                | j                  d|j                                | j                  d|j                                | j                  d|j                                | j                  |j                                y w)Nr&   r   )r   a)r   b)r%   c)r&   d	r   r'   r   r6   r   r*   r)   r   r4   rB   s     r!   r.   z PriorityQueueJoinTest.test_orderr  s     Q'	X	X!	h	h1<<>2!%%'M31<<>2!%%'M3	"   DDN)r:   r;   r<   r   PriorityQueuer   r   r.   r=   r#   r!   r   r   o  s    &&K# #r#   r   c                   4    e Zd Zej                  Zed        Zy)LifoQueueJoinTestc              #   <  K   | j                  d      }|j                  d       |j                  d       | j                  |j                                |j	                  d       |j	                  d       | j                  d|j                                | j                  d|j                                | j                  d|j                                | j                  d|j                                | j                  |j                                y w)Nr&   r   r   r   r%   r   rB   s     r!   r.   zLifoQueueJoinTest.test_order  s     Q'	Q	Q!	a	aALLN+1557],ALLN+1557],	"r   N)r:   r;   r<   r   	LifoQueuer   r   r.   r=   r#   r!   r   r     s    ""K# #r#   r   c                       e Zd Zed        Zy)ProducerConsumerTestc              #   .  K   t        j                  d      g t        j                  fd       }t        j                  fd       } |         |        j	                          | j                  t        t        d                   y w)Nr%   r   c               3   r   K   	  j                  j                                j                          2wrG   )rt   r   r   )historyr   s   r!   consumerz=ProducerConsumerTest.test_producer_consumer.<locals>.consumer  s,     aeeg/ s   47c               3   T   K   t        d      D ]  } j                  |         y w)Nra   )r(   r   )r   r   s    r!   producerz=ProducerConsumerTest.test_producer_consumer.<locals>.producer  s#     b	eeDk! "s   %(ra   )r   r   r   r   r   r*   rw   r(   )r   r   r   r   r   s      @@r!   test_producer_consumerz+ProducerConsumerTest.test_producer_consumer  s|     LL# 
	 
	
 
	" 
	" 	
jffheBi'2s   BBN)r:   r;   r<   r   r   r=   r#   r!   r   r     s    3 3r#   r   __main__)rj   datetimer   r   unittesttornador   r   tornado.genr   tornado.testingr   r	   r   r?   rz   r   r   r   r   r:   mainr=   r#   r!   <module>r      s         $ 32"] 2"jb2= b2JB"= B"J6:M 6:r#M #$# #$3= 36 zHMMO r#   