o ?Ogàã@s0ddlZddlZddlmZGdd„deƒZdS)éNé)Ú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‡fdd „Zd!d"„Z‡ZS)%ÚIsolatedAsyncioTestCaseÚrunTestcstƒ |¡d|_d|_dS©N)ÚsuperÚ__init__Ú_asyncioTestLoopÚ_asyncioCallsQueue)ÚselfZ methodName©Ú __class__©ú:/opt/alt/python310/lib64/python3.10/unittest/async_case.pyr!s  z IsolatedAsyncioTestCase.__init__cÃódSrr©r rrrÚ asyncSetUp&ó€z"IsolatedAsyncioTestCase.asyncSetUpcÃrrrrrrrÚ asyncTearDown)rz%IsolatedAsyncioTestCase.asyncTearDowncOó|j|g|¢Ri|¤ŽdSr)Z addCleanup)r ÚfuncÚargsÚkwargsrrrÚaddAsyncCleanup,s z'IsolatedAsyncioTestCase.addAsyncCleanupcCs| ¡| |j¡dSr)ZsetUpÚ _callAsyncrrrrrÚ _callSetUp;sz"IsolatedAsyncioTestCase._callSetUpcCs| |¡dSr©Ú_callMaybeAsync)r ÚmethodrrrÚ_callTestMethod?sz'IsolatedAsyncioTestCase._callTestMethodcCs| |j¡| ¡dSr)rrZtearDownrrrrÚ _callTearDownBs  z%IsolatedAsyncioTestCase._callTearDowncOrrr)r ZfunctionrrrrrÚ _callCleanupFsz$IsolatedAsyncioTestCase._callCleanupcOs^|jdus Jdƒ‚||i|¤Ž}t |¡sJ|›dƒ‚|j ¡}|j ||f¡|j |¡S)Nú$asyncio test loop is not initializedz returned non-awaitable©r ÚinspectZ isawaitableÚ create_futurer Ú put_nowaitÚrun_until_complete©r rrrÚretÚfutrrrrIs   z"IsolatedAsyncioTestCase._callAsynccOsT|jdus Jdƒ‚||i|¤Ž}t |¡r(|j ¡}|j ||f¡|j |¡S|S)Nr"r#r(rrrrQs   z'IsolatedAsyncioTestCase._callMaybeAsyncc Ãs¸t ¡|_}| d¡ | ¡IdH}| ¡|durdS|\}}z|IdH}| ¡s2| |¡Wn'ttfy=‚t tj fyZ}z| ¡sP|  |¡WYd}~nd}~wwqr) ÚasyncioZQueuer Z set_resultÚgetZ task_doneÚ cancelledÚ SystemExitÚKeyboardInterruptÚ BaseExceptionZCancelledErrorZ set_exception)r r*ÚqueueZqueryZ awaitabler)ZexrrrÚ_asyncioLoopRunner[s,€   € €þôz*IsolatedAsyncioTestCase._asyncioLoopRunnercCs\|jdus Jdƒ‚t ¡}t |¡| d¡||_| ¡}| | |¡¡|_|  |¡dS)Nz%asyncio test loop already initializedT) r r+Znew_event_loopÚset_event_loopZ set_debugr%Z create_taskr2Z_asyncioCallsTaskr')r Úloopr*rrrÚ_setupAsyncioLoopns  z)IsolatedAsyncioTestCase._setupAsyncioLoopc Cs$|jdus Jdƒ‚|j}d|_|j d¡| |j ¡¡zct |¡}|s8W| | ¡¡t d¡|  ¡dS|D]}|  ¡q:| tj |ddiŽ¡|D]}|  ¡rUqN|  ¡durf| d|  ¡|dœ¡qN| | ¡¡W| | ¡¡t d¡|  ¡dS| | ¡¡t d¡|  ¡w)Nr"Zreturn_exceptionsTz(unhandled exception during test shutdown)ÚmessageÚ exceptionÚtask)r r r&r'Újoinr+Z all_tasksZshutdown_default_executorr3ÚcloseZcancelZgatherr-r7Zcall_exception_handlerZshutdown_asyncgens)r r4Z to_cancelr8rrrÚ_tearDownAsyncioLoopxsD    ë ÿ ý€  þ  z,IsolatedAsyncioTestCase._tearDownAsyncioLoopNcs*| ¡z tƒ |¡W| ¡S| ¡wr)r5rÚrunr;)r Úresultr rrr<œs zIsolatedAsyncioTestCase.runcs| ¡tƒ ¡| ¡dSr)r5rÚdebugr;rr rrr>£s  zIsolatedAsyncioTestCase.debugcCs|jdur | ¡dSdSr)r r;rrrrÚ__del__¨s  ÿzIsolatedAsyncioTestCase.__del__)rr)Ú__name__Ú __module__Ú __qualname__rrrrrrr r!rrr2r5r;r<r>r?Ú __classcell__rrr rrs"  $ r)r+r$ÚcaserrrrrrÚs