f ž _²c@s0ddlZddlZddlmZGdd„deƒZdS)iNi)ÚTestCasecsŒeZdZd‡fdd„ Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zd ‡fdd„ Z‡ZS)!ÚIsolatedAsyncioTestCaseÚrunTestcstƒ |¡d|_d|_dS©N)ÚsuperÚ__init__Ú_asyncioTestLoopÚ_asyncioCallsQueue)ÚselfZ methodName©Z __class__©ú,/usr/lib64/python3.10/unittest/async_case.pyr"s z IsolatedAsyncioTestCase.__init__cÃódSrr ©rr r r Ú asyncSetUp'óz"IsolatedAsyncioTestCase.asyncSetUpcÃr rr r r r r Ú asyncTearDown*rz%IsolatedAsyncioTestCase.asyncTearDowncOó|j|g|¢Ri|¤ŽdSr)Z addCleanup)rÚfuncÚargsÚkwargsr r r ÚaddAsyncCleanup-s z'IsolatedAsyncioTestCase.addAsyncCleanupcCs| ¡| |j¡dSr)ZsetUpÚ _callAsyncrr r r r Ú _callSetUp<sz"IsolatedAsyncioTestCase._callSetUpcCs| |¡dSr©Ú_callMaybeAsync)rZmethodr r r Ú_callTestMethod@rz'IsolatedAsyncioTestCase._callTestMethodcCs| |j¡| ¡dSr)rrZtearDownr r r r Ú _callTearDownCs z%IsolatedAsyncioTestCase._callTearDowncOrrr)rZfunctionrrr r r Ú _callCleanupGrz$IsolatedAsyncioTestCase._callCleanupcOs4||i|¤Ž}|j ¡}|j ||f¡|j |¡Sr)rÚ create_futurerÚ put_nowaitÚrun_until_complete©rrrrÚretÚfutr r r rJs z"IsolatedAsyncioTestCase._callAsynccOsB||i|¤Ž}t |¡r>|j ¡}|j ||f¡|j |¡S|Sr)ÚinspectZ isawaitablerrrrrr r r r rRs    z'IsolatedAsyncioTestCase._callMaybeAsyncc Ãs¶t ¡|_}| d¡| ¡IdH}| ¡|dur:dS|\}}z |IdH}| ¡s`| |¡Wqttfyz‚Yqt tj fy´}z| ¡s |  |¡WYd}~qd}~00r) ÚasyncioZQueuerZ set_resultZgetZ task_doneÚ cancelledZ SystemExitZKeyboardInterruptZ BaseExceptionZCancelledErrorZ set_exception)rr"ZqueueZqueryZ awaitabler!Zexr r r Ú_asyncioLoopRunner\s   z*IsolatedAsyncioTestCase._asyncioLoopRunnercCsJt ¡}t |¡| d¡||_| ¡}| | |¡¡|_|  |¡dS)NT) r$Znew_event_loopÚset_event_loopZ set_debugrrZ create_taskr&Z_asyncioCallsTaskr)rÚloopr"r r r Ú_setupAsyncioLoopos  z)IsolatedAsyncioTestCase._setupAsyncioLoopc Csì|j}d|_|j d¡| |j ¡¡zªt |¡}|sPWt d¡| ¡dS|D] }|  ¡qT| tj ||ddœŽ¡|D]0}|  ¡rŒq~|  ¡dur~|  d|  ¡|dœ¡q~| | ¡¡Wt d¡| ¡nt d¡| ¡0dS)NT)r(Zreturn_exceptionsz(unhandled exception during test shutdown)ZmessageÚ exceptionÚtask)rrrrZjoinr$Z all_tasksr'ZcloseZcancelZgatherr%r*Zcall_exception_handlerZshutdown_asyncgens)rr(Z to_cancelr+r r r Ú_tearDownAsyncioLoopys<   ë ÿ ý   ÿ z,IsolatedAsyncioTestCase._tearDownAsyncioLoopNcs*| ¡ztƒ |¡W| ¡S| ¡0r)r)rÚrunr,)rZresultr r r r-›s  þzIsolatedAsyncioTestCase.run)rr)Z__name__Z __module__Z __qualname__rrrrrrrrrrr&r)r,r-Z __classcell__r r r r rs  "r)r$r#Zcaserrr r r r Zs