python (3.12.0)

(root)/
lib/
python3.12/
test/
__pycache__/
test_queue.cpython-312.pyc

ΑeuRddlZddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	e	jdejddg	Zejddg
Z
eje
dZdZd
ZGddej$ZGddZGddeZGddeZGddeej.ZeGddeej.ZGddeZGddeej.ZeGddeej.ZGd d!eZGd"d#eej.ZeGd$d%eej.ZGd&d'e Z!Gd(d)eZ"Gd*d+e"ej.Z#eGd,d-e"ej.Z$Gd.d/Z%Gd0d1e%ej.Z&eGd2d3e%ej.Z'e(d4k(rejRyy)5N)
gc_collect)
import_helper)threading_helperT)modulequeue_queue)blocked)freshzNo _queue module foundc^|jdkDxr|j|jk(SNr)maxsizeqsize)qs C/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/test/test_queue.pyqfullrs$99q=3QWWY!))33ceZdZdZdZy)_TriggerThreadc||_||_tj|_tj
j
|yN)fnargs	threadingEventstartedEventThread__init__)selfrrs   rrz_TriggerThread.__init__s3	%OO-!!$'rctjd|jj|j|j
y)N皙?)timesleeprsetrrrs rrunz_TriggerThread.run!s3	

3rN)__name__
__module____qualname__rr&rrrrs(rrceZdZdZdZy)BlockingTestMixinc"t||}|j	|||_|jj	s|jd|z|jt
j|S#t
j|wxYw)Nz*blocking function %r appeared not to block)rstartresultris_setfailrjoin_thread)r
block_func
block_argstrigger_functrigger_argsthreads      rdo_blocking_testz"BlockingTestMixin.do_blocking_test<svl;	1$j1DK&&--/		F$%&;;((0((0sAA77Bct||}|j		|||jd|z	tj||j
j
s|jdyy#|$rwxYw#tj||j
j
s|jdwwxYw)Nzexpected exception of kind %rz(trigger thread ended but event never set)rr.r1rr2rr0)rr3r4r5r6expected_exception_classr7s       rdo_exceptional_blocking_testz.BlockingTestMixin.do_exceptional_blocking_testJsl;	F
;J'		9!9:;
((0&&--/		DE0,


((0&&--/		DE0sA;B;BBACN)r'r(r)r8r;r*rrr,r,:s
1Frr,cHeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
Zy)BaseQueueTestMixincDd|_tj|_yr
)cumrLockcumlockr%s rsetUpzBaseQueueTestMixin.setUp]s ~~'rc|jrtd|j|j|j	|j|j
d|j
d|j
dtgdgdgd}|j|j|jg}|j|||jjd	ttd
z
D]3}|j
||j|jd5|jt|dd
tz}dtz}|j
||jt|d|j	|j|j|j	|j
|d|jd	|j
|d|jd|j%|j|f|jd|j%|j|ddf|jdttD]}|j|j|jd	|jd|jd	|jd|jd|j%|jd|jd|j%|jd|jdy#|j j"$rYswxYw#|j j"$rYnwxYw#|j j&$rYwxYw#|j j&$rYwxYw)N&Call this function with an empty queueoM)rErFrG)rGrFrE)rErGrF)Queue	LifoQueue
PriorityQueuez&Didn't seem to queue the correct data!Queue should not be emptyQueue should not be fullQueue should be fullrblockz(Didn't appear to block with a full queueg{Gz?timeoutz+Didn't appear to time-out with a full queuer*T
Queue should be emptyz*Didn't appear to block with an empty queuez-Didn't appear to time-out with an empty queueempty)TrU)rRuntimeError
assertTruerXassertFalsefullputdictgetassertEqual	__class__r'range
QUEUE_SIZErr1rFullr8Empty)rrtarget_orderactual_orderilastr\s       rbasic_queue_testz#BaseQueueTestMixin.basic_queue_testas779GHH	""	c
	c
	c
O(7,;=!%%'2|AKK4H4H'IA	Cz!|$	DA
EE!HOOAGGI'BC	D	
E!H&@A:~z!	da"89#!	
EE$aE II@A	
EE$E%IICD	
aeedWaeeR8aeedD"%5quubAz"	A
EEG	AGGI
'>?	
EEENIIBC	
EE$EIIEF	
aeeR
;aeeZ
C5zz		
zz		zz		
zz		sH$M$M6>#N"#N5M32M36NNN21N25OOc	|j}|dkr|jy|j5|xj|z
c_ddd|ja#1swYxYwr
)r_	task_donerAr?)rrxs   rworkerzBaseQueueTestMixin.workersZA1u

A


KKM


sA##A,cd|_g}dD]E}tj|j|f}|j	|j|Gt
dD]}|j||j|j|jtt
dddD]}|jd|j|D]}|jy)Nr)rrKtargetrdz0q.join() did not block until all tasks were done)r?rrrnr.appendrbr]joinr`sum)rrthreadsrhr7s     rqueue_join_testz"BaseQueueTestMixin.queue_join_tests	#A%%T[[tDFLLNNN6"	#s	A
EE!H		3uSz?K	M	A
EE"I			FKKM	rc|j}	|j|jdy#t$rYywxYwNz(Did not detect task count going negative)	type2testrlr1
ValueErrorrrs  rtest_queue_task_donez'BaseQueueTestMixin.test_queue_task_dones@NN	B
KKM
II@A		s4	AAc|j}|j||j|	|j|jdy#t$rYywxYwrz)r{rxrlr1r|r}s  rtest_queue_joinz"BaseQueueTestMixin.test_queue_joins^
NNQQ	B
KKM
II@A		sA	A"!A"cr|jt}|j||j|yr)r{rcrjr}s  r
test_basiczBaseQueueTestMixin.test_basics.
NN:&a a rc"|jt}|jt5|j	ddddd|jt5|jdddddy#1swY;xYw#1swYyxYwNrKrsrS)r{rcassertRaisesr|r]r_r}s  r&test_negative_timeout_raises_exceptionz9BaseQueueTestMixin.test_negative_timeout_raises_exceptions{NN:&


z
*	!
EE!RE 	!


z
*	!
EE!RE 	!	!	!	!	!	!sA9B9BBc|jt}ttD]}|jd|j	|j
j5|jddddttD]}|j|j	|j
j5|jdddy#1swYlxYw#1swYyxYw)NrK)	r{rcrb
put_nowaitrrrd
get_nowaitrerrrhs   rtest_nowaitzBaseQueueTestMixin.test_nowaitsNN:&z"	A
LLO	


tzz
/	
LLO	z"	A
LLN	


tzz//
0	
LLN				
		s CC)C&)C2c|jd}|jd|jd|jd|j|jj5|jdddd|j
|jdd|_|j|jj5|jddddy#1swYpxYw#1swYyxYw)NrKrN)	r{r]rrrdrr`rrr}s  rtest_shrinking_queuez'BaseQueueTestMixin.test_shrinking_queuesNN1	a	a	a


tzz
/	
LLO	A&	


tzz
/	
LLO							s*C+C7+C47DN)
r'r(r)rBrjrnrxr~rrrrrr*rrr=r=\s8(6Dr$BB!!
rr=ceZdZfdZxZS)	QueueTestcX|jj|_t|yr)rrHr{superrBrras rrBzQueueTest.setUps))

rr'r(r)rB
__classcell__ras@rrr
rrceZdZeZy)PyQueueTestNr'r(r)py_queuerr*rrrrErrceZdZeZy)
CQueueTestNr'r(r)c_queuerr*rrrrErrceZdZfdZxZS)
LifoQueueTestcX|jj|_t|yr)rrIr{rrBrs rrBzLifoQueueTest.setUps--

rrrs@rrrrrrceZdZeZy)PyLifoQueueTestNrr*rrrr
rrrceZdZeZy)CLifoQueueTestNrr*rrrrrrrceZdZfdZxZS)PriorityQueueTestcX|jj|_t|yr)rrJr{rrBrs rrBzPriorityQueueTest.setUps11

rrrs@rrrrrrceZdZeZy)PyPriorityQueueTestNrr*rrrrrrrceZdZeZy)CPriorityQueueTestNrr*rrrrrrrceZdZy)FailingQueueExceptionNr'r(r)r*rrrr$srrc*eZdZfdZdZdZxZS)FailingQueueTestcx|jjGfdd}||_t|y)Nc,eZdZfdZfdZfdZy),FailingQueueTest.setUp.<locals>.FailingQueuecHd|_d|_j|g|y)NF)
fail_next_put
fail_next_getr)rrrHs  rrz5FailingQueueTest.setUp.<locals>.FailingQueue.__init__.s&%*"%*"t+d+rcd|jrd|_tdj||SNFzYou Lose)rr_put)ritemrHs  rrz1FailingQueueTest.setUp.<locals>.FailingQueue._put2s0%%).D&/
;;zz$--rcb|jrd|_tdj|Sr)rr_get)rrHs rrz1FailingQueueTest.setUp.<locals>.FailingQueue._get7s.%%).D&/
;;zz$''rN)r'r(r)rrr)rHsrFailingQueuer-s
,
.

(rr)rrHrrrB)rrrHras  @rrBzFailingQueueTest.setUp)s1

  	(5	( )

rc\|jrtdttdz
D]}|j	|d|_	|j	dd|j
dd|_	|j	dd	|j
d|j	d
|jt|dd|_	|j|jd|jd
|j
d|j	d
d|_	|j|jd|jd
t|j
d|j	d
|jt|d|j|jt|d|j	d
|jt|d|j|jd|jd
ttD]}|j|j|jd|j	dd|_
	|j|j
d|j|jdd|_
	|jd	|j
d|j|jd|j|j|jdd|_
	|j|jd
|jdt|j
d|j|jd|j|j|jdy#t$rY[wxYw#t$rY?wxYw#t$rYwxYw#t$rYwxYw#t$rYwxYw#t$rYEwxYw#t$rYwxYw)NrDrKToopsrrQz)The queue didn't fail when it should haver!rSrirP)r\r*)r\TrUrMrVfirstrLrW)rrYrbrcr]rr1rrZrr8r_r;rrs   rfailing_queue_testz#FailingQueueTest.failing_queue_testAsv779GHHz!|$	A
EE!H		
EE&E"IIAB	
EE&#E&IIAB	
f
a"89	!!!%%AEE2>IIAB
	
f
	--aee5GPR.C
EIIAB
	
f
a"89	E!H&@A	f
a"89aeeYr:z"	A
EEG	AGGI
'>?	g	
EEGIIAB	
	#>?	
EE#EIIAB	
	#>?	AGGI
'>?	--aeeR
.C
EIIAB	
	#>?	AGGI
'>?K%		%		%		%		*%		%		%		s~$N?8$O9O">O/*!O?3#P/>P?	OO	OO	O,+O,/	O<;O<?	PP	PP	P+*P+cr|jt}|j||j|yr)rrcrr}s  rtest_failing_queuez#FailingQueueTest.test_failing_queues0
j)""r)r'r(r)rBrrrrs@rrr's0O@b#rrceZdZeZy)PyFailingQueueTestNrr*rrrrrrrceZdZeZy)CFailingQueueTestNrr*rrrrrrrcZeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
Zy)BaseSimpleQueueTestc.|j|_yr)r{rr%s rrBzBaseSimpleQueueTest.setUps!rc		|j}|j||jdkDr&t	j
|jdz\#t$r|j|YywxYw)Ng?MbP?)pop
IndexErrorr]randomr"r#)rrseqrndsentinelvals      rfeedzBaseSimpleQueueTest.feedsk
ggi
EE#Jzz|c!

3::<$./
h
sAA;:A;cT	|j}||k(ry|j|(r)r_rtrrresultsrrs     rconsumezBaseSimpleQueueTest.consumes+%%'ChNN3	rc			|jd}	||k(ry|j|-#|jj$rtjdYnwxYwa)NFrQh㈵>)r_rrer"r#rtrs     rconsume_nonblockz$BaseSimpleQueueTest.consume_nonblocksi%%e%,ChNN3zz''%JJt$%s/.A A c			|jd}	||k(ry|j|-#|jj$rYnwxYwL)NrrS)r_rrertrs     rconsume_timeoutz#BaseSimpleQueueTest.consume_timeouts`%%%-ChNN3zz''s/A
Ac
rg}d}|j}|jtjd}	gfd}
t	|Dcgc]#}tj|
||||	|f%}}t	|Dcgc]"}tj|
||||f$}
}tj||
z5	ddd|j|j|j|j|jd|Scc}wcc}w#1swYexYw)N*cfd}|S)Ncf	|i|y#t$r}j|Yd}~yd}~wwxYwr)
BaseExceptionrt)rkwargse
exceptionsfs   rwrapperzHBaseSimpleQueueTest.run_threads.<locals>.log_exceptions.<locals>.wrappers6)t&v&$)%%a(()s	0+0r*)rrrs` rlog_exceptionsz7BaseSimpleQueueTest.run_threads.<locals>.log_exceptionss
)
Nrrpr)copyreverserRandomrbrrr
start_threadsr[rZrXr`r)r	n_threadsrinputs	feed_funcconsume_funcrrrrrrhfeeders	consumersrs              @rrun_threadszBaseSimpleQueueTest.run_threadss1kkm
mmB
	"),.##>)+D*+S#x)@B..
$I.0%%^L-I,-w+AC0	0
+
+Gi,?
@			
$	"A&.0		s(D#'D(D--D6c|j}|j|j|j|j	d|jd|j
|j|j|j	d|jd|jd|jd|j
|j|j|j	d|j|jd|j|j	d|j|jd|j|j	d|j|jdd|j
|j|j|j	d|j|jd	d|j|j|j|j	d|j|jj5|jdddd|j|jj5|jd
	ddd|j|jj5|jddd|j|j|j|j	dy#1swYxYw#1swYxYw#1swYaxYw)NrrKrNrrFrQr!rSr)
rrZrXr`rr]r[rr_rrrrer}s  rrzBaseSimpleQueueTest.test_basicsgFF	"A&	a#A&	a	Q	a#A&!$A&+A&U+Q/#A&s+Q/	"A&


tzz//
0	
EEE	


tzz//
0	 
EE$E	 


tzz//
0	
LLN		"A&			 	 		s$5M5M5M&MM#&M/c|j}|jd|jt5|j	ddddy#1swYyxYwr)rr]rr|r_r}s  rrz:BaseSimpleQueueTest.test_negative_timeout_raises_exceptionsGFF	a


z
*	
EE"E			sAAc|j}ttd}|jd|||j|j
}|j
||y)NrrrK)rlistrbrrrr`)rrrrs    r
test_orderzBaseSimpleQueueTest.test_order!sKFFeCj!""1aDLLI	
&)rcd}|j}ttd}|j||||j|j
}|j
t||yN2')rrrbrrrr`sortedrNrrrs     rtest_many_threadsz%BaseSimpleQueueTest.test_many_threads*sTFFeEl#""1aDLLI	
&1rcd}|j}ttd}|j||||j|j
}|j
t||yr)rrrbrrrr`rrs     rtest_many_threads_nonblockz.BaseSimpleQueueTest.test_many_threads_nonblock5sZFFeEl#""1a#'99d.C.CE	
&1rcd}|j}ttd}|j||||j|j
}|j
t||y)Nri)rrrbrrrr`rrs     rtest_many_threads_timeoutz-BaseSimpleQueueTest.test_many_threads_timeout?sZFFeDk"""1a#'99d.B.BD	
&1rc&Gdd}d}|j}t|D]}|j|t|D]E}tj|j}t
|j|Gy)NceZdZy).BaseSimpleQueueTest.test_references.<locals>.CNrr*rrCrLsrr
)rrbr]weakrefrefr_rassertIsNone)rr
rrrhwrs      rtest_referencesz#BaseSimpleQueueTest.test_referencesIsx		
FFq	A
EE!#J	q	$AQUUW%BLbd#	$rN)r'r(r)rBrrrrrrrrrrr	rr*rrrrsE"	0   @#'J*	222
$rrc"eZdZeZfdZxZS)PySimpleQueueTestcX|jj|_t|yr)r_PySimpleQueuer{rrBrs rrBzPySimpleQueueTest.setUp\s22

r)r'r(r)rrrBrrs@rrrYsErrc.eZdZeZfdZdZdZxZS)CSimpleQueueTestcX|jj|_t|yr)rSimpleQueuer{rrBrs rrBzCSimpleQueueTest.setUpfs//

rc|j|j|jj|j|j|jjyr)assertIsr{rrr%s rtest_is_defaultz CSimpleQueueTest.test_is_defaultjs:

dnndjj&<&<=

dnndjj&<&<=rc	Z|jtjd}g}Gfddt}	|}j	t~|j
j|d|k\rnK|j|tt|dzy)Nrc eZdZdZfdZy)2CSimpleQueueTest.test_reentrancy.<locals>.Circularc||_yr)circularr%s rrz;CSimpleQueueTest.test_reentrancy.<locals>.Circular.__init__zs	 $
rc:jtyr)r]next)rgenrs r__del__z:CSimpleQueueTest.test_reentrancy.<locals>.Circular.__del__}sd3i rN)r'r(r)rr')r&rsrCircularr!ys

%
!rr(rsrK)r	itertoolscountobjectr]r%rtr_r`rrb)rrrr(or&rs     @@rtest_reentrancyz CSimpleQueueTest.test_reentrancyns
FFoo
	!v	!
A
EE$s)NN1557#r{a
	
$uQU|"45r)	r'r(r)rrrBrr-rrs@rrras
E>6rr__main__)*r)rrr"unittestrtest.supportrrrrequires_working_threadingimport_fresh_modulerr
skipUnlessneed_c_queuercrrrr,r=rTestCaserrrrrrrr	Exceptionrrrrrrrr'mainr*rr<module>r8s2
#&),++48,=,,WxjI
+-
+
+GH:
F"x""7,DE

4Y%%@FFDV*Vp")X..H--&mX%6%6]H$5$5*+X->->*H,=,=
-I,q#(q#j)8+<+<((*;*;q$q$h+X->->&6*H,=,=&6&6RzHMMOr