a :êdg²ã@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‡ZS)!ÚIsolatedAsyncioTestCaseÚrunTestcstƒ |¡d|_d|_dS©N)ÚsuperÚ__init__Ú_asyncioTestLoopÚ_asyncioCallsQueue)ÚselfZ methodName©Ú __class__©ú//usr/local/lib/python3.9/unittest/async_case.pyr"s z IsolatedAsyncioTestCase.__init__cÃsdSrr©r rrrÚ asyncSetUp'sz"IsolatedAsyncioTestCase.asyncSetUpcÃsdSrrrrrrÚ asyncTearDown*sz%IsolatedAsyncioTestCase.asyncTearDowncOs|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Ú _callTearDownCs z%IsolatedAsyncioTestCase._callTearDowncOs|j|g|¢Ri|¤ŽdSrr)r ÚfunctionrrrrrÚ _callCleanupGsz$IsolatedAsyncioTestCase._callCleanupcOsP|jdusJ‚||i|¤Ž}t |¡s*J‚|j ¡}|j ||f¡|j |¡Sr©r ÚinspectZ isawaitableÚ create_futurer Ú put_nowaitÚrun_until_complete©r rrrÚretÚfutrrrrJs  z"IsolatedAsyncioTestCase._callAsynccOsT|jdusJ‚||i|¤Ž}t |¡rL|j ¡}|j ||f¡|j |¡S|SdSrr r%rrrrRs   z'IsolatedAsyncioTestCase._callMaybeAsyncc Ãs¼t ¡|_}| d¡| ¡IdH}| ¡|dur:dS|\}}z |IdH}| ¡s`| |¡Wqttfyz‚Yqt tj fy´}z| ¡s |  |¡WYd}~qd}~00qdSr) ÚasyncioÚQueuer Ú set_resultÚgetÚ task_doneÚ cancelledÚ SystemExitÚKeyboardInterruptÚ BaseExceptionÚCancelledErrorÚ set_exception)r r'ÚqueueÚqueryZ awaitabler&ÚexrrrÚ_asyncioLoopRunner\s   z*IsolatedAsyncioTestCase._asyncioLoopRunnercCsX|jdusJ‚t ¡}t |¡| d¡||_| ¡}| | |¡¡|_|  |¡dS)NT) r r(Znew_event_loopÚset_event_loopZ set_debugr"Z create_taskr6Z_asyncioCallsTaskr$)r Úloopr'rrrÚ_setupAsyncioLoopos  z)IsolatedAsyncioTestCase._setupAsyncioLoopc Csú|jdusJ‚|j}d|_|j d¡| |j ¡¡zªt |¡}|s^Wt d¡| ¡dS|D] }|  ¡qb| tj ||ddœŽ¡|D]0}|  ¡ršqŒ|  ¡durŒ|  d|  ¡|dœ¡qŒ| | ¡¡Wt d¡| ¡nt d¡| ¡0dS)NT)r8Zreturn_exceptionsz(unhandled exception during test shutdown)ÚmessageÚ exceptionÚtask)r r r#r$Újoinr(Z all_tasksr7ÚcloseÚcancelZgatherr-r;Zcall_exception_handlerZshutdown_asyncgens)r r8Z to_cancelr<rrrÚ_tearDownAsyncioLoopys>   ë ÿ ý   ÿ z,IsolatedAsyncioTestCase._tearDownAsyncioLoopNcs.| ¡ztƒ |¡W| ¡S| ¡0dSr)r9rÚrunr@)r Úresultr rrrA›s  þzIsolatedAsyncioTestCase.run)r)N)Ú__name__Ú __module__Ú __qualname__rrrrrrrrrrr6r9r@rAÚ __classcell__rrr rrs  "r)r(r!ZcaserrrrrrÚs