f ž _²ã@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/lib64/python3.10/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._callCleanupcOs4||i|¤Ž}|j ¡}|j ||f¡|j |¡Sr)r Ú create_futurer Ú put_nowaitÚrun_until_complete©r rrrÚretÚfutrrrrJs z"IsolatedAsyncioTestCase._callAsynccOsB||i|¤Ž}t |¡r>|j ¡}|j ||f¡|j |¡S|Sr)ÚinspectZ isawaitabler r r r!r"r#rrrrRs    z'IsolatedAsyncioTestCase._callMaybeAsyncc Ãs¶t ¡|_}| d¡| ¡IdH}| ¡|dur:dS|\}}z |IdH}| ¡s`| |¡Wqttfyz‚Yqt tj fy´}z| ¡s |  |¡WYd}~qd}~00r) ÚasyncioÚQueuer Ú set_resultÚgetÚ task_doneÚ cancelledÚ SystemExitÚKeyboardInterruptÚ BaseExceptionÚCancelledErrorÚ set_exception)r r%ÚqueueÚqueryZ awaitabler$ÚexrrrÚ_asyncioLoopRunner\s   z*IsolatedAsyncioTestCase._asyncioLoopRunnercCsJt ¡}t |¡| d¡||_| ¡}| | |¡¡|_|  |¡dS)NT) r'Znew_event_loopÚset_event_loopZ set_debugr r Z create_taskr5Z_asyncioCallsTaskr")r Úloopr%rrrÚ_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)r7Zreturn_exceptionsz(unhandled exception during test shutdown)ÚmessageÚ exceptionÚtask)r r r!r"Újoinr'Z all_tasksr6ÚcloseÚcancelZgatherr,r:Zcall_exception_handlerZshutdown_asyncgens)r r7Z to_cancelr;rrrÚ_tearDownAsyncioLoopys<   ë ÿ ý   ÿ z,IsolatedAsyncioTestCase._tearDownAsyncioLoopNcs*| ¡ztƒ |¡W| ¡S| ¡0r)r8rÚrunr?)r Úresultr rrr@›s  þzIsolatedAsyncioTestCase.run)r)N)Ú__name__Ú __module__Ú __qualname__rrrrrrrrrrr5r8r?r@Ú __classcell__rrr rrs  "r)r'r&ZcaserrrrrrÚs