o
    ÑtPf33  ã                   @   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
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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#e
d)ƒrÊG d*d+„ d+eƒZ$[e%d,krÕe &¡  dS dS )-é    N)ÚTestCase)Úget_hubÚLoopExit)Úutil)Úqueue)ÚEmptyÚFull©ÚAsyncResult)ÚAbstractGenericGetTestCasec                   @   sd   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S )Ú	TestQueuec                 C   s<   d| _ t ¡ }| d¡ |  | ¡ d¡ |  | ¡ d¡ d S )NFÚhi)Úswitch_expectedr   ÚQueueÚputÚassertEqualÚpeekÚget©ÚselfÚq© r   úY/var/www/html/humari/django-venv/lib/python3.10/site-packages/gevent/tests/test__queue.pyÚtest_send_first   s
   
zTestQueue.test_send_firstc                    sh   t  ¡ }ˆ  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 )Nç{®Gáz„?©Útimeout)ÚassertRaisesr   r   ©r   ©r   r   r   Úwaiter   s   z)TestQueue.test_peek_empty.<locals>.waiterçš™™™™™¹?)	r   r   r   r   r   ÚgeventÚspawnÚsleepÚjoin)r   r   r    Úgr   r   r   Útest_peek_empty   s   
ÿ
zTestQueue.test_peek_emptyc                 C   s\   t  ¡ }t |j¡}| ¡  t d¡ | d¡ | ¡  |  	|j
d u ¡ |  | ¡ d¡ d S )Nr   é   )r   r   r"   r#   r   Ústartr$   r   r%   Ú
assertTrueÚ	exceptionr   )r   r   r&   r   r   r   Útest_peek_multi_greenlet$   s   

z"TestQueue.test_peek_multi_greenletc                    sV   t  ¡ }‡ 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 )Nr!   g      à?Úhi2ÚOK)r"   ÚTimeoutÚ	greentestÚRUNNING_ON_APPVEYORr   r   r   r   r   r   r    1   s   
ÿþz(TestQueue.test_send_last.<locals>.waiterr   r-   r   r   r.   )r   r   r"   r#   r$   r   r   )r   r   r    Úpr   r   r   Útest_send_last.   s   


zTestQueue.test_send_lastc                    s¢   t  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 )Né   c                    s@   |   d¡ ˆ  d¡ |   d¡ ˆ  d¡ |   d¡ ˆ  d¡ dS )NÚaÚbÚcr.   )r   Úappendr   ©Úresultsr   r   Úputter@   s   





z'TestQueue.test_max_size.<locals>.putterr   r5   r6   )r5   r6   r7   r7   r   r.   )r   r   r"   r#   r$   r   r   )r   r   r;   r2   r   r9   r   Útest_max_size<   s   
	

zTestQueue.test_max_sizec                 C   s¸   t  ¡ }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 )Nr   Údone)r   Úset)Úevtr   r   r   r   ÚsenderV   s   
z,TestQueue.test_zero_max_size.<locals>.senderc                 S   s   |  ¡ }|  |¡ d S ©N)r   r>   )r?   r   Úxr   r   r   ÚreceiverZ   s   z.TestQueue.test_zero_max_size.<locals>.receiverçü©ñÒMbP?r   r=   r   )r   ÚChannelr
   r"   r#   r$   r*   Úreadyr   r   r/   Újoinall)r   r   r@   rC   Úe1Úe2Úp1Úp2r   r   r   Útest_zero_max_sizeS   s   
"ÿzTestQueue.test_zero_max_sizec                    sÎ   t  ¡ }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 rA   ©r>   r   ©r   r?   r   r   r   r    n   ó   z/TestQueue.test_multiple_waiters.<locals>.waiter)Ú1Ú2Ú3Ú4c                 S   s   g | ]}t ƒ ‘qS r   r	   )Ú.0rB   r   r   r   Ú
<listcomp>r   s    z3TestQueue.test_multiple_waiters.<locals>.<listcomp>r   c               	      sP   ˆ D ]!} t  dd¡ |  ¡ }ˆ |¡ W d   ƒ n1 sw   Y  qtˆƒS )NrD   F)r"   r/   r   ÚaddÚlen)ÚerB   ©Úevtsr:   r   r   Úcollect_pending_resultsz   s   þ€z@TestQueue.test_multiple_waiters.<locals>.collect_pending_resultsr   r(   r4   é   é   )	r   r   Ú	enumerater"   r#   r$   r>   r   r   )r   r   r    ÚsendingsÚiÚ_r\   r   rZ   r   Útest_multiple_waitersj   s    
zTestQueue.test_multiple_waitersc                 C   sR   t  ¡ }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/   ÚRuntimeErrorr   r>   ©r   r?   Úresultr   r   r   Ú
do_receiveŒ   ó   ÿÿý"ûz6TestQueue.test_waiters_that_cancel.<locals>.do_receiverf   r   )r   r   r
   r"   r#   r   r   r   )r   r   rk   r?   r   r   r   Útest_waiters_that_cancel‰   s   
z"TestQueue.test_waiters_that_cancelc                 C   s0   t  ¡ }dd„ }t ||¡ |  | ¡ d¡ d S )Nc                 S   s   |   d¡ d S )NÚsent)r   r   r   r   r   Údo_sendž   s   z0TestQueue.test_senders_that_die.<locals>.do_sendrn   )r   r   r"   r#   r   r   )r   r   ro   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 |||¡ t d¡ | d¡ |  | ¡ d¡ |  | ¡ d¡ d S )Nc                 S   rM   rA   rN   rO   r   r   r   r    ¦   rP   z3TestQueue.test_two_waiters_one_dies.<locals>.waiterc              	   S   rd   re   rg   ri   r   r   r   rk   ©   rl   z7TestQueue.test_two_waiters_one_dies.<locals>.do_receiver!   r   rf   ©	r   r   r
   r"   r#   r$   r   r   r   )r   r    rk   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 |||¡ t d¡ | d¡ |  | ¡ d¡ |  | ¡ d¡ |  | ¡ d¡ d S )Nc              	   S   rd   re   rg   ri   r   r   r   rk   ¼   rl   z4TestQueue.test_two_bogus_waiters.<locals>.do_receiver!   rn   rf   rq   )r   rk   r   rH   rI   r   r   r   Útest_two_bogus_waiters»   s   

z TestQueue.test_two_bogus_waitersN)Ú__name__Ú
__module__Ú__qualname__r   r'   r,   r3   r<   rL   rc   rm   rp   rt   ru   r   r   r   r   r      s    
	r   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTestChannelc                    sr   t  ¡ ‰ g ‰‡ ‡fdd„}t |¡}ˆ d¡ ˆ  d¡ ˆ d¡ ˆ  d¡ ˆ d¡ |  g d¢ˆ¡ | ¡  d S )	Nc                      s    ˆ  ˆ  ¡ ¡ ˆ  ˆ  ¡ ¡ d S rA   )r8   r   r   ©ÚchannelÚeventsr   r   Úanother_greenlet×   s   z/TestChannel.test_send.<locals>.another_greenletÚsendingÚhelloú
sent helloÚworldú
sent world)r~   r   r€   r   r‚   )r   rE   r"   r#   r8   r   r   r   ©r   r}   r&   r   rz   r   Ú	test_sendÒ   s   





zTestChannel.test_sendc                    s€   t  ¡ ‰ 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‚   )r8   r   r   rz   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   rE   r"   r#   r8   r   r   r$   rƒ   r   rz   r   Ú	test_waitæ   s   


zTestChannel.test_waitc                 C   s.   t  ¡ }t |jt¡ t|ƒ}|  |g ¡ d S rA   )r   rE   r"   r#   r   ÚStopIterationÚlistr   )r   r{   Úrr   r   r   Útest_iterableü   s   zTestChannel.test_iterableN)rv   rw   rx   r„   rˆ   rŒ   r   r   r   r   ry   Ð   s    ry   c                   @   ó   e Zd Zdd„ ZdS )ÚTestJoinableQueuec                 C   sX   t  ¡ }tƒ }t |j|¡ | ¡ }|  ||¡ |  d|j	¡ | 
¡  |  d|j	¡ d S )Nr(   r   )r   ÚJoinableQueueÚobjectr"   r#   r   r   ÚassertIsr   Úunfinished_tasksÚ	task_done)r   r{   ÚXrj   r   r   r   Útest_task_done  s   z TestJoinableQueue.test_task_doneN)rv   rw   rx   r•   r   r   r   r   rŽ     ó    rŽ   c                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )Ú
TestNoWaitc                    sž   g ‰ t  d¡}‡ fdd„}tƒ jj}||t t|j¡dƒ ||t t|j¡dƒ t	 
d¡ tˆ ƒdks7J ˆ ƒ‚ˆ d d u sAJ ˆ ƒ‚tˆ d t jƒsMJ ˆ ƒ‚d S )Nr(   c                    ó   ˆ   | |Ž ¡ d S rA   ©r8   ©ÚfuncÚargs©rj   r   r   Ústore_result  rP   z7TestNoWait.test_put_nowait_simple.<locals>.store_resultr4   r]   r   )r   r   r   ÚloopÚrun_callbackr   Úwrap_errorsr   Ú
put_nowaitr"   r$   rX   Ú
isinstance©r   r   rž   r    r   r   r   Útest_put_nowait_simple  s   


z!TestNoWait.test_put_nowait_simplec                    s¤   g ‰ t  d¡}| d¡ ‡ fdd„}tƒ jj}||t t|j	¡ƒ ||t t|j	¡ƒ t
 d¡ tˆ ƒdks:J ˆ ƒ‚ˆ d dksDJ ˆ ƒ‚tˆ d t jƒsPJ ˆ ƒ‚d S )Nr(   r^   c                    r˜   rA   r™   rš   r   r   r   rž   &  rP   z7TestNoWait.test_get_nowait_simple.<locals>.store_resultr   r4   )r   r   r   r   rŸ   r    r   r¡   r   Ú
get_nowaitr"   r$   rX   r£   r¤   r   r   r   Útest_get_nowait_simple!  s   



z!TestNoWait.test_get_nowait_simplec                    sÂ   g ‰ t  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˜   rA   r™   rš   r   r   r   rž   8  rP   z7TestNoWait.test_get_nowait_unlock.<locals>.store_resultr   )r   r   r"   r#   r   Úemptyr$   Úfullr   rŸ   r    r¦   rF   Údead©r   r   r2   rž   r   r   r   Útest_get_nowait_unlock3  s   


z!TestNoWait.test_get_nowait_unlockc                    sÚ   g ‰ t  ¡ }t |jd¡}‡ fdd„}|  | ¡ ¡ |  | ¡ ¡ t d¡ |  | ¡ ¡ |  | ¡ ¡ t	ƒ j
 ||j¡ t d¡ |  | ¡ ¡ |  | ¡ ¡ |  ˆ dg¡ |  | ¡ ¡ |  |j¡ |  | ¡ ¡ d S )Nr¨   c                    r˜   rA   r™   rš   r   r   r   rž   M  rP   z?TestNoWait.test_get_nowait_unlock_channel.<locals>.store_resultrD   )r   rE   r"   r#   r   r*   r©   rª   r$   r   rŸ   r    r¦   r   rF   r«   r¬   r   r   r   Útest_get_nowait_unlock_channelF  s"   

z)TestNoWait.test_get_nowait_unlock_channelc                    sÞ   g ‰ t  ¡ }t |j¡}‡ fdd„}|  | ¡ |¡ |  | ¡ |¡ t 	d¡ |  | ¡ |¡ |  | ¡ |¡ t
ƒ j ||jd¡ |  | ¡ |¡ t 	d¡ |  ˆ d g¡ |  | ¡ |¡ |  | ¡ |¡ |  | ¡ |¡ d S )Nc                    r˜   rA   r™   rš   r   r   r   rž   f  rP   z7TestNoWait.test_put_nowait_unlock.<locals>.store_resultrD   é
   )r   r   r"   r#   r   r*   r©   ÚassertFalserª   r$   r   rŸ   r    r¢   rF   r   r¬   r   r   r   Útest_put_nowait_unlocka  s    

z!TestNoWait.test_put_nowait_unlockN)rv   rw   rx   r¥   r§   r­   r®   r±   r   r   r   r   r—     s    r—   c                   @   r   )ÚTestJoinEmptyc                 C   s   d| _ t ¡ }| ¡  dS )zFTest that join() exits immediately if not jobs were put into the queueFN)r   r   r   r%   r   r   r   r   Útest_issue_45}  s   zTestJoinEmpty.test_issue_45N)rv   rw   rx   r³   r   r   r   r   r²   {  r–   r²   c                   @   r   )ÚAbstractTestWeakRefMixinc                 C   s,   dd l }|  ¡ }| |¡}|  ||ƒ ¡ d S )Nr   )ÚweakrefÚ_makeOneÚrefr‘   )r   rµ   Úoner·   r   r   r   Útest_weak_reference…  s   
z,AbstractTestWeakRefMixin.test_weak_referenceN)rv   rw   rx   r¹   r   r   r   r   r´   ƒ  r–   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 )Nr   )r¶   r   ©r   r   r   r   r   Úwait’  s   zTestGetInterrupt.waitc                 C   ó   |   ¡ S rA   ©Úkindr   r   r   r   r¶   •  ó   zTestGetInterrupt._makeOneN)
rv   rw   rx   r   r/   r   r   r¿   r¼   r¶   r   r   r   r   rº   Œ  s
    rº   c                   @   ó   e Zd ZejZdS )ÚTestGetInterruptJoinableQueueN©rv   rw   rx   r   r   r¿   r   r   r   r   rÂ   ˜  ó    
rÂ   c                   @   rÁ   )ÚTestGetInterruptLifoQueueN©rv   rw   rx   r   Ú	LifoQueuer¿   r   r   r   r   rÅ   ›  rÄ   rÅ   c                   @   rÁ   )ÚTestGetInterruptPriorityQueueN©rv   rw   rx   r   ÚPriorityQueuer¿   r   r   r   r   rÈ   ž  rÄ   rÈ   c                   @   rÁ   )ÚTestGetInterruptChannelN)rv   rw   rx   r   rE   r¿   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 rA   )Ú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(   r4   r   )r   rª   r   r»   r   r   r   r¼   ­  s   

ÿzTestPutInterrupt.waitc                 C   s
   |   d¡S )Nr(   r¾   r   r   r   r   r¶   ²  ó   
zTestPutInterrupt._makeOne)rv   rw   rx   r   r   r¿   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½   rA   r¾   r   r   r   r   r¶   Â  rÀ   z TestPutInterruptChannel._makeOneN)rv   rw   rx   r   rE   r¿   r¶   r   r   r   r   rÖ   ¿  s    rÖ   ÚSimpleQueuec                   @   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)	rv   rw   rx   r   r×   r¿   rÛ   Ú*test_raises_timeout_Timeout_exc_customizedÚtest_outer_timeout_is_not_lostr   r   r   r   rØ   È  s
    rØ   Ú__main__)'rÙ   Úgevent.testingÚtestingr0   r   r"   Ú
gevent.hubr   r   r   r   Úgevent.queuer   r   Úgevent.eventr
   Úgevent.testing.timingr   r   ry   rŽ   r—   r²   r   r´   rº   rÂ   rÅ   rÈ   rË   rÌ   rÓ   rÔ   rÕ   rÖ   ÚhasattrrØ   rv   Úmainr   r   r   r   Ú<module>   sB     B2l	

ÿ