Your IP : 216.73.216.196


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_queue.cpython-310.opt-2.pyc

o

0�iR�@sddlZddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	ej
ddgd�Zej
ddgd�Ze�
ed	�Zd
Zdd�ZGd
d�dej�ZGdd�d�ZGdd�de�ZGdd�de�ZGdd�deej�ZeGdd�deej��ZGdd�de�ZGdd�deej�ZeGdd�deej��ZGdd �d e�ZGd!d"�d"eej�ZeGd#d$�d$eej��ZGd%d&�d&e�Z Gd'd(�d(e�Z!Gd)d*�d*e!ej�Z"eGd+d,�d,e!ej��Z#Gd-d.�d.�Z$Gd/d0�d0e$ej�Z%eGd1d2�d2e$ej��Z&e'd3k�re�(�dSdS)4�N)�
gc_collect)�
import_helper)�threading_helper�queueZ_queue)Zblocked)ZfreshzNo _queue module found�cCs|jdko|��|jkS�Nr)�maxsize�qsize)�q�r�6/opt/alt/python310/lib64/python3.10/test/test_queue.py�qfullsr
c@�eZdZdd�Zdd�ZdS)�_TriggerThreadcCs&||_||_t��|_tj�|�dS�N)�fn�args�	threadingZEvent�startedEvent�Thread�__init__)�selfrrrrrrs
z_TriggerThread.__init__cCs$t�d�|j��|j|j�dS)N皙�����?)�time�sleepr�setrr�rrrr�runs
	
z_TriggerThread.runN)�__name__�
__module__�__qualname__rrrrrrrsrc@r)�BlockingTestMixinc	CsTt||�}|��z||�|_|j��s|�d|�|jWt�|�St�|�w)Nz*blocking function %r appeared not to block)r�start�resultr�is_set�failr�join_thread)r�
block_func�
block_args�trigger_func�trigger_args�threadrrr�do_blocking_test:s


�z"BlockingTestMixin.do_blocking_testc	Cs�t||�}|��z*z||�Wn|y�w|�d|�Wt�|�|j��s2|�d�dSdSt�|�|j��sD|�d�ww)Nzexpected exception of kind %rz(trigger thread ended but event never set)rr"r%rr&rr$)rr'r(r)r*Zexpected_exception_classr+rrr�do_exceptional_blocking_testHs&
��

�
�
�z.BlockingTestMixin.do_exceptional_blocking_testN)rrr r,r-rrrrr!8sr!c@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�BaseQueueTestMixincCsd|_t��|_dSr)�cumrZLock�cumlockrrrr�setUp[szBaseQueueTestMixin.setUpcCsh|��rtd��|�|���|�|���|�d�|�d�|�d�tgd�gd�gd�d�}|��|��|��g}|�	|||j
jd	�tt
d
�D]}|�|�|�|��d�qN|�t|�d�d
t
}dt
}|�|�|�t|�d�|�|���|�|���z|j|dd�|�d�Wn|jjy�Ynwz|j|dd�|�d�Wn|jjy�Ynw|�|j|f|jd�|�|j|ddf|jd�tt
�D]}|��q�|�|��d�z
|jdd�|�d�Wn|jj�yYnwz
|jdd�|�d�Wn|jj�yYnw|�|jd|jd�|�|jd|jd�dS)N�&Call this function with an empty queue�o�M��)r3r4r5)r5r4r3)r3r5r4)�Queue�	LifoQueue�
PriorityQueuez&Didn't seem to queue the correct data!��Queue should not be empty�Queue should not be full���Queue should be fullr��blockz(Didn't appear to block with a full queueg{�G�z�?�Ztimeoutz+Didn't appear to time-out with a full queuerT�
�Queue should be emptyz*Didn't appear to block with an empty queuez-Didn't appear to time-out with an empty queue��empty)TrB)r	�RuntimeError�
assertTruerE�assertFalse�full�put�dict�get�assertEqual�	__class__r�range�
QUEUE_SIZEr
r%r�Fullr,�Empty)rr
Ztarget_orderZactual_order�i�lastrIrrr�basic_queue_test_sp


��

��
��z#BaseQueueTestMixin.basic_queue_testcCs\	|��}|dkr|��dS|j�|j|7_Wd�n1s$wY|��q)NTr)rL�	task_doner0r/)rr
�xrrr�worker�s��zBaseQueueTestMixin.workercCs�d|_g}dD]}tj|j|fd�}|��|�|�qtd�D]}|�|�q |��|�	|jt
td��d�dD]}|�d�q:|��|D]}|��qHdS)Nr)rr9��targetr�dz0q.join() did not block until all tasks were done���)r/rrrXr"�appendrOrJ�joinrM�sum)rr
ZthreadsrSr+rrr�queue_join_test�s$�
�z"BaseQueueTestMixin.queue_join_testcCs8|��}z|��Wn
tyYdSw|�d�dS�Nz(Did not detect task count going negative)�	type2testrV�
ValueErrorr%�rr
rrr�test_queue_task_done�s�z'BaseQueueTestMixin.test_queue_task_donecCsL|��}|�|�|�|�z|��Wn
tyYdSw|�d�dSra)rbr`rVrcr%rdrrr�test_queue_join�s

�z"BaseQueueTestMixin.test_queue_joincC�"|�t�}|�|�|�|�dSr)rbrPrUrdrrr�
test_basic�s

zBaseQueueTestMixin.test_basiccCs�|�t�}|�t��|jddd�Wd�n1swY|�t��|jddd�Wd�dS1s9wYdS�Nr9r\rA)rbrP�assertRaisesrcrJrLrdrrr�&test_negative_timeout_raises_exception�s
�"�z9BaseQueueTestMixin.test_negative_timeout_raises_exceptioncCs�|�t�}tt�D]}|�d�q	|�|jj��
|�d�Wd�n1s(wYtt�D]}|��q1|�|jj��
|��Wd�dS1sOwYdS)Nr9)	rbrPrO�
put_nowaitrjrrQ�
get_nowaitrR�rr
rSrrr�test_nowait�s
�

"�zBaseQueueTestMixin.test_nowaitcCs�|�d�}|�d�|�d�|�d�|�|jj��
|�d�Wd�n1s+wY|�|��d�d|_|�|jj��|�d�Wd�dS1sSwYdS)N�r9r<�)	rbrJrjrrQrlrMr	rrdrrr�test_shrinking_queue�s



�"�z'BaseQueueTestMixin.test_shrinking_queueN)
rrr r1rUrXr`rerfrhrkrorrrrrrr.Zs9


r.c�eZdZ�fdd�Z�ZS)�	QueueTestc�|jj|_t���dSr)rr6rb�superr1r�rNrrr1��
zQueueTest.setUp�rrr r1�
__classcell__rrrwrrt��rtc@�eZdZeZdS)�PyQueueTestN�rrr �py_queuerrrrrr}��r}c@r|)�
CQueueTestN�rrr �c_queuerrrrrr���r�crs)�
LifoQueueTestcrur)rr7rbrvr1rrwrrr1rxzLifoQueueTest.setUpryrrrwrr�r{r�c@r|)�PyLifoQueueTestNr~rrrrr�r�r�c@r|)�CLifoQueueTestNr�rrrrr�r�r�crs)�PriorityQueueTestcrur)rr8rbrvr1rrwrrr1rxzPriorityQueueTest.setUpryrrrwrr�r{r�c@r|)�PyPriorityQueueTestNr~rrrrr�r�r�c@r|)�CPriorityQueueTestNr�rrrrr�r�r�c@�eZdZdS)�FailingQueueExceptionN�rrr rrrrr�"sr�cs,eZdZ�fdd�Zdd�Zdd�Z�ZS)�FailingQueueTestcs0|jj�G�fdd�d��}||_t���dS)Ncs0eZdZ�fdd�Z�fdd�Z�fdd�ZdS)z,FailingQueueTest.setUp.<locals>.FailingQueuecs"d|_d|_�j|g|�R�dS)NF)�
fail_next_put�
fail_next_getr)rr�r6rrr+sz5FailingQueueTest.setUp.<locals>.FailingQueue.__init__cs |jr
d|_td����||�S�NFzYou Lose)r�r��_put)r�itemr�rrr�/sz1FailingQueueTest.setUp.<locals>.FailingQueue._putcs|jr
d|_td����|�Sr�)r�r��_getrr�rrr�4s
z1FailingQueueTest.setUp.<locals>.FailingQueue._getN)rrr rr�r�rr�rr�FailingQueue*sr�)rr6r�rvr1)rr�rwr�rr1&szFailingQueueTest.setUpcCs�|��rtd��ttd�D]}|�|�qd|_z|jddd�|�d�Wn	ty0Ynwd|_z|jddd	�|�d�Wn	tyKYnw|�d
�|�t	|�d�d|_z|�
|jd|jd
�|�d�Wn	tyvYnw|�d
�d|_z|�|jd|jd
t�|�d�Wn	ty�Ynw|�d
�|�t	|�d�|��|�t	|�d�|�d
�|�t	|�d�|�
|jd|jd
�tt�D]}|��q�|�|��d�|�d�d|_
z|��|�d�Wn	ty�Ynw|�|��d�d|_
z
|jdd	�|�d�Wn
t�yYnw|�|��d�|��|�|��d�d|_
z|�|jd
|jdt�|�d�Wn
t�yTYnw|�|��d�|��|�|��d�dS)Nr2r9TZoopsrr?z)The queue didn't fail when it should haverrArTr>)rIr)rITrBr;rC�firstr:rD)r	rFrOrPrJr�r%r�rGr
r,rLr-r�rnrrr�failing_queue_test>s���
�
��



����z#FailingQueueTest.failing_queue_testcCrgr)r�rPr�rdrrr�test_failing_queue�s

z#FailingQueueTest.test_failing_queue)rrr r1r�r�rzrrrwrr�$sQr�c@r|)�PyFailingQueueTestNr~rrrrr��r�r�c@r|)�CFailingQueueTestNr�rrrrr��r�r�c@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�BaseSimpleQueueTestcCs|��|_dSr)rbr
rrrrr1�szBaseSimpleQueueTest.setUpcCsX	z|��}Wnty|�|�YdSw|�|�|��dkr+t�|��d�q)NTg�?���MbP?)�pop�
IndexErrorrJ�randomrr)rr
�seq�rnd�sentinel�valrrr�feed�s
�
�zBaseSimpleQueueTest.feedcCs"	|��}||krdS|�|�qr)rLr]�rr
�resultsr�r�rrr�consume�s
�zBaseSimpleQueueTest.consumecCsR		z|jdd�}Wn|jjyt�d�Ynwnq||kr#dS|�|�q)NTFr?��h㈵��>)rLrrRrrr]r�rrr�consume_nonblock�s��
�z$BaseSimpleQueueTest.consume_nonblockcCsH		z|jdd�}Wn|jjyYnwnq||krdS|�|�q)NTr�rA)rLrrRr]r�rrr�consume_timeout�s��
�z#BaseSimpleQueueTest.consume_timeoutcs�g�d�|������t�d��g��fdd��������fdd�t|�D�}�����fdd�t|�D�}t�||��Wd�n1sJwY|���|���	��|�
���d��S)N�*cs��fdd�}|S)Nc
sFz
�|i|��WdSty"}z��|�WYd}~dSd}~wwr)�
BaseExceptionr])r�kwargs�e)�
exceptions�frr�wrapper�s��zHBaseSimpleQueueTest.run_threads.<locals>.log_exceptions.<locals>.wrapperr)r�r�)r�)r�r�log_exceptions�sz7BaseSimpleQueueTest.run_threads.<locals>.log_exceptionscs&g|]}tj�������fd��qS�rY�rr��.0rS)�	feed_funcr�r
r�r�r�rr�
<listcomp>�s

�

�z3BaseSimpleQueueTest.run_threads.<locals>.<listcomp>cs$g|]}tj������fd��qSr�r�r�)�consume_funcr�r
r�r�rrr��s

�
�r)�copy�reverser�ZRandomrOrZ
start_threadsrHrGrErMr	)rZ	n_threadsr
�inputsr�r�ZfeedersZ	consumersr)	r�r�r�r�r
r�r�r�r�r�run_threads�s(
���
zBaseSimpleQueueTest.run_threadscCs�|j}|�|���|�|��d�|�d�|�|���|�|��d�|�d�|�d�|�d�|�|���|�|��d�|�|��d�|�|��d�|�|�	�d�|�|��d�|�|jdd�d�|�|���|�|��d�|�|jdd	�d�|�|���|�|��d�|�
|jj��|jdd�Wd�n1s�wY|�
|jj��|jd
d	�Wd�n1s�wY|�
|jj��|�	�Wd�n1s�wY|�|���|�|��d�dS)Nrr9r<rprqFr?rrAr�)
r
rGrErMr	rJrHrlrLrmrjrrRrdrrrrh�s@



��
�zBaseSimpleQueueTest.test_basiccCsL|j}|�d�|�t��|jdd�Wd�dS1swYdSri)r
rJrjrcrLrdrrrrks

"�z:BaseSimpleQueueTest.test_negative_timeout_raises_exceptioncCs8|j}ttd��}|�d|||j|j�}|�||�dS)Nr[r9)r
�listrOr�r�r�rM)rr
r�r�rrr�
test_orderszBaseSimpleQueueTest.test_ordercC�@d}|j}ttd��}|�||||j|j�}|�t|�|�dS�N�2�')r
r�rOr�r�r�rM�sorted�r�Nr
r�r�rrr�test_many_threads's
z%BaseSimpleQueueTest.test_many_threadscCr�r�)r
r�rOr�r�r�rMr�r�rrr�test_many_threads_nonblock2�
�z.BaseSimpleQueueTest.test_many_threads_nonblockcCr�)Nr�i�)r
r�rOr�r�r�rMr�r�rrr�test_many_threads_timeout<r�z-BaseSimpleQueueTest.test_many_threads_timeoutcCsdGdd�d�}d}|j}t|�D]}|�|��qt|�D]}t�|���}t�|�|��qdS)Nc@r�)z.BaseSimpleQueueTest.test_references.<locals>.CNr�rrrr�CIsr��)r
rOrJ�weakref�refrLrZassertIsNone)rr�r�r
rSZwrrrr�test_referencesFs�z#BaseSimpleQueueTest.test_referencesN)rrr r1r�r�r�r�r�rhrkr�r�r�r�r�rrrrr��s

 %	

r�cs eZdZeZ�fdd�Z�ZS)�PySimpleQueueTestcrur)rZ_PySimpleQueuerbrvr1rrwrrr1YrxzPySimpleQueueTest.setUp)rrr rrr1rzrrrwrr�Vsr�cs0eZdZeZ�fdd�Zdd�Zdd�Z�ZS)�CSimpleQueueTestcrur)r�SimpleQueuerbrvr1rrwrrr1crxzCSimpleQueueTest.setUpcCs(|�|j|jj�|�|j|jj�dSr)ZassertIsrbrr�rrrr�test_is_defaultgsz CSimpleQueueTest.test_is_defaultcs~|j�t���d}g}G��fdd�dt�}	|�}��t���~|�����|d|kr0nq|�|t	t
|d���dS)Nr�cs"eZdZdd�Z��fdd�ZdS)z2CSimpleQueueTest.test_reentrancy.<locals>.CircularcSs
||_dSr)Zcircularrrrrrws
z;CSimpleQueueTest.test_reentrancy.<locals>.Circular.__init__cs��t���dSr)rJ�nextr��genr
rr�__del__zsz:CSimpleQueueTest.test_reentrancy.<locals>.Circular.__del__N)rrr rr�rr�rr�Circularvsr�Tr\r9)r
�	itertools�count�objectrJr�r]rLrMr�rO)rr�r�r��orr�r�test_reentrancyks�z CSimpleQueueTest.test_reentrancy)	rrr r�rr1r�r�rzrrrwrr�^s
r��__main__))r�r�rrZunittestr�Ztest.supportrrrZimport_fresh_modulerr�Z
skipUnlessZneed_c_queuerPr
rrr!r.rtZTestCaser}r�r�r�r�r�r�r��	Exceptionr�r�r�r�r�r�r�r�mainrrrr�<module>sV "u5
)�