o
    ,wÖiÉ>  ã                   @   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
 d dlmZmZ d dlmZ d dlmZ G d	d
„ d
ƒZG dd„ dƒZG dd„ deeeƒZG dd„ deeeƒZG dd„ deƒZG dd„ deeƒZG dd„ deeƒZG dd„ deƒZG dd„ de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!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räe '¡  dS dS )0é    N)ÚTestCase)Úget_hubÚLoopExit)Úutil)Úqueue)ÚEmptyÚFull©ÚAsyncResult)ÚAbstractGenericGetTestCasec                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚUsesOnlyOneItemMixinTc                    s®   g ‰ |   d¡}‡ fdd„}tƒ jj}||t t|j¡dƒ ||t t|j¡dƒ t 	d¡ |  
tˆ ƒd¡ | jrA|  ˆ d ˆ ¡ n
|  ˆ d tjˆ ¡ |  ˆ d tjˆ ¡ d S )Né   c                    ó   ˆ   | |Ž ¡ d S ©N©Úappend©ÚfuncÚargs©Úresult© úU/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/gevent/tests/test__queue.pyÚstore_result   ó   zAUsesOnlyOneItemMixin.test_put_nowait_simple.<locals>.store_resulté   é   r   )Ú_makeOner   ÚloopÚrun_callbackr   Úwrap_errorsr   Ú
put_nowaitÚgeventÚsleepÚassertEqualÚlenÚ SUPPORTS_PUTTING_WITHOUT_GETTINGÚassertIsNoneÚassertIsInstancer   ©ÚselfÚqr   r   r   r   r   Útest_put_nowait_simple   s   


z+UsesOnlyOneItemMixin.test_put_nowait_simplec                    sì   g ‰ |   ¡ }t |j¡}‡ fdd„}|  | ¡ |¡ | jr!| j}n| j}|| ¡ |ƒ t 	d¡ |  | ¡ |¡ || ¡ |ƒ t
ƒ j ||jd¡ |  | ¡ |¡ t 	d¡ |  ˆ d g¡ |  | ¡ |¡ || ¡ |ƒ |  | ¡ |¡ d S )Nc                    r   r   r   r   r   r   r   r   .   r   zAUsesOnlyOneItemMixin.test_put_nowait_unlock.<locals>.store_resultçü©ñÒMbP?é
   )r   r"   ÚspawnÚgetÚ
assertTrueÚemptyr&   ÚassertFalseÚfullr#   r   r   r   r!   Úreadyr$   )r*   r+   Úpr   Ú
assertFullr   r   r   Útest_put_nowait_unlock)   s&   

z+UsesOnlyOneItemMixin.test_put_nowait_unlockc                    sV   ˆ   ¡ }‡ fdd„}t ||¡}t d¡ | d¡ t d¡ |jdddks)J ‚d S )Nc                    sJ   t  tjsdnd¡ ˆ  |  ¡ d¡ W d   ƒ dS 1 sw   Y  dS )Nçš™™™™™¹?g      à?Úhi2ÚOK)r"   ÚTimeoutÚ	greentestÚRUNNING_ON_APPVEYORr$   r0   ©r+   ©r*   r   r   ÚwaiterJ   s   
ÿþz3UsesOnlyOneItemMixin.test_send_last.<locals>.waiterç{®Gáz„?r:   r   ©Útimeoutr;   )r   r"   r/   r#   Úputr0   )r*   r+   rA   r6   r   r@   r   Útest_send_lastG   s   


z#UsesOnlyOneItemMixin.test_send_lastN)Ú__name__Ú
__module__Ú__qualname__r&   r,   r8   rF   r   r   r   r   r      s
    r   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚSubscriptMixinc                 C   s   t ‚r   )ÚNotImplementedErrorr@   r   r   r   Ú_getFUTX   s   zSubscriptMixin._getFUTc                 O   s   |   ¡ |i |¤ŽS r   )rL   )r*   r   Úkwargsr   r   r   r   [   r   zSubscriptMixin._makeOnec                 C   s†   dd l }|  ¡ }zt||jƒ}W n ty.   |jdksJ ‚dd l}|  |t |j¡ Y d S w |  	||¡ |  |t t
|t ƒ¡ d S )Nr   ÚChannel)r   rL   ÚgetattrrG   ÚAttributeErrorÚtypesr(   ÚintÚGenericAliasÚassertIsNotÚtype)r*   Ústdlib_queueÚkindÚstdlib_kindrQ   r   r   r   Útest_subscript^   s   ýzSubscriptMixin.test_subscriptN)rG   rH   rI   rL   r   rY   r   r   r   r   rJ   W   s    rJ   c                   @   sl   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )Ú	TestQueuec                 C   ó   t jS r   )r   ÚQueuer@   r   r   r   rL   n   ó   zTestQueue._getFUTc                    s”   g ‰ |   d¡}| d¡ ‡ fdd„}tƒ jj}||t t|j¡ƒ ||t t|j¡ƒ t	 
d¡ |  tˆ ƒd¡ |  ˆ d d¡ |  ˆ d t¡ d S )Nr   é   c                    r   r   r   r   r   r   r   r   v   r   z6TestQueue.test_get_nowait_simple.<locals>.store_resultr   r   )r   rE   r   r   r   r   r    r   Ú
get_nowaitr"   r#   r$   r%   r(   r)   r   r   r   Útest_get_nowait_simpleq   s   



z TestQueue.test_get_nowait_simplec                    sÂ   g ‰ |   d¡}t |jd¡}‡ fdd„}| ¡ sJ |ƒ‚t d¡ | ¡ s)J |ƒ‚tƒ j 	||j
¡ t d¡ | ¡ s?J |ƒ‚ˆ dgksHJ ˆ ƒ‚| ¡ sPJ |ƒ‚|jsWJ |ƒ‚| ¡ s_J |ƒ‚d S )Nr   é   c                    r   r   r   r   r   r   r   r   ˆ   r   z6TestQueue.test_get_nowait_unlock.<locals>.store_resultr   )r   r"   r/   rE   r2   r#   r4   r   r   r   r_   r5   Údead©r*   r+   r6   r   r   r   r   Útest_get_nowait_unlockƒ   s   


z TestQueue.test_get_nowait_unlockc                 C   s<   d| _ |  ¡ }| d¡ |  | ¡ d¡ |  | ¡ d¡ d S )NFÚhi)Úswitch_expectedr   rE   r$   Úpeekr0   ©r*   r+   r   r   r   Útest_send_first–   s
   
zTestQueue.test_send_firstc                    sh   ˆ   ¡ }ˆ  t¡ | ¡  W d   ƒ n1 sw   Y  ‡ fdd„}t ||¡}t d¡ | ¡  d S )Nc                    s   ˆ j t| jdd d S )NrB   rC   )ÚassertRaisesr   rg   r?   r@   r   r   rA   £   s   z)TestQueue.test_peek_empty.<locals>.waiterr9   )r   rj   r   rg   r"   r/   r#   Újoin)r*   r+   rA   Úgr   r@   r   Útest_peek_empty   s   
ÿ
zTestQueue.test_peek_emptyc                 C   s\   |   ¡ }t |j¡}| ¡  t d¡ | d¡ | ¡  |  |j	d u ¡ |  
| ¡ d¡ d S )Nr   r   )r   r"   r/   rg   Ústartr#   rE   rk   r1   Ú	exceptionr$   )r*   r+   rl   r   r   r   Útest_peek_multi_greenlet©   s   

z"TestQueue.test_peek_multi_greenletc                    s¢   |   d¡}g ‰ ‡ fdd„}t ||¡}t d¡ |  ˆ ddg¡ |  | ¡ d¡ t d¡ |  ˆ g d¢¡ |  | ¡ d¡ |  | ¡ d¡ |jdd	d
ksOJ ‚d S )Nr   c                    s@   |   d¡ ˆ  d¡ |   d¡ ˆ  d¡ |   d¡ ˆ  d¡ dS )NÚaÚbÚcr;   )rE   r   r?   ©Úresultsr   r   Úputter·   s   





z'TestQueue.test_max_size.<locals>.putterr   rq   rr   )rq   rr   rs   rs   rC   r;   )r   r"   r/   r#   r$   r0   )r*   r+   rv   r6   r   rt   r   Útest_max_size³   s   
	

zTestQueue.test_max_sizec                    sÎ   |   ¡ }dd„ }g d¢}dd„ |D ƒ‰ t|ƒD ]\}}t ||ˆ | ¡ qt d¡ tƒ ‰‡ ‡fdd„}| |d	 ¡ |  |ƒ d
¡ | |d
 ¡ |  |ƒ d¡ | |d ¡ | |d ¡ |  |ƒ d¡ d S )Nc                 S   ó   |  |  ¡ ¡ d S r   ©Úsetr0   ©r+   Úevtr   r   r   rA   Î   r   z/TestQueue.test_multiple_waiters.<locals>.waiter)Ú1Ú2Ú3Ú4c                 S   s   g | ]}t ƒ ‘qS r   r	   )Ú.0Úxr   r   r   Ú
<listcomp>Ò   s    z3TestQueue.test_multiple_waiters.<locals>.<listcomp>rB   c               	      sP   ˆ D ]!} t  dd¡ |  ¡ }ˆ |¡ W d   ƒ n1 sw   Y  qtˆƒS )Nr-   F)r"   r<   r0   Úaddr%   )Úer‚   ©Úevtsru   r   r   Úcollect_pending_resultsÚ   s   þ€z@TestQueue.test_multiple_waiters.<locals>.collect_pending_resultsr   r   r   r   r^   )r   Ú	enumerater"   r/   r#   rz   rE   r$   )r*   r+   rA   ÚsendingsÚiÚ_rˆ   r   r†   r   Útest_multiple_waitersÊ   s    
zTestQueue.test_multiple_waitersc                 C   sR   |   ¡ }dd„ }tƒ }t |||¡ |  | ¡ d¡ | d¡ |  | ¡ d¡ d S )Nc              	   S   óx   t  dtƒ ¡+ z|  ¡ }| |¡ W n ty!   | d¡ Y n	w W d   ƒ d S W d   ƒ d S 1 s5w   Y  d S ©Nr   ú	timed out©r"   r<   ÚRuntimeErrorr0   rz   ©r+   r|   r   r   r   r   Ú
do_receiveì   ó   ÿÿý"ûz6TestQueue.test_waiters_that_cancel.<locals>.do_receiver   re   )r   r
   r"   r/   r$   r0   rE   )r*   r+   r”   r|   r   r   r   Útest_waiters_that_cancelé   s   
z"TestQueue.test_waiters_that_cancelc                 C   s0   |   ¡ }dd„ }t ||¡ |  | ¡ d¡ d S )Nc                 S   s   |   d¡ d S )NÚsent)rE   r?   r   r   r   Údo_sendþ   s   z0TestQueue.test_senders_that_die.<locals>.do_sendr—   )r   r"   r/   r$   r0   )r*   r+   r˜   r   r   r   Útest_senders_that_dieû   s   zTestQueue.test_senders_that_diec                 C   sx   dd„ }dd„ }|   ¡ }tƒ }tƒ }t |||¡ t |||¡ t d¡ | d¡ |  | ¡ d¡ |  | ¡ d¡ d S )Nc                 S   rx   r   ry   r{   r   r   r   rA     r   z3TestQueue.test_two_waiters_one_dies.<locals>.waiterc              	   S   rŽ   r   r‘   r“   r   r   r   r”   	  r•   z7TestQueue.test_two_waiters_one_dies.<locals>.do_receiver9   re   r   ©r   r
   r"   r/   r#   rE   r$   r0   )r*   rA   r”   r+   Ú	dying_evtÚwaiting_evtr   r   r   Útest_two_waiters_one_dies  s   

z#TestQueue.test_two_waiters_one_diesc                 C   s€   dd„ }|   ¡ }tƒ }tƒ }t |||¡ t |||¡ t d¡ | d¡ |  | ¡ d¡ |  | ¡ d¡ |  | ¡ d¡ d S )Nc              	   S   rŽ   r   r‘   r“   r   r   r   r”     r•   z4TestQueue.test_two_bogus_waiters.<locals>.do_receiver9   r—   r   rš   )r*   r”   r+   Úe1Úe2r   r   r   Útest_two_bogus_waiters  s   

z TestQueue.test_two_bogus_waitersN)rG   rH   rI   rL   r`   rd   ri   rm   rp   rw   r   r–   r™   r   r    r   r   r   r   rZ   l   s    
	rZ   c                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚTestChannelFc                 C   r[   r   )r   rN   r@   r   r   r   rL   4  r]   zTestChannel._getFUTc                    sÚ   g ‰ |   ¡ }t |jd¡}‡ fdd„}|  | ¡ ¡ |  | ¡ ¡ t d¡ |  | ¡ ¡ |  | ¡ ¡ tƒ j	 
||j¡ t d¡ |  | ¡ ¡ |  | ¡ ¡ |  ˆ dg¡ |  | ¡ ¡ |  |j¡ |  | ¡ ¡ d S )Nra   c                    r   r   r   r   r   r   r   r   >  r   z@TestChannel.test_get_nowait_unlock_channel.<locals>.store_resultr-   )r   r"   r/   rE   r1   r2   r4   r#   r   r   r   r_   r$   r5   rb   rc   r   r   r   Útest_get_nowait_unlock_channel7  s"   

z*TestChannel.test_get_nowait_unlock_channelc                 C   s¸   |   ¡ }dd„ }dd„ }tƒ }tƒ }t |||¡}t d¡ |  | ¡  ¡ t |||¡}|  | ¡ d¡ |  | ¡ d¡ t 	d¡ t 
||g¡ W d   ƒ d S 1 sUw   Y  d S )	Nc                 S   s   |  d¡ |  d¡ d S )Nre   Údone)rE   rz   )r|   r+   r   r   r   ÚsenderT  s   
z.TestChannel.test_zero_max_size.<locals>.senderc                 S   s   |  ¡ }|  |¡ d S r   )r0   rz   )r|   r+   r‚   r   r   r   ÚreceiverX  s   z0TestChannel.test_zero_max_size.<locals>.receiverr-   re   r£   r   )r   r
   r"   r/   r#   r1   r5   r$   r0   r<   Újoinall)r*   r+   r¤   r¥   rž   rŸ   Úp1Úp2r   r   r   Útest_zero_max_sizeQ  s   
"ÿzTestChannel.test_zero_max_sizec                    sr   |   ¡ ‰ g ‰‡ ‡fdd„}t |¡}ˆ d¡ ˆ  d¡ ˆ d¡ ˆ  d¡ ˆ d¡ |  g d¢ˆ¡ | ¡  d S )	Nc                      s    ˆ  ˆ  ¡ ¡ ˆ  ˆ  ¡ ¡ d S r   )r   r0   r   ©ÚchannelÚeventsr   r   Úanother_greenletm  s   z/TestChannel.test_send.<locals>.another_greenletÚsendingÚhelloú
sent helloÚworldú
sent world)r®   r¯   r°   r±   r²   )r   r"   r/   r   rE   r$   r0   ©r*   r­   rl   r   rª   r   Ú	test_sendh  s   





zTestChannel.test_sendc                    s€   |   ¡ ‰ g ‰‡ ‡fdd„}t |¡}ˆ d¡ ˆ ˆ  ¡ ¡ ˆ ˆ  ¡ ¡ |  g d¢ˆ¡ t d¡ |  g d¢ˆ¡ | ¡  d S )Nc                      s6   ˆ  d¡ ˆ  d¡ ˆ  d¡ ˆ  d¡ ˆ  d¡ d S )Núsending hellor¯   úsending worldr±   r²   )r   rE   r   rª   r   r   r­   €  s
   



z/TestChannel.test_wait.<locals>.another_greenletÚwaiting)r·   rµ   r¯   r¶   r±   r   )r·   rµ   r¯   r¶   r±   r²   )r   r"   r/   r   r0   r$   r#   r³   r   rª   r   Ú	test_wait|  s   


zTestChannel.test_waitc                 C   s.   |   ¡ }t |jt¡ t|ƒ}|  |g ¡ d S r   )r   r"   r/   rE   ÚStopIterationÚlistr$   )r*   r«   Úrr   r   r   Útest_iterable’  s   zTestChannel.test_iterableN)
rG   rH   rI   r&   rL   r¢   r©   r´   r¸   r¼   r   r   r   r   r¡   1  s    r¡   c                   @   s@   e Zd ZeZdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )ÚTestJoinableQueuec                 C   r[   r   )r   ÚJoinableQueuer@   r   r   r   rL   œ  r]   zTestJoinableQueue._getFUTc                 C   sX   |   ¡ }tƒ }t |j|¡ | ¡ }|  ||¡ |  d|j¡ | 	¡  |  d|j¡ d S )Nr   r   )
r   Úobjectr"   r/   rE   r0   ÚassertIsr$   Úunfinished_tasksÚ	task_done)r*   r«   ÚXr   r   r   r   Útest_task_doneŸ  s   z TestJoinableQueue.test_task_donec                 C   s*  |   ¡ }| d¡ | d¡ | |¡ |  | jj¡ | d¡ W d   ƒ n1 s*w   Y  |  | jj¡ | d¡ W d   ƒ n1 sFw   Y  |r¢|  | jj¡ | ¡  W d   ƒ n1 scw   Y  |  | jj¡ | ¡  W d   ƒ n1 s~w   Y  |  t	¡ | 
¡  W d   ƒ n1 s—w   Y  | ¡  d S |  | ¡ d¡ | 
¡  |  | ¡ d¡ | 
¡  | ¡  |  | jj¡ | ¡  W d   ƒ n1 sÔw   Y  |  | jj¡ | ¡  W d   ƒ n1 sïw   Y  |  | jj¡ | dd¡ W d   ƒ d S 1 sw   Y  d S )NÚLÚOÚEÚWÚLOTg      ð?)r   rE   r!   Úshutdownrj   r   ÚShutDownr0   r_   Ú
ValueErrorrÂ   rk   ÚassertIn)r*   Ú	immediater+   r   r   r   Ú#_shutdown_all_methods_in_one_threadª  sF   


ÿÿ
ÿ
ÿ
ÿ
ÿ
ÿ$ÿz5TestJoinableQueue._shutdown_all_methods_in_one_threadc                 C   ó
   |   d¡S )NF©rÏ   r@   r   r   r   Ú'test_shutdown_all_methods_in_one_threadË  ó   
z9TestJoinableQueue.test_shutdown_all_methods_in_one_threadc                 C   rÐ   )NTrÑ   r@   r   r   r   Ú1test_shutdown_immediate_all_methods_in_one_threadÎ  rÓ   zCTestJoinableQueue.test_shutdown_immediate_all_methods_in_one_threadc                 C   s   d| _ |  ¡ }| ¡  dS )zFTest that join() exits immediately if not jobs were put into the queueFN)rf   r   rk   rh   r   r   r   Útest_issue_45Ò  s   zTestJoinableQueue.test_issue_45N)
rG   rH   rI   r   rL   rÄ   rÏ   rÒ   rÔ   rÕ   r   r   r   r   r½   ™  s    !r½   c                   @   ó   e Zd Zdd„ ZdS )ÚTestLifoQueuec                 C   r[   r   )r   Ú	LifoQueuer@   r   r   r   rL   Ú  r]   zTestLifoQueue._getFUTN©rG   rH   rI   rL   r   r   r   r   r×   Ù  ó    r×   c                   @   rÖ   )ÚTestPriorityQueuec                 C   r[   r   )r   ÚPriorityQueuer@   r   r   r   rL   ß  r]   zTestPriorityQueue._getFUTNrÙ   r   r   r   r   rÛ   Þ  rÚ   rÛ   c                   @   rÖ   )ÚAbstractTestWeakRefMixinc                 C   s,   dd l }|  ¡ }| |¡}|  ||ƒ ¡ d S )Nr   )Úweakrefr   ÚrefrÀ   )r*   rÞ   Úonerß   r   r   r   Útest_weak_referenceå  s   
z,AbstractTestWeakRefMixin.test_weak_referenceN)rG   rH   rI   rá   r   r   r   r   rÝ   ã  s    rÝ   c                   @   s&   e Zd ZeZejZdd„ Zdd„ Z	dS )ÚTestGetInterruptc                 C   s   |   ¡ j|dS )NrC   )r   r0   ©r*   rD   r   r   r   Úwaitò  s   zTestGetInterrupt.waitc                 C   ó   |   ¡ S r   ©rW   r@   r   r   r   r   õ  ó   zTestGetInterrupt._makeOneN)
rG   rH   rI   r   r<   r   r\   rW   rä   r   r   r   r   r   râ   ì  s
    râ   c                   @   ó   e Zd ZejZdS )ÚTestGetInterruptJoinableQueueN©rG   rH   rI   r   r¾   rW   r   r   r   r   ré   ø  ó    
ré   c                   @   rè   )ÚTestGetInterruptLifoQueueN©rG   rH   rI   r   rØ   rW   r   r   r   r   rì   û  rë   rì   c                   @   rè   )ÚTestGetInterruptPriorityQueueN©rG   rH   rI   r   rÜ   rW   r   r   r   r   rî   þ  rë   rî   c                   @   rè   )ÚTestGetInterruptChannelN)rG   rH   rI   r   rN   rW   r   r   r   r   rð     rë   rð   c                       s6   e Zd ZejZeZ‡ fdd„Zdd„ Z	dd„ Z
‡  ZS )ÚTestPutInterruptc                    s   t t| ƒ ¡  |  ¡ | _d S r   )Úsuperrñ   ÚsetUpr   r   r@   ©Ú	__class__r   r   ró   	  s   zTestPutInterrupt.setUpc                 C   s0   | j  ¡ s| j  d¡ | j  ¡ r| j jd|dS )Nr   r   rC   )r   r4   rE   rã   r   r   r   rä     s   

ÿzTestPutInterrupt.waitc                 C   rÐ   )Nr   ræ   r@   r   r   r   r     rÓ   zTestPutInterrupt._makeOne)rG   rH   rI   r   r\   rW   r   r<   ró   rä   r   Ú__classcell__r   r   rô   r   rñ     s    rñ   c                   @   rè   )ÚTestPutInterruptJoinableQueueNrê   r   r   r   r   r÷     rë   r÷   c                   @   rè   )ÚTestPutInterruptLifoQueueNrí   r   r   r   r   rø     rë   rø   c                   @   rè   )ÚTestPutInterruptPriorityQueueNrï   r   r   r   r   rù     rë   rù   c                   @   s   e Zd ZejZdd„ ZdS )ÚTestPutInterruptChannelc                 C   rå   r   ræ   r@   r   r   r   r   "  rç   z TestPutInterruptChannel._makeOneN)rG   rH   rI   r   rN   rW   r   r   r   r   r   rú     s    rú   c                   @   s"   e Zd ZejZdd„ ZeZeZdS )ÚTestGetInterruptSimpleQueuec                 C   s
   t  d¡‚)NzNot supported)ÚunittestÚSkipTestr@   r   r   r   Útest_raises_timeout_Timeout+  rÓ   z7TestGetInterruptSimpleQueue.test_raises_timeout_TimeoutN)	rG   rH   rI   r   ÚSimpleQueuerW   rþ   Ú*test_raises_timeout_Timeout_exc_customizedÚtest_outer_timeout_is_not_lostr   r   r   r   rû   (  s
    rû   Ú__main__)(rü   Úgevent.testingÚtestingr=   r   r"   Ú
gevent.hubr   r   r   r   Úgevent.queuer   r   Úgevent.eventr
   Úgevent.testing.timingr   r   rJ   rZ   r¡   r½   r×   rÛ   r¿   rÝ   râ   ré   rì   rî   rð   rñ   r÷   rø   rù   rú   rû   rG   Úmainr   r   r   r   Ú<module>   sD    I Fh@		
ÿ