a  ze%U@sdZddlZddlmZddlZddlmZddZGdddejZ Gd d d e Z Gd d d e Z Gd dde Z Gddde Z Gddde ZGdddZGdddee ZGdddee ZGdddee ZedkredS)zTests for queues.pyN)mock)utilscCstddSN)asyncioZset_event_loop_policyrrQ/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_asyncio/test_queues.pytearDownModule srcseZdZfddZZS)_QueueTestBasecst||_dSr)supersetUp new_test_looploopself __class__rrr s z_QueueTestBase.setUp)__name__ __module__ __qualname__r __classcell__rrrrr sr c@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)QueueBasicTestscs@fdd}|ttjd}Wdn1sB0Y|d|tt||v} ||fdd}t |Wdn1s0Yfdd }t( |tjd}Wdn1s0Y| d d |vdS) zTest Queue's repr or str. fn is repr or str. expect_id is True if we expect the Queue's id to appear in fn(Queue()). c3s.dV}d|dV}d|dVdSN皙?g?assertAlmostEqualZwhenrrrgens   z.QueueBasicTests._test_repr_or_str..genr Nz.add_gettercsVtjdd}|d|dtdIdHd|v|dS)Nmaxsizer rz _putters[1])rrr#rputr!r" get_nowaitr$r&rr add_putter9s  z5QueueBasicTests._test_repr_or_str..add_putterr)z _queue=[1]) r assertWarnsDeprecationWarningrrr" startswithhexid assertEqualrun_until_completer#)rr'Z expect_idrr%Z id_is_presentr(r/rr&r_test_repr_or_strs    *  *  , z!QueueBasicTests._test_repr_or_strcCst}|ttj|d}Wdn1s40Y||j||ttj|jd}Wdn1sz0Y||j|jdSNr) rZMockr0r1rrassertIs_loopr )rr r%rrrtest_ctor_loopJs * ,zQueueBasicTests.test_ctor_loopcCs(t|jt}||j|jdSr)rZset_event_loopr rr9r:rr%rrrtest_ctor_noloopTs z QueueBasicTests.test_ctor_noloopcCs|tddSNT)r7reprrrrr test_reprYszQueueBasicTests.test_reprcCs|tddS)NF)r7strrrrrtest_str\szQueueBasicTests.test_strcCs|ttj|jd}Wdn1s.0Y|||d||| d| ||dSNrr)) r0r1rrr r"emptyr# assertFalser5r.r<rrr test_empty_s , zQueueBasicTests.test_emptycCs|ttj|jd}Wdn1s.0Y|||t tjd|jd}Wdn1sv0Y|d||dS)Nrr)r*) r0r1rrr rEfullr#r"r<rrr test_fullhs , . zQueueBasicTests.test_fullcsv|ttj|jdWdn1s.0YdD]}|q<fddtdD}|gd|dS)Nrr)r,csg|] }qSrr..0_r$rr xz.QueueBasicTests.test_order..rJ)r0r1rrr r#ranger5riitemsrr$r test_orderrs  , zQueueBasicTests.test_ordercsfdd}|ttjddWdn1sD0Ydjgfddfdd}|d  dS) Nc3s.dV}d|dV}d|dVdS)N{Gz?{Gz?rrrrrr}s   z)QueueBasicTests.test_maxsize..genr,r*cs,tdD]}|IdH|qdS)NrJT)rQr-append)rS) have_been_putr%rrputters  z,QueueBasicTests.test_maxsize..puttercs}tdIdHddgdtdIdHgddd||dS)NrVrr))rr)r,r,)rrr!r5r.r"doneresult)trYr rZr%rrrtests z*QueueBasicTests.test_maxsize..testrW) r r0r1rrr5r+r6rtimerrr_rr^r test_maxsize{s   , zQueueBasicTests.test_maxsizeN) rrrr7r;r=r@rBrFrHrUrbrrrrrs3    rc@s\eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dS) QueueGetTestscsl|ttj|jdWdn1s.0Ydfdd}|j|}|d|dS)Nrr)csIdHSrr rr$rr queue_getsz2QueueGetTests.test_blocking_get..queue_get)r0r1rrr r#r6r5)rreresrr$rtest_blocking_gets  ,  zQueueGetTests.test_blocking_getcCs|t tjd|jd}Wdn1s00Y|d|j}|j||j | }| d|| | ||dS)Nr)r)r0r1rrr r#Z create_future_puttersrXr6r r5r"r[Z assertIsNoner\)rr%waiterrfrrrtest_get_with_putterss .    z#QueueGetTests.test_get_with_putterscsfdd}|t(tjdtjdWdn1sN0Ydfddfdd}|}d |d  dS) Nc3sdV}d|dVdSNrVrrrrrrs z1QueueGetTests.test_blocking_get_wait..genrFcsIdH}d|Sr>)setr )rffinishedr%startedrrresz7QueueGetTests.test_blocking_get_wait..queue_getcsLdjd}IdH|IdH}|SNrVr)) call_laterr#rwaitrEr")Zqueue_get_taskrfrnr r%rerrorr queue_puts    z7QueueGetTests.test_blocking_get_wait..queue_putr)rV) r r0r1rrEventr6r5rr`)rrrtrfrrsrtest_blocking_get_waits    *  z$QueueGetTests.test_blocking_get_waitcCsV|ttj|jd}Wdn1s.0Y|d|d|dSrCr0r1rrr r#r5r.r<rrrtest_nonblocking_gets , z"QueueGetTests.test_nonblocking_getcCsL|ttj|jd}Wdn1s.0Y|tj|jdSr8)r0r1rrr assertRaisesZ QueueEmptyr.r<rrrtest_nonblocking_get_exceptions ,z,QueueGetTests.test_nonblocking_get_exceptioncsfdd}|ttjdWdn1sB0Yfddfdd}d|d dS) Nc3s.dV}d|dV}d|dVdS)NrVgZd;?g?rrrrrrs   z-QueueGetTests.test_get_cancelled..genrcstdIdHS)Ng&1?)rwait_forr rr$rrresz3QueueGetTests.test_get_cancelled..queue_getcs0}tdIdHd|IdHSrp)rrr!r#)Zget_task)r r%rerrr_s  z.QueueGetTests.test_get_cancelled..testr)gQ?) r r0r1rrr5r6rr`rar)r r%rerrtest_get_cancelleds   * z QueueGetTests.test_get_cancelledcCs|ttj|jd}Wdn1s.0Y|j|}|j|}t|j| t|j| | | dt|j| |ddSNra)r0r1rrr rr test_utils run_brieflycancelr"r[r#r5r\)rr%t1t2rrrtest_get_cancelled_races ,    z%QueueGetTests.test_get_cancelled_racecCs|t tj|jdd}Wdn1s00Y|j|d|j|dt|j| |j | d| |j | ddS)Nr)r r+r~b) r0r1rrr rr-rrr5r6r r<rrrtest_get_with_waiting_putterss . z+QueueGetTests.test_get_with_waiting_putterscCsdd}dd}d}d}|t tj||jd}Wdn1sH0Y|t6|jtj|||||||jdWdn1s0YdS)Ncs t|D]}|IdHqdSr)rQr )queueZ num_expectedrNrrrconsumer"s z.consumercs"t|D]}||IdHqdSr)rQr-)rZ num_itemsrSrrrproducer&s z.producerr)rr0r1rrr r6Zgather)rrr queue_sizeZproducer_num_itemsr%rrrtest_why_are_getters_waitings .  z*QueueGetTests.test_why_are_getters_waitingcCsdd}|||_dd}|t tj|jdd}Wdn1sL0Y|j|j|||t |j ddS)NcssdVdVdSrrrrrr a_generator8szXQueueGetTests.test_cancelled_getters_not_being_held_in_self_getters..a_generatorcs4zt|dIdH}Wntjy.Yn0dS)Nr)rr{r TimeoutError)ritemrrrr>szUQueueGetTests.test_cancelled_getters_not_being_held_in_self_getters..consumerrrr) r r r0r1rrr6rr5lenZ_getters)rrrrrrr5test_cancelled_getters_not_being_held_in_self_getters7s  .zCQueueGetTests.test_cancelled_getters_not_being_held_in_self_gettersN) rrrrgrjrvrxrzr|rrrrrrrrrcs  " rcc@s|eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZdS) QueuePutTestscsV|ttj|jdWdn1s.0Yfdd}|j|dS)NrcsdIdHdS)Nr)r-rr$rrrtPsz2QueuePutTests.test_blocking_put..queue_put)r0r1rrr r6rrtrr$rtest_blocking_putLs , zQueuePutTests.test_blocking_putcsfdd}|t*tjddtjdWdn1sP0Ydfddfd d }|d dS) Nc3sdV}d|dVdSrkrrrrrrXs z1QueuePutTests.test_blocking_put_wait..genr)r*rFcs0dIdHdIdHddS)Nr)r,T)rlr-rrmrrrtdsz7QueuePutTests.test_blocking_put_wait..queue_putcsJdj}IdH|IdHdSrk)rqr.rrrrEr")Zqueue_put_taskrnr r%rtrrorrreks    z7QueuePutTests.test_blocking_put_wait..queue_getrV) r r0r1rrrur6rr`)rrrerrrtest_blocking_put_waitVs   * z$QueuePutTests.test_blocking_put_waitcCsV|ttj|jd}Wdn1s.0Y|d|d|dSrCrwr<rrrtest_nonblocking_putvs , z"QueuePutTests.test_nonblocking_putcCsdd}||}|ttj|d}Wdn1s>0Y||}|td| d| d| z||Wn,tj y||}||Yn0| }| d|dS)NcssdVdVdSNrVrrrrrrr}szBQueuePutTests.test_get_cancel_drop_one_pending_reader..genrrVr)r,)r r0r1rrrr r6r!r#rCancelledErrorr\r5)rrr r%readerr\rrr'test_get_cancel_drop_one_pending_reader|s   *  z5QueuePutTests.test_get_cancel_drop_one_pending_readercCsdd}||}|d|ttj|d}Wdn1sH0Y||}||}||}|t d| d| d| z||Wntj yYn0||| ||hddhdS)NcssdVdVdSrrrrrrrszDQueuePutTests.test_get_cancel_drop_many_pending_readers..genTrrVr)r,)r Z set_debugr0r1rrrr r6r!r#rrr5r\)rrr r%Zreader1Zreader2Zreader3rrr)test_get_cancel_drop_many_pending_readerss$   *   z7QueuePutTests.test_get_cancel_drop_many_pending_readerscCsdd}||}|ttjd|d}Wdn1s@0Y|d||d}|t d| }| |d| z||Wn.tj y||d}||Yn0| }| |d| |ddS)NcssdVdVdSrrrrrrrsz/QueuePutTests.test_put_cancel_drop..genr)rr,rVr)r r0r1rrr#rr-r6r!r.r5rrqsize)rrr r%writerZvalue1Zvalue2rrrtest_put_cancel_drops$  ,   z"QueuePutTests.test_put_cancel_dropcCsZ|t tjd|jd}Wdn1s00Y|d|tj|jddS)Nr)r*r,)r0r1rrr r#ry QueueFullr<rrrtest_nonblocking_put_exceptions . z,QueuePutTests.test_nonblocking_put_exceptioncst tjdjdWdn1s00Yddtj jdt tjdjdWdn1s0Yfdd}j |dS)Ng?r*r)r,rJcs2dIdHdIdHdS)Nr)r,)r-r"rGrr%rrrrtsz3QueuePutTests.test_float_maxsize..queue_put) r0r1rrr r#r"rGryrr6rrrrtest_float_maxsizes .   .z QueuePutTests.test_float_maxsizecs|ttj|jdWdn1s.0Yfdd}fdd}|j|}|d|j||| || dS)NrcsdIdHdS)Nr)Trrr$rrrtsz3QueuePutTests.test_put_cancelled..queue_putcsIdHSrrdrr$rrr_sz.QueuePutTests.test_put_cancelled..testr)) r0r1rrr rr5r6r"r[r\)rrtr_r]rr$rtest_put_cancelleds ,  z QueuePutTests.test_put_cancelledcCs|t tj|jdd}Wdn1s00Y|j|d}|j|d}|j|d}t|j| | | | | t|j| | | |dt|j| |d|j|dS)Nr)rr~rX)r0r1rrr rr-rrr"r[rErr5r.r6)rr%Zput_aZput_bZput_crrrtest_put_cancelled_races .   z%QueuePutTests.test_put_cancelled_racecCs~|ttj|jd}Wdn1s.0Y|j|}t|j|j | d| |j |ddSr}) r0r1rrr rr rrr6r-r5)rr%r]rrrtest_put_with_waiting_getterss  , z+QueuePutTests.test_put_with_waiting_gettersc s|t tjd|jdWdn1s00Yfdd}fdd}|d}|d}|d}|d }|t2|jtj||||||jdWdn1s0YdS) Nr,rcs|IdHdSrrrrrrrZ"sz:QueuePutTests.test_why_are_putters_waiting..puttercs2tdIdH}t|D] }}q dS)Nr)rr!rrQr.)numrNrrrrgetter%s z:QueuePutTests.test_why_are_putters_waiting..getterrr)rJr)rrZrt0rrZt3rrrtest_why_are_putters_waitings .   z*QueuePutTests.test_why_are_putters_waitingcCsdd}||}|ttj|dd}Wdn1s@0Y|d||d}|t d| t |j d| |tj||Wdn1s0Y| t |j ddS)NcssdVdVdSrrrrrrr4szUQueuePutTests.test_cancelled_puts_not_being_held_in_self_putters..a_generatorr)rrVr)r r0r1rrr#rr-r6r!r5rrhrryr)rrr rput_taskrrr2test_cancelled_puts_not_being_held_in_self_putters3s  , (z@QueuePutTests.test_cancelled_puts_not_being_held_in_self_putterscCsdd}||}|ttjd|d}Wdn1s@0Y|d||d}|t d| | | tj ||Wdn1s0YdS)NcssdVdVdSrrrrrrrLszKQueuePutTests.test_cancelled_put_silence_value_error_exception..genr)rrV)r r0r1rrr#rr-r6r!r.rryr)rrr rrrrr0test_cancelled_put_silence_value_error_exceptionKs  , z>QueuePutTests.test_cancelled_put_silence_value_error_exceptionN)rrrrrrrrrrrrrrrrrrrrrrJs   rc@seZdZddZdS)LifoQueueTestscsv|ttj|jdWdn1s.0YdD]}|q<fddtdD}|gd|dS)NrrIcsg|] }qSrrKrLr$rrrOprPz-LifoQueueTests.test_order..rJ)r,rJr))r0r1r LifoQueuer r#rQr5rRrr$rrUjs  , zLifoQueueTests.test_orderNrrrrUrrrrrhsrc@seZdZddZdS)PriorityQueueTestscsv|ttj|jdWdn1s.0YdD]}|q<fddtdD}|gd|dS)NrrIcsg|] }qSrrKrLr$rrrO|rPz1PriorityQueueTests.test_order..rJ)r)r,rJ)r0r1r PriorityQueuer r#rQr5rRrr$rrUvs  , zPriorityQueueTests.test_orderNrrrrrrtsrc@s0eZdZdZddZddZddZdd ZdS) _QueueJoinTestMixinNcCsJ|t|j|jd}Wdn1s.0Y|t|jdSr8)r0r1q_classr ry ValueError task_doner<rrrtest_task_done_underflows ,z,_QueueJoinTestMixin.test_task_done_underflowcstjjdWdn1s.0YtdD]}|q@ddfddfdd}j|}ttdd tt |D]}dqjt |dS) NrdrTcs(r$IdH}|7qdSr)r rr) accumulatorr%runningrrworkersz2_QueueJoinTestMixin.test_task_done..workercs*fddtdD}IdH|S)Ncsg|]}jqSr)r r)rMindex)rrrrrOszD_QueueJoinTestMixin.test_task_done..test..r,)rQjoin)tasks)r%rrrrr_s  z0_QueueJoinTestMixin.test_task_done..testF) r0r1rr rQr#r6r5sumrrrr)rrSr_rr)rr%rrrrtest_task_dones ,   z"_QueueJoinTestMixin.test_task_donecsV|t|j|jdWdn1s.0Yfdd}|j|dS)Nrcs IdHIdHdSr)rrr$rrrsz7_QueueJoinTestMixin.test_join_empty_queue..join)r0r1rr r6)rrrr$rtest_join_empty_queues , z)_QueueJoinTestMixin.test_join_empty_queuecCsb|t|j|jd}Wdn1s.0Y||dd|_||ddS)Nrz maxsize=0r,zmaxsize=0 tasks=2)r0r1rr r5_format_unfinished_tasksr<rrr test_formats  ,z_QueueJoinTestMixin.test_format)rrrrrrrrrrrrrs $ rc@seZdZejZdS)QueueJoinTestsN)rrrrrrrrrrrsrc@seZdZejZdS)LifoQueueJoinTestsN)rrrrrrrrrrrsrc@seZdZejZdS)PriorityQueueJoinTestsN)rrrrrrrrrrrsr__main__)__doc__ZunittestrrZtest.test_asynciorrrZTestCaser rrcrrrrrrrrmainrrrrs*  %   C