
    R?g6                     "   S SK r S SKJr  S SKJr  S SKrS SKJrJr  S SKJ	r	  S SK
JrJr   " S S\5      r " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r\S:X  a  \R*                  " 5         gg)    N)	timedelta)random)genqueues)TimeoutError)gen_testAsyncTestCasec                   0    \ rS rSrS rS r\S 5       rSrg)QueueBasicTest   c                    [         R                  " SS9nU R                  [        [	        U5      5      [        U5      5        U R                  [        [	        U5      5      [        U5      5        UR                  5         [        U5      [        U5      4 Hk  nU R                  UR                  S5      5        U R                  SU5        U R                  SU5        U R                  SU5        U R                  SU5        Mm     UR                  S 5        UR                  S 5        UR                  S 5        [        U5      [        U5      4 H9  nU R                  SU5        U R                  S	U5        U R                  S
U5        M;     g )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      :/usr/lib/python3/dist-packages/tornado/test/queues_test.pytest_repr_and_str 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                     [         R                  " 5       nS H  nUR                  U5        M     [        S5       Vs/ s H  o1R	                  5       PM     nnU R                  / SQU5        g s  snf )N)r         r'   )r   r   
put_nowaitrange
get_nowaitassertEqual)r   r    i_itemss        r"   
test_orderQueueBasicTest.test_order/   sU    LLNALLO  */q2A2E* 3s   A-c              #     #    U R                  [        [        R                  S S9  U R                  [        [        R                  SS9  [        R                  " SS9nU R                  UR                  5       5        U R                  UR                  5       5        U R                  SUR                  5        U R                  UR                  S5      R                  5       5        U R                  UR                  S5      R                  5       5        U R                  UR                  5       5        U R                  UR                  5       5        UR                  S5      nU R                  UR                  5       5        U R                  SUR                  5       v 5        U R                  UR                  5       5        U R                  UR                  5       5        U R                  UR                  5       5        g 7f)Nr   r(   r   r   )assertRaises	TypeErrorr   r   
ValueErrorr   emptyassertFalsefullr,   r   r   doner   )r   r    put2s      r"   test_maxsizeQueueBasicTest.test_maxsize7   sJ    )V\\4@*fllB?LL#	""AII&a(a(#!uuQx%1557],		$#!s   G?H N)	__name__
__module____qualname____firstlineno__r#   r0   r   r<   __static_attributes__r>   r%   r"   r   r      s     ,.+ " "r%   r   c                       \ rS rSr\S 5       rS rS r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       r\S 5       rSrg)QueueGetTestL   c              #      #    [         R                  " 5       nUR                  S5        U R                  SUR	                  5       v 5        g 7fNr   )r   r   r)   r,   r   r   r    s     r"   test_blocking_getQueueGetTest.test_blocking_getM   s3     LLN	Q1557],s   A
Ac                     [         R                  " 5       nUR                  S5        U R                  SUR	                  5       5        g rH   )r   r   r)   r,   r+   rI   s     r"   test_nonblocking_get!QueueGetTest.test_nonblocking_getS   s.    LLN	QALLN+r%   c                     [         R                  " 5       nU R                  [         R                  UR                  5        g N)r   r   r4   
QueueEmptyr+   rI   s     r"   test_nonblocking_get_exception+QueueGetTest.test_nonblocking_get_exceptionX   s'    LLN&++Q\\:r%   c              #      #    [         R                  " S5      nUR                  S5        UR                  S5      nU R	                  SUR                  5       v 5        U R                  Uv 5        g 7fNr   r   )r   r   r)   r   r,   r   assertIsNoner   r    r   s      r"   test_get_with_putters"QueueGetTest.test_get_with_putters\   sR     LLO	QeeAh1557],9&s   A/A1c           	   #     #    [         R                  " 5       nUR                  S5        U R                  R	                  SUR
                  S5        U R                  R	                  SUR
                  S5        U R                  SUR                  [        SS9S9v 5        U R                  SUR                  [        SS9S9v 5        g 7f)Nr   {Gz?r   {Gz?r(   secondstimeout)	r   r   r   io_loop
call_laterr)   r,   r   r   rI   s     r"   test_blocking_get_wait#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  #    [         R                  " 5       nUR                  [        SS9S9nUR                  5       nU R	                  [
        5         Uv   S S S 5        UR                  S5        U R                  SUv 5        g ! , (       d  f       N4= f7f)Nr[   r]   r_   r   )r   r   r   r   r4   r   r)   r,   )r   r    get_timeoutr   s       r"   test_get_timeoutQueueGetTest.test_get_timeoutm   sp     LLNeeId$;e<eeg|, - 	
Q3Y(	 -,s   ABB.B
BBc              #      #    [         R                  " 5       nUR                  [        SS9S9nUR	                  S5        [
        R                  " S5      v   U R                  SUv 5        g 7f)Nr[   r]   r_   r   r\   )r   r   r   r   r   r   sleepr,   )r   r    r   s      r"   test_get_timeout_preempted'QueueGetTest.test_get_timeout_preemptedx   sP     LLNeeId3e4	aiio3Y(s   A*A,c           
   #     #    [         R                  " S5      n[        S5       Vs/ s H  o!R                  U[	        SS95      PM     nnUR                  S5      nU R                  S[        UR                  5      5        [        R                  " S5      v   U R                  S[        UR                  5      5        U R                  UR                  5       5        UR                  S5        U R                  SUR                  5       v 5        U R                  S[        UR                  5      5        USS   H#  nU R                  [        UR                  5        M%     g s  snf 7f)Nr   
   r[   r]   r\      r   )r   r   r*   r   r   r,   len_puttersr   rj   r8   r:   r   r4   r   resultr   r    r-   r   r   putters         r"   !test_get_clears_timed_out_putters.QueueGetTest.test_get_clears_timed_out_putters   s     LLO>CBiHi55Id34iHeeBiS_-iioS_-$	b	1557],C

O,abkFlFMM: " Is   $E&"E!DE&c              #     #    [         R                  " 5       n[        S5       Vs/ s H/  n[        R                  " UR                  [        SS95      5      PM1     nn[        R                  " UR                  5       5      nU R                  S[        UR                  5      5        [        R                  " S5      v   U R                  S[        UR                  5      5        U R                  UR                  5       5        UR                  5         U R                  S[        UR                  5      5        U H#  nU R                  [        UR                   5        M%     g s  snf 7f)Nrn   r[   r]   ro   r\   r(   )r   r   r*   asyncioensure_futurer   r   r,   rp   _gettersr   rj   r8   r:   r4   r   rr   r   r    r.   r   r   getters         r"   !test_get_clears_timed_out_getters.QueueGetTest.test_get_clears_timed_out_getters   s     LLNKPQS9
KTaG!!!%%	$(?"@A9 	 
 ##AEEG,S_-iioS_-$	C

O,FlFMM: 
s   #E&6E!DE&c              #      ^#    [         R                  " 5       m[        S5       H  nTR                  U5        M     U4S jnU" 5       v nU R	                  U[        [        S5      5      5        g 7f)N   c                  h   >#    / n T  S h  vN nU R                  U5        US:X  d  M"  U s  $  N!
 g 7f)N   )append)resultsr-   r    s     r"   f&QueueGetTest.test_async_for.<locals>.f   s4     G #aq!6"N#1s    20.02202)r   r   r*   r   r,   list)r   r-   r   r   r    s       @r"   test_async_forQueueGetTest.test_async_for   sR     LLNqAEE!H 	# )$uQx.1s   A-A0r>   N)r?   r@   rA   rB   r   rJ   rM   rR   rX   rc   rg   rk   ru   r}   r   rC   r>   r%   r"   rE   rE   L   s    - -
,
; ' ' I I ) ) ) ) ; ; ; ; 2 2r%   rE   c                       \ rS rSr\S 5       rS r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       r\S 5       rSrg)QueuePutTest   c                     [         R                  " 5       nUR                  S5        U R                  SUR	                  5       5        g rH   )r   r   r   r,   r+   rI   s     r"   test_blocking_putQueuePutTest.test_blocking_put   s.    LLN	aALLN+r%   c                     [         R                  " S5      nUR                  S5        U R                  [         R                  UR
                  S5        g rU   )r   r   r   r4   	QueueFullr)   rI   s     r"   test_nonblocking_put_exception+QueuePutTest.test_nonblocking_put_exception   s6    LLO	a&**ALL!<r%   c              #     #    [         R                  " 5       nUR                  5       nUR                  5       nUR                  S5      v   U R	                  SUv 5        UR                  S5      v   U R	                  SUv 5        g 7fNr   r   )r   r   r   r   r,   r   r    get0get1s       r"   test_put_with_getters"QueuePutTest.test_put_with_getters   sd     LLNuuwuuweeAh4Z)eeAh4Z)s   BBc              #   R  #    [         R                  " 5       nUR                  5       nUR                  5       nUR                  S5        [        R
                  v   U R                  SUv 5        UR                  S5        [        R
                  v   U R                  SUv 5        g 7fr   )r   r   r   r)   r   momentr,   r   s       r"   !test_nonblocking_put_with_getters.QueuePutTest.test_nonblocking_put_with_getters   st     LLNuuwuuw	Qjj4Z)	Qjj4Z)s   B%B'c              #   f  ^#    [         R                  " S5      mTR                  S5        U4S jnU R                  R	                  SU5        U R                  R	                  SU5        TR                  S5      TR                  S5      /nU R                  [        S U 5       5      5        Uv   g 7f)Nr   r   c                  &   > T R                  5         g rP   )r   )r    s   r"   get_and_discard<QueuePutTest.test_blocking_put_wait.<locals>.get_and_discard   s    EEGr%   r[   r\   c              3   @   #    U  H  oR                  5       v   M     g 7frP   )r:   ).0r   s     r"   	<genexpr>6QueuePutTest.test_blocking_put_wait.<locals>.<genexpr>   s     7w!VVXXws   )r   r   r)   ra   rb   r   r8   any)r   r   futuresr    s      @r"   test_blocking_put_wait#QueuePutTest.test_blocking_put_wait   s     LLO	Q	 	o6o6558QUU1X&7w778s   B.B1c              #     #    [         R                  " S5      nUR                  S5        UR                  S[	        SS9S9nUR                  S5      nU R                  [        5         Uv   S S S 5        U R                  SUR                  5       5        U R                  SUR                  5       v 5        Uv   g ! , (       d  f       NU= f7f)Nr   r   r[   r]   r_   r(   )
r   r   r)   r   r   r4   r   r,   r+   r   )r   r    put_timeoutr   s       r"   test_put_timeoutQueuePutTest.test_put_timeout   s     LLO	QeeAy'>e?eeAh|, - 	ALLN+1557], 	 -,s   A%C'B;,AC;
C	Cc              #      #    [         R                  " S5      nUR                  S5        UR                  S[	        SS9S9nUR                  5         [        R                  " S5      v   Uv   g 7f)Nr   r   r[   r]   r_   r\   )r   r   r)   r   r   r   r   rj   rW   s      r"   test_put_timeout_preempted'QueuePutTest.test_put_timeout_preempted   sP     LLO	QeeAy6e7	iio	s   A,A.c           
   #     #    [         R                  " S5      n[        S5       Vs/ s H  o!R                  U[	        SS95      PM     nnUR                  S5      nU R                  S[        UR                  5      5        [        R                  " S5      v   U R                  S[        UR                  5      5        U R                  UR                  5       5        UR                  S5        U R                  S[        UR                  5      5        USS   H#  nU R                  [        UR                  5        M%     g s  snf 7f)Nr   rn   r[   r]   r\   ro   r(   )r   r   r*   r   r   r,   rp   rq   r   rj   r8   r:   r4   r   rr   rs   s         r"   !test_put_clears_timed_out_putters.QueuePutTest.test_put_clears_timed_out_putters   s     LLO>CBiHi55Id34iHeeBiS_-iioS_-$	b	C

O,abkFlFMM: " Is   $E"D?C<Ec              #     #    [         R                  " 5       n[        S5       Vs/ s H/  n[        R                  " UR                  [        SS95      5      PM1     nn[        R                  " UR                  5       5      nUR                  5         U R                  S[        UR                  5      5        [        R                  " S5      v   U R                  S[        UR                  5      5        U R                  UR                  5       5        UR                  S5        U R                  S[        UR                  5      5        U R                  SUv 5        U H#  nU R                  [         UR"                  5        M%     g s  snf 7f)Nrn   r[   r]      r\   r   r   )r   r   r*   rx   ry   r   r   r,   rp   rz   r   rj   r8   r:   r   r4   r   rr   r{   s         r"   !test_put_clears_timed_out_getters.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6FD0Fc              #     #    [         R                  " SS9nU R                  UR                  5       5        U R	                  UR                  5       5        UR                  S5        UR                  S5        U R	                  UR                  5       5        U R                  UR                  5       5        U R                  [         R                  UR                  S5        U R                  SUR                  5       5        U R	                  UR                  5       5        U R	                  UR                  5       5        UR                  S5      v   UR                  S5      nU R	                  UR                  5       5        U R                  SUR                  5       v 5        Uv   U R                  UR                  5       5        g 7f)Ng?r   r   r   r(   r'   )r   r   r   r7   r8   r9   r)   r4   r   r,   r+   r   r:   r   rW   s      r"   test_float_maxsizeQueuePutTest.test_float_maxsize  s.     LL%	""	Q	Q#!&**ALL!<ALLN+#"eeAheeAh$1557],	!s   GGr>   N)r?   r@   rA   rB   r   r   r   r   r   r   r   r   r   r   r   rC   r>   r%   r"   r   r      s    , ,
=
 * * 
* 
*       ; ; ; ;" " "r%   r   c                   r    \ rS rSr\R
                  rS r\S 5       r	\S 5       r
\S 5       r\S 5       rSrg)	QueueJoinTesti6  c                 d    U R                  5       nU R                  [        UR                  5        g rP   )queue_classr4   r6   	task_donerI   s     r"   test_task_done_underflow&QueueJoinTest.test_task_done_underflow9  s$    *akk2r%   c              #   T  ^ ^#    T R                  5       m[        S5       H  nTR                  U5        M     ST l        [        R
                  UU 4S j5       nU" 5         U" 5         TR                  5       v   T R                  [        [        S5      5      T R                  5        g 7f)Nd   r   c               3      >#     TR                  5       v n T=R                  U -  sl        TR                  5         [        R                  " [        5       S-  5      v   M\  7f)Nr[   )r   accumulatorr   r   rj   r   )itemr    r   s    r"   worker,QueueJoinTest.test_task_done.<locals>.workerE  sJ     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_doneQueueJoinTest.test_task_done=  s     sALLO  		1 
	1 	ffhU3Z$*:*:;s   B$B(c              #     #    U R                  5       nUR                  S5        [        R                  " UR	                  5       5      nU R                  UR                  5       5        UR                  5       v   U R                  UR                  5       5        [        R                  v   U R                  UR                  5       5        UR                  5         U R                  UR                  5       5        g 7frH   )r   r)   rx   ry   r   r8   r:   r   r   r   r   r   )r   r    r   s      r"   test_task_done_delay"QueueJoinTest.test_task_done_delayS  s      	Q$$QVVX.%eeg%jj%			$s   C7C9c              #   t   #    U R                  5       nUR                  5       v   UR                  5       v   g 7frP   )r   r   rI   s     r"   test_join_empty_queue#QueueJoinTest.test_join_empty_queuea  s)     ffhffhs   68c              #      #    U R                  5       nUR                  S5        U R                  [        5         UR	                  [        SS9S9v   S S S 5        g ! , (       d  f       g = f7f)Nr   r[   r]   r_   )r   r   r4   r   r   r   rI   s     r"   test_join_timeoutQueueJoinTest.test_join_timeoutg  sM     	a|,&&4!8&99 -,,s   7A,A	A,
A)%A,)r   N)r?   r@   rA   rB   r   r   r   r   r   r   r   r   r   rC   r>   r%   r"   r   r   6  s`    ,,K3 < <* % %  
 : :r%   r   c                   <    \ rS rSr\R
                  r\S 5       rSr	g)PriorityQueueJoinTestio  c              #   6  #    U R                  SS9nUR                  S5        UR                  S5        U R                  UR                  5       5        UR	                  S5        UR	                  S5        U R                  SUR                  5       5        U R                  SUR                  5       v 5        U R                  SUR                  5       5        U R                  SUR                  5       v 5        U R                  UR                  5       5        g 7f)Nr(   r   )r   a)r   b)r'   c)r(   d	r   r)   r   r9   r   r,   r+   r   r7   rI   s     r"   r0    PriorityQueueJoinTest.test_orderr  s     Q'	X	X!	h	h1<<>2!%%'M31<<>2!%%'M3	"   DDr>   N)
r?   r@   rA   rB   r   PriorityQueuer   r   r0   rC   r>   r%   r"   r   r   o  s    &&K# #r%   r   c                   <    \ rS rSr\R
                  r\S 5       rSr	g)LifoQueueJoinTesti  c              #   6  #    U R                  SS9nUR                  S5        UR                  S5        U R                  UR                  5       5        UR	                  S5        UR	                  S5        U R                  SUR                  5       5        U R                  SUR                  5       v 5        U R                  SUR                  5       5        U R                  SUR                  5       v 5        U R                  UR                  5       5        g 7f)Nr(   r   r   r   r'   r   rI   s     r"   r0   LifoQueueJoinTest.test_order  s     Q'	Q	Q!	a	aALLN+1557],ALLN+1557],	"r   r>   N)
r?   r@   rA   rB   r   	LifoQueuer   r   r0   rC   r>   r%   r"   r   r     s    ""K# #r%   r   c                   $    \ rS rSr\S 5       rSrg)ProducerConsumerTesti  c              #   .  ^^#    [         R                  " SS9m/ m[        R                  UU4S j5       n[        R                  U4S j5       nU" 5         U" 5       v   TR	                  5       v   U R                  [        [        S5      5      T5        g 7f)Nr'   r   c               3   t   >#     T R                  TR                  5       v 5        TR                  5         M3  7frP   )r   r   r   )historyr    s   r"   consumer=ProducerConsumerTest.test_producer_consumer.<locals>.consumer  s+     aeeg/ s   58c               3   X   >#    [        S5       H  n TR                  U 5      v   M     g 7f)Nrn   )r*   r   )r   r    s    r"   producer=ProducerConsumerTest.test_producer_consumer.<locals>.producer  s"     b	eeDk! "s   '*rn   )r   r   r   r   r   r,   r   r*   )r   r   r   r   r    s      @@r"   test_producer_consumer+ProducerConsumerTest.test_producer_consumer  s{     LL# 
	 
	
 
	" 
	" 	
jffheBi'2s   BBr>   N)r?   r@   rA   rB   r   r   rC   r>   r%   r"   r   r     s    3 3r%   r   __main__)rx   datetimer   r   unittesttornador   r   tornado.genr   tornado.testingr   r	   r   rE   r   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MMO r%   