
    <|h33                     6   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
 d dlmZmZ d dlmZ d dl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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 G d# d$e      Z  G d% d&e      Z! G d' d(e      Z" e#e
d)      r G d* d+e      Z$[e%d,k(  r ejL                          yy)-    N)TestCase)get_hubLoopExit)util)queue)EmptyFull)AsyncResult)AbstractGenericGetTestCasec                   N    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)	TestQueuec                     d| _         t        j                         }|j                  d       | j	                  |j                         d       | j	                  |j                         d       y )NFhi)switch_expectedr   QueueputassertEqualpeekgetselfqs     W/var/www/html/test/engine/venv/lib/python3.12/site-packages/gevent/tests/test__queue.pytest_send_firstzTestQueue.test_send_first   sL    $KKM	d4($'    c                 "    t        j                         } j                  t              5  |j	                          d d d         fd}t        j                  ||      }t        j                  d       |j                          y # 1 sw Y   JxY w)Nc                 J    j                  t        | j                  d       y )N{Gz?timeout)assertRaisesr   r   r   r   s    r   waiterz)TestQueue.test_peek_empty.<locals>.waiter   s    eQVVT:r   皙?)	r   r   r!   r   r   geventspawnsleepjoin)r   r   r#   gs   `   r   test_peek_emptyzTestQueue.test_peek_empty   sd    KKMx( 	FFH		;LL#S		 	s   BBc                 p   t        j                         }t        j                  |j                        }|j                          t        j                  d       |j                  d       |j                          | j                  |j                  d u        | j                  |j	                         d       y )Nr      )r   r   r%   r&   r   startr'   r   r(   
assertTrue	exceptionr   )r   r   r)   s      r   test_peek_multi_greenletz"TestQueue.test_peek_multi_greenlet$   sr    KKMLL 		Q	a	t+,1%r   c                     t        j                         } fd}t        j                  ||      }t        j                  d       |j                  d       t        j                  d       |j                  d      dk(  sJ y )Nc                     t        j                  t        j                  sdnd      5  j	                  | j                         d       d d d        y# 1 sw Y   yxY w)Nr$   g      ?hi2OK)r%   Timeout	greentestRUNNING_ON_APPVEYORr   r   r"   s    r   r#   z(TestQueue.test_send_last.<locals>.waiter1   sE    9+H+HcR 1  %011s   !AAr   r3   r   r   r4   )r   r   r%   r&   r'   r   r   )r   r   r#   ps   `   r   test_send_lastzTestQueue.test_send_last.   sa    KKM	
 LL#T	eTuuQu4'''r   c                    t        j                  d      }g fd}t        j                  ||      }t        j                  d       | j                  ddg       | j                  |j                         d       t        j                  d       | j                  g d       | j                  |j                         d       | j                  |j                         d       |j                  d      d	k(  sJ y )
N   c                     | j                  d       j                  d       | j                  d       j                  d       | j                  d       j                  d       y)Nabcr4   )r   append)r   resultss    r   putterz'TestQueue.test_max_size.<locals>.putter@   sK    EE#JNN3EE#JNN3EE#JNN3r   r   r=   r>   )r=   r>   r?   r?   r   r4   )r   r   r%   r&   r'   r   r   )r   r   rB   r8   rA   s       @r   test_max_sizezTestQueue.test_max_size<   s    KKN	 LL#Q3*-#&Q/2#&#&uuQu4'''r   c                 (   t        j                         }d }d }t               }t               }t        j                  |||      }t        j
                  d       | j                  |j                                 t        j                  |||      }| j                  |j                         d       | j                  |j                         d       t        j                  d      5  t        j                  ||g       d d d        y # 1 sw Y   y xY w)Nc                 H    |j                  d       | j                  d       y )Nr   done)r   set)evtr   s     r   senderz,TestQueue.test_zero_max_size.<locals>.senderV   s    EE$KGGFOr   c                 F    |j                         }| j                  |       y N)r   rG   )rH   r   xs      r   receiverz.TestQueue.test_zero_max_size.<locals>.receiverZ   s    AGGAJr   MbP?r   rF   r   )r   Channelr
   r%   r&   r'   r.   readyr   r   r5   joinall)r   r   rI   rM   e1e2p1p2s           r   test_zero_max_sizezTestQueue.test_zero_max_sizeS   s    MMO		 ]]\\&"a(UBHHJ'\\(B*4(6*^^A 	%NNB8$	% 	% 	%s   'DDc                 F  	 t        j                         }d }g d}|D cg c]  }t                c}t        |      D ]  \  }}t	        j
                  |||          ! t	        j                  d       t               		fd}|j                  |d          | j                   |       d       |j                  |d          | j                   |       d       |j                  |d          |j                  |d          | j                   |       d	       y c c}w )
Nc                 B    |j                  | j                                y rK   rG   r   r   rH   s     r   r#   z/TestQueue.test_multiple_waiters.<locals>.waitern       GGAEEGr   )1234r   c                      D ]B  } t        j                  dd      5  | j                         }j                  |       d d d        D t	              S # 1 sw Y   YxY w)NrN   F)r%   r5   r   addlen)erL   evtsrA   s     r   collect_pending_resultsz@TestQueue.test_multiple_waiters.<locals>.collect_pending_resultsz   s\     #^^E51 #AKKN# ## w<# #s   "AA	r   r,   r;         )
r   r   r
   	enumerater%   r&   r'   rG   r   r   )
r   r   r#   sendingsrL   i_re   rd   rA   s
           @@r   test_multiple_waiterszTestQueue.test_multiple_waitersj   s    KKM	 ('/0!0h' 	-DAqLLDG,	- 	T%	  	
hqk02A6	hqk02A6	hqk	hqk02A6+ 1s   Dc                    t        j                         }d }t               }t        j                  |||       | j                  |j                         d       |j                  d       | j                  |j                         d       y )Nc                     t        j                  dt                     5  	 | j                         }|j	                  |       d d d        y # t        $ r |j	                  d       Y %w xY w# 1 sw Y   y xY wNr   	timed outr%   r5   RuntimeErrorr   rG   r   rH   results      r   
do_receivez6TestQueue.test_waiters_that_cancel.<locals>.do_receive   d    <>2 ))UUWFGGFO) ) $ )GGK()	) )(   A+!AA(%A+'A((A++A4rp   r   )r   r   r
   r%   r&   r   r   r   )r   r   ru   rH   s       r   test_waiters_that_cancelz"TestQueue.test_waiters_that_cancel   sb    KKM	) mZC(K0	d$'r   c                     t        j                         }d }t        j                  ||       | j	                  |j                         d       y )Nc                 &    | j                  d       y )Nsent)r   )r   s    r   do_sendz0TestQueue.test_senders_that_die.<locals>.do_send   s    EE&Mr   r{   )r   r   r%   r&   r   r   )r   r   r|   s      r   test_senders_that_diezTestQueue.test_senders_that_die   s8    KKM	 	Wa &)r   c                    d }d }t        j                         }t               }t               }t        j                  |||       t        j                  |||       t        j
                  d       |j                  d       | j                  |j                         d       | j                  |j                         d       y )Nc                 B    |j                  | j                                y rK   rY   rZ   s     r   r#   z3TestQueue.test_two_waiters_one_dies.<locals>.waiter   r[   r   c                     t        j                  dt                     5  	 | j                         }|j	                  |       d d d        y # t        $ r |j	                  d       Y %w xY w# 1 sw Y   y xY wro   rq   rs   s      r   ru   z7TestQueue.test_two_waiters_one_dies.<locals>.do_receive   rv   rw   r$   r   rp   	r   r   r
   r%   r&   r'   r   r   r   )r   r#   ru   r   	dying_evtwaiting_evts         r   test_two_waiters_one_diesz#TestQueue.test_two_waiters_one_dies   s    		) KKMM	!mZI.VQ,S	d+6*D1r   c                    d }t        j                         }t               }t               }t        j                  |||       t        j                  |||       t        j
                  d       |j                  d       | j                  |j                         d       | j                  |j                         d       | j                  |j                         d       y )Nc                     t        j                  dt                     5  	 | j                         }|j	                  |       d d d        y # t        $ r |j	                  d       Y %w xY w# 1 sw Y   y xY wro   rq   rs   s      r   ru   z4TestQueue.test_two_bogus_waiters.<locals>.do_receive   rv   rw   r$   r{   rp   r   )r   ru   r   rR   rS   s        r   test_two_bogus_waitersz TestQueue.test_two_bogus_waiters   s    	) KKM]]ZB'ZB'S	f;/;/&)r   N)__name__
__module____qualname__r   r*   r0   r9   rC   rV   rl   rx   r}   r   r    r   r   r   r      s9    (
&((.%.7>($*2.*r   r   c                       e Zd Zd Zd Zd Zy)TestChannelc                 \   t        j                         g fd}t        j                  |      }j	                  d       j                  d       j	                  d       j                  d       j	                  d       | j                  g d       |j                          y )Nc                      j                   j                                j                   j                                y rK   )r@   r   channeleventss   r   another_greenletz/TestChannel.test_send.<locals>.another_greenlet   s'    MM'++-(MM'++-(r   sendinghello
sent helloworld
sent world)r   r   r   r   r   )r   rO   r%   r&   r@   r   r   r   r   r   r)   r   r   s      @@r   	test_sendzTestChannel.test_send   s    --/	) LL)*i Gl#Gl#RTZ[	r   c                    t        j                         g fd}t        j                  |      }j	                  d       j	                  j                                j	                  j                                | j                  g d       t        j                  d       | j                  g d       |j                          y )Nc                      j                  d        j                  d       j                  d        j                  d       j                  d       y )Nsending hellor   sending worldr   r   )r@   r   r   s   r   r   z/TestChannel.test_wait.<locals>.another_greenlet   s?    MM/*KK MM/*KK MM,'r   waiting)r   r   r   r   r   r   )r   r   r   r   r   r   )r   rO   r%   r&   r@   r   r   r'   r   s      @@r   	test_waitzTestChannel.test_wait   s    --/	( LL)*i gkkm$gkkm$XZ`aQfhno	r   c                     t        j                         }t        j                  |j                  t
               t        |      }| j                  |g        y rK   )r   rO   r%   r&   r   StopIterationlistr   )r   r   rs      r   test_iterablezTestChannel.test_iterable   s8    --/W[[-0MBr   N)r   r   r   r   r   r   r   r   r   r   r      s    (, r   r   c                       e Zd Zd Zy)TestJoinableQueuec                 T   t        j                         }t               }t        j                  |j
                  |       |j                         }| j                  ||       | j                  d|j                         |j                          | j                  d|j                         y )Nr,   r   )r   JoinableQueueobjectr%   r&   r   r   assertIsr   unfinished_tasks	task_done)r   r   Xrt   s       r   test_task_donez TestJoinableQueue.test_task_done  sz    %%'HW[[!$fa G445G445r   N)r   r   r   r   r   r   r   r   r     s    6r   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)
TestNoWaitc                    g t        j                  d      }fd}t               j                  j                  } ||t        j                  t        |j                        d        ||t        j                  t        |j                        d       t        j                  d       t              dk(  sJ        d   J        t        d   t         j                        sJ        y )Nr,   c                 .    j                   | |        y rK   r@   funcargsrt   s     r   store_resultz7TestNoWait.test_put_nowait_simple.<locals>.store_result      MM$+&r   r;   rf   r   )r   r   r   looprun_callbackr   wrap_errorsr	   
put_nowaitr%   r'   rb   
isinstancer   r   r   r   rt   s       @r   test_put_nowait_simplez!TestNoWait.test_put_nowait_simple  s    KKN	' y~~22\4#3#3D!,,#GK\4#3#3D!,,#GKQ6{a''ay (&( &)UZZ08&80r   c                    g t        j                  d      }|j                  d       fd}t               j                  j
                  } ||t        j                  t        |j                                ||t        j                  t        |j                               t        j                  d       t              dk(  sJ        d   dk(  sJ        t        d   t         j                        sJ        y )Nr,   rg   c                 .    j                   | |        y rK   r   r   s     r   r   z7TestNoWait.test_get_nowait_simple.<locals>.store_result&  r   r   r   r;   )r   r   r   r   r   r   r   r   r   
get_nowaitr%   r'   rb   r   r   s       @r   test_get_nowait_simplez!TestNoWait.test_get_nowait_simple!  s    KKN	a	' y~~22\4#3#3E1<<#HI\4#3#3E1<<#HIQ6{a''ayA~%v%~&)U[[19691r   c                 T   g t        j                  d      }t        j                  |j                  d      }fd}|j                         sJ |       t        j                  d       |j                         sJ |       t               j                  j                  ||j                         t        j                  d       |j                         sJ |       dgk(  sJ        |j                         sJ |       |j                  sJ |       |j                         sJ |       y )Nr,      c                 .    j                   | |        y rK   r   r   s     r   r   z7TestNoWait.test_get_nowait_unlock.<locals>.store_result8  r   r   r   )r   r   r%   r&   r   emptyr'   fullr   r   r   r   rP   deadr   r   r8   r   rt   s       @r   test_get_nowait_unlockz!TestNoWait.test_get_nowait_unlock3  s    KKNLL"	' wwy!yQvvxx	##L!,,?Qwwy!y!}$f$}wwy!yvvqvwwy!yr   c                 x   g t        j                         }t        j                  |j                  d      }fd}| j                  |j                                | j                  |j                                t        j                  d       | j                  |j                                | j                  |j                                t               j                  j                  ||j                         t        j                  d       | j                  |j                                | j                  |j                                | j                  dg       | j                  |j                                | j                  |j                         | j                  |j                                y )Nr   c                 .    j                   | |        y rK   r   r   s     r   r   z?TestNoWait.test_get_nowait_unlock_channel.<locals>.store_resultM  r   r   rN   )r   rO   r%   r&   r   r.   r   r   r'   r   r   r   r   r   rP   r   r   s       @r   test_get_nowait_unlock_channelz)TestNoWait.test_get_nowait_unlock_channelF  s    MMOLL"	' 		"!U	"!	##L!,,?U	"!!%	"	"r   c                 R   g t        j                         }t        j                  |j                        }fd}| j                  |j                         |       | j                  |j                         |       t        j                  d       | j                  |j                         |       | j                  |j                         |       t               j                  j                  ||j                  d       | j                  |j                         |       t        j                  d       | j                  d g       | j                  |j                         |       | j                  |j                         |       | j                  |j                         |       y )Nc                 .    j                   | |        y rK   r   r   s     r   r   z7TestNoWait.test_put_nowait_unlock.<locals>.store_resultf  r   r   rN   
   )r   r   r%   r&   r   r.   r   assertFalser   r'   r   r   r   r   rP   r   r   s       @r   test_put_nowait_unlockz!TestNoWait.test_put_nowait_unlocka  s   KKMLL	' 		1%1%U	1%1%	##L!,,CA&U$(	1%1%	1%r   N)r   r   r   r   r   r   r   r   r   r   r   r   r     s    9 :$&#6&r   r   c                       e Zd Zd Zy)TestJoinEmptyc                 Z    d| _         t        j                         }|j                          y)zFTest that join() exits immediately if not jobs were put into the queueFN)r   r   r   r(   r   s     r   test_issue_45zTestJoinEmpty.test_issue_45}  s!    $!	r   N)r   r   r   r   r   r   r   r   r   {  s    r   r   c                       e Zd Zd Zy)AbstractTestWeakRefMixinc                 |    dd l }| j                         }|j                  |      }| j                  | |              y )Nr   )weakref_makeOnerefr   )r   r   oner   s       r   test_weak_referencez,AbstractTestWeakRefMixin.test_weak_reference  s.    mmokk#c35!r   N)r   r   r   r   r   r   r   r   r     s    "r   r   c                   4    e Zd ZeZej                  Zd Zd Z	y)TestGetInterruptc                 B    | j                         j                  |      S )Nr   )r   r   r   r    s     r   waitzTestGetInterrupt.wait  s    }}""7"33r   c                 "    | j                         S rK   kindr   s    r   r   zTestGetInterrupt._makeOne      yy{r   N)
r   r   r   r   r5   r   r   r   r   r   r   r   r   r   r     s    G;;D4r   r   c                   $    e Zd Zej                  Zy)TestGetInterruptJoinableQueueNr   r   r   r   r   r   r   r   r   r   r         Dr   r   c                   $    e Zd Zej                  Zy)TestGetInterruptLifoQueueNr   r   r   r   	LifoQueuer   r   r   r   r   r         ??Dr   r   c                   $    e Zd Zej                  Zy)TestGetInterruptPriorityQueueNr   r   r   r   PriorityQueuer   r   r   r   r   r     r   r   r   c                   $    e Zd Zej                  Zy)TestGetInterruptChannelN)r   r   r   r   rO   r   r   r   r   r   r     s    ==Dr   r   c                   F     e Zd Zej                  ZeZ fdZd Z	d Z
 xZS )TestPutInterruptc                 T    t         t        |           | j                         | _        y rK   )superr   setUpr   r   )r   	__class__s    r   r   zTestPutInterrupt.setUp  s    +-]]_
r   c                     | j                   j                         s6| j                   j                  d       | j                   j                         s6| j                   j                  d|      S )Nr,   r;   r   )r   r   r   r   s     r   r   zTestPutInterrupt.wait  sG    **//#JJNN1 **//#zz~~a~11r   c                 $    | j                  d      S )Nr,   r   r   s    r   r   zTestPutInterrupt._makeOne  s    yy|r   )r   r   r   r   r   r   r	   r5   r   r   r   __classcell__)r   s   @r   r   r     s     ;;DG%2
r   r   c                   $    e Zd Zej                  Zy)TestPutInterruptJoinableQueueNr   r   r   r   r  r    r   r   r  c                   $    e Zd Zej                  Zy)TestPutInterruptLifoQueueNr   r   r   r   r  r    r   r   r  c                   $    e Zd Zej                  Zy)TestPutInterruptPriorityQueueNr   r   r   r   r  r    r   r   r  c                   *    e Zd Zej                  Zd Zy)TestPutInterruptChannelc                 "    | j                         S rK   r   r   s    r   r   z TestPutInterruptChannel._makeOne  r   r   N)r   r   r   r   rO   r   r   r   r   r   r
  r
    s    ==Dr   r
  SimpleQueuec                   2    e Zd Zej                  Zd ZeZeZy)TestGetInterruptSimpleQueuec                 ,    t        j                  d      )NzNot supported)unittestSkipTestr   s    r   test_raises_timeout_Timeoutz7TestGetInterruptSimpleQueue.test_raises_timeout_Timeout  s    ##O44r   N)	r   r   r   r   r  r   r  *test_raises_timeout_Timeout_exc_customizedtest_outer_timeout_is_not_lostr   r   r   r  r    s!      	5 6Q2)D&r   r  __main__)'r  gevent.testingtestingr6   r   r%   
gevent.hubr   r   r   r   gevent.queuer   r	   gevent.eventr
   gevent.testing.timingr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r
  hasattrr  r   mainr   r   r   <module>r     s2    " #  (   $ $ <~* ~*B0 ( 0 d
6 
6i& i&XH "v "
/1K 
$4  0 $4 . 1 "$4  0 $4 .  5- E&6 E  zINN r   