o
    ÑtPf10  ã                   @   sà   d dl mZ e ¡  d dl mZ d dlZd dlZd dlZdZG dd„ dej	ƒZ
G dd„ deƒZG d	d
„ d
ej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jƒZG dd„ dejeƒZedkrne ¡  dS dS )é    )Úmonkey)ÚqueueNé   c                   @   ó   e Zd Zdd„ Zdd„ ZdS )Ú_TriggerThreadc                 C   s0   || _ || _ddlm} |ƒ | _tj | ¡ d S )Nr   )ÚEvent)ÚfnÚargsÚgevent.eventr   ÚstartedEventÚ	threadingÚThreadÚ__init__)Úselfr   r	   r   © r   ú`/var/www/html/humari/django-venv/lib/python3.10/site-packages/gevent/tests/test__monkey_queue.pyr      s
   z_TriggerThread.__init__c                 C   s$   t  d¡ | j ¡  | j| jŽ  d S )Nç{®Gáz„?)ÚtimeÚsleepr   Úsetr   r	   ©r   r   r   r   Úrun   s   
	
z_TriggerThread.runN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r      s    r   c                   @   r   )ÚBlockingTestMixinc                 C   sd   t ||ƒ| _| j ¡  ||Ž | _| jj ¡ s|  d| ¡ | j d¡ | j ¡ r/|  d| ¡ | jS )Nz,blocking function '%r' appeared not to blocké
   ú,trigger function '%r' appeared to not return)	r   ÚtÚstartÚresultr   ÚisSetÚfailÚjoinÚis_alive)r   Ú
block_funcÚ
block_argsÚtrigger_funcÚtrigger_argsr   r   r   Údo_blocking_test3   s   

ÿ
ÿz"BlockingTestMixin.do_blocking_testc              
   C   sÌ   t ||ƒ| _| j ¡  z;|  |¡ ||Ž  W d   ƒ n1 s w   Y  W | j d¡ | j ¡ r8|  d| ¡ | jj ¡ sE|  d¡ d S d S | j d¡ | j ¡ rY|  d| ¡ | jj ¡ se|  d¡ w w )Nr   r   z(trigger thread ended but event never set)	r   r   r   ÚassertRaisesr#   r$   r"   r   r!   )r   r%   r&   r'   r(   Úexpected_exception_classr   r   r   Údo_exceptional_blocking_testB   s.   

ÿ€
ÿÿü
ÿÿz.BlockingTestMixin.do_exceptional_blocking_testN)r   r   r   r)   r,   r   r   r   r   r   1   s    r   c                   @   sR   e Zd Zej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 )ÚBaseQueueTestc                 C   s   d| _ t ¡ | _d S )Nr   )Úcumr   ÚLockÚcumlockr   r   r   r   ÚsetUpU   s   zBaseQueueTest.setUpc                 C   sf  |  ¡ stdƒ‚| d¡ | d¡ | d¡ | d¡ tdddd}| ¡ | ¡ f}|  |||jj ||jj fd¡ tg d¢g d	¢g d
¢d}| ¡ | ¡ | ¡ g}|  |||jj d¡ t	t
d ƒD ]}| |¡ |  |  ¡ d¡ qe|  | ¡ d¡ | d¡ |  | ¡ d¡ z|jddd |  d¡ W n
 tjy¢   Y nw z|jddd |  d¡ W n
 tjy»   Y nw |  | ¡ t
¡ |  |jd|jd¡ |  |jd|jd¡ t	t
ƒD ]}| ¡  qÜ|  |  ¡ d¡ z|jdd |  d¡ W n tjy   Y nw z|jdd |  d¡ W n tjy   Y nw |  |jd|jd¡ |  |jd|jd¡ d S ) Nú&Call this function with an empty queueéo   éM  éÞ   é¼  )ÚQueueÚ	LifoQueueÚPriorityQueuez#q.peek() and q.get() are not equal!)r4   r5   r6   )r5   r4   r3   )r5   r4   r6   z&Didn't seem to queue the correct data!é   úQueue should not be emptyúQueue should not be fulléç  úQueue should be fulléx  r   ©Úblockz(Didn't appear to block with a full queuer   ©Útimeoutz+Didn't appear to time-out with a full queue©r?   r   ©r?   Tr   úQueue should be emptyz*Didn't appear to block with an empty queuez-Didn't appear to time-out with an empty queue©Úempty)Tr   )rH   ÚRuntimeErrorÚputÚdictÚpeekÚgetÚassertEqualÚ	__class__r   ÚrangeÚ
QUEUE_SIZEÚassertFalseÚfullÚ
assertTruer"   r7   ÚFullÚqsizer)   ÚEmpty)r   ÚqÚtarget_first_itemsÚactual_first_itemÚtarget_orderÚactual_orderÚir   r   r   Úsimple_queue_testY   s€   



ý

ÿýþÿ

ÿÿ
ÿÿzBaseQueueTest.simple_queue_testc                 C   s6   	 |  ¡ }|d u r| ¡  d S |  j|7  _| ¡  q©N)rM   Ú	task_doner.   )r   rX   Úxr   r   r   Úworker–   s   ùzBaseQueueTest.workerc                 C   s~   d| _ dD ]}tj| j|fd ¡  qtdƒD ]}| |¡ q| ¡  |  | j t	tdƒƒd¡ dD ]}| d ¡ q1| ¡  d S )Nr   )r   r:   )Útargetr	   éd   z0q.join() did not block until all tasks were done)
r.   r   r   rb   r   rP   rJ   r#   rN   Úsum©r   rX   r]   r   r   r   Úqueue_join_test    s   ÿzBaseQueueTest.queue_join_testc                 C   s8   t  ¡ }z| ¡  W n
 ty   Y d S w |  d¡ d S ©Nú(Did not detect task count going negative)r7   ÚJoinableQueuer`   Ú
ValueErrorr"   ©r   rX   r   r   r   Útest_queue_task_done­   s   ÿz"BaseQueueTest.test_queue_task_donec                 C   sL   t  ¡ }|  |¡ |  |¡ z| ¡  W n
 ty   Y d S w |  d¡ d S rh   )r7   rj   rg   r`   rk   r"   rl   r   r   r   Útest_queue_join¸   s   

ÿzBaseQueueTest.test_queue_joinc                 C   sˆ   g d¢}t j|d}|D ]}|  |jdd¡ |  || ¡ ¡ | ¡  qz| ¡  W n	 ty3   Y nw |  d¡ |  	|jdd¡ d S )N)r:   é   é   ©Úitemsgü©ñÒMbP?rB   ri   )
r7   rj   rR   r#   rN   rM   r`   rk   r"   rT   )r   ÚlrX   r]   r   r   r   Útest_queue_task_done_with_itemsÆ   s   
ÿ
z-BaseQueueTest.test_queue_task_done_with_itemsc                 C   s"   |   t¡}|  |¡ |  |¡ d S r_   )Ú	type2testrQ   r^   rl   r   r   r   Útest_simple_queueÚ   s   

zBaseQueueTest.test_simple_queueN)r   r   r   r7   ru   r1   r^   rb   rg   rm   rn   rt   rv   r   r   r   r   r-   R   s    =
r-   c                   @   s   e Zd ZejZdS )ÚLifoQueueTestN)r   r   r   r7   r8   ru   r   r   r   r   rw   á   s    
rw   c                   @   s   e Zd ZejZdd„ ZdS )ÚPriorityQueueTestc                 C   s<   d}d}| j ||gd}|  || ¡ ¡ |  || ¡ ¡ d S )N)ro   Úb)r:   Úarq   )ru   ÚassertTupleEqualÚ
get_nowait)r   Úitem1Úitem2rX   r   r   r   Ú
test__initç   s
   zPriorityQueueTest.test__initN)r   r   r   r7   r9   ru   r   r   r   r   r   rx   ä   s    rx   c                   @   s   e Zd ZdS )ÚFailingQueueExceptionN)r   r   r   r   r   r   r   r€   ð   s    r€   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚFailingQueuec                 G   s$   d| _ d| _tjj| g|¢R Ž  d S )NF)Úfail_next_putÚfail_next_getr7   r   )r   r	   r   r   r   r   ô   s   zFailingQueue.__init__c                 C   s"   | j r
d| _ tdƒ‚tj | |¡S ©NFzYou Lose)r‚   r€   r7   Ú_put)r   Úitemr   r   r   r…   ø   s   zFailingQueue._putc                 C   s    | j r
d| _ tdƒ‚tj | ¡S r„   )rƒ   r€   r7   Ú_getr   r   r   r   r‡   ý   s   zFailingQueue._getN)r   r   r   r   r…   r‡   r   r   r   r   r   ó   s    r   c                   @   r   )ÚFailingQueueTestc                 C   s²  |  ¡ stdƒ‚ttd ƒD ]}| |¡ qd|_|  t¡ |jddd W d   ƒ n1 s0w   Y  d|_|  t¡ |jddd W d   ƒ n1 sOw   Y  | d	¡ |  | 	¡ d
¡ d|_|  t¡ |  
|jd|jd¡ W d   ƒ n1 s~w   Y  | d	¡ d|_|  |jd|jdt¡ | d	¡ |  | 	¡ d
¡ | ¡  |  | 	¡ d¡ | d	¡ |  | 	¡ d
¡ |  
|jd|jd¡ ttƒD ]}| ¡  qÊ|  |  ¡ d¡ | d¡ d|_|  t¡ | ¡  W d   ƒ n1 sõw   Y  |  |  ¡ d¡ d|_|  t¡ |jdd W d   ƒ n	1 sw   Y  |  |  ¡ d¡ | ¡  |  |  ¡ d¡ d|_|  |jd|jdt¡ |  |  ¡ d¡ | ¡  |  |  ¡ d¡ d S )Nr2   r:   TÚoopsr   r@   gš™™™™™¹?rB   r=   r>   rD   r   rE   r<   rF   Úfirstr;   rG   )rH   rI   rP   rQ   rJ   r‚   r*   r€   rT   rS   r)   rM   r,   rR   rƒ   rf   r   r   r   Úfailing_queue_test  sj   ÿÿ
ÿ
ÿ




ÿÿÿz#FailingQueueTest.failing_queue_testc                 C   s    t tƒ}|  |¡ |  |¡ d S r_   )r   rQ   r‹   rl   r   r   r   Útest_failing_queueB  s   
z#FailingQueueTest.test_failing_queueN)r   r   r   r‹   rŒ   r   r   r   r   rˆ     s    =rˆ   Ú__main__)Úgeventr   Ú	patch_allr   r7   r   r   ÚunittestrQ   r   r   Úobjectr   ÚTestCaser-   rw   rx   Ú	Exceptionr€   r   rˆ   r   Úmainr   r   r   r   Ú<module>   s&   "! Gÿ