U e5d²ã@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.8/unittest/async_case.pyr"s z IsolatedAsyncioTestCase.__init__cÃsdSrr©r rrrÚ asyncSetUp'sz"IsolatedAsyncioTestCase.asyncSetUpcÃsdSrrrrrrÚ asyncTearDown*sz%IsolatedAsyncioTestCase.asyncTearDowncOs|j|f|˜|Ž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|f|ž|ŽdSrr)r ZfunctionrrrrrÚ _callCleanupGsz$IsolatedAsyncioTestCase._callCleanupcOs0|||Ž}|j ¡}|j ||f¡|j |¡Sr)r Ú create_futurer Ú put_nowaitÚrun_until_complete©r rrrÚretÚfutrrrrJs  z"IsolatedAsyncioTestCase._callAsynccOsB|||Ž}t |¡r:|j ¡}|j ||f¡|j |¡S|SdSr)ÚinspectZ isawaitabler rr r r!r"rrrrRs     z'IsolatedAsyncioTestCase._callMaybeAsyncc Ãs¼t ¡|_}| d¡| ¡IdH}| ¡|dkr:dS|\}}z |IdH}| ¡s`| |¡Wqttfk r|‚Yqt tj fk r´}z| ¡s¤|  |¡W5d}~XYqXqdSr) ÚasyncioZQueuer Z set_resultÚgetZ task_doneÚ cancelledÚ SystemExitÚKeyboardInterruptÚ BaseExceptionZCancelledErrorZ set_exception)r r$ZqueueZqueryZ awaitabler#ZexrrrÚ_asyncioLoopRunner\s   z*IsolatedAsyncioTestCase._asyncioLoopRunnercCsJt ¡}t |¡| d¡||_| ¡}| | |¡¡|_|  |¡dS)NT) r&Znew_event_loopÚset_event_loopZ set_debugr rZ create_taskr,Z_asyncioCallsTaskr!)r Úloopr$rrrÚ_setupAsyncioLoopos  z)IsolatedAsyncioTestCase._setupAsyncioLoopc CsÊ|j}d|_|j d¡| |j ¡¡zˆt |¡}|s@W¢vdS|D] }|  ¡qD| tj ||ddœŽ¡|D]0}|  ¡r|qn|  ¡dk rn|  d|  ¡|dœ¡qn| | ¡¡W5t d¡| ¡XdS)NT)r.Zreturn_exceptionsz(unhandled exception during test shutdown)ÚmessageÚ exceptionÚtask)r r r r!Újoinr&r-ÚcloseZ all_tasksZcancelZgatherr(r1Zcall_exception_handlerZshutdown_asyncgens)r r.Z to_cancelr2rrrÚ_tearDownAsyncioLoopys2   ÿ ý  z,IsolatedAsyncioTestCase._tearDownAsyncioLoopNcs(| ¡ztƒ |¡W¢S| ¡XdSr)r/r5rÚrun)r Úresultr rrr6›szIsolatedAsyncioTestCase.run)r)N)Ú__name__Ú __module__Ú __qualname__rrrrrrrrrrr,r/r5r6Ú __classcell__rrr rrs  "r)r&r%ZcaserrrrrrÚs