a €šçdàã@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)ÚselfÚ methodName©Ú __class__©ú+/usr/lib64/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)Ú addCleanup)r ÚfuncÚargsÚkwargsrrrÚaddAsyncCleanup,s z'IsolatedAsyncioTestCase.addAsyncCleanupcCs| ¡| |j¡dSr)ÚsetUpÚ _callAsyncrrrrrÚ _callSetUp;sz"IsolatedAsyncioTestCase._callSetUpcCs| |¡dSr©Ú_callMaybeAsync)r ÚmethodrrrÚ_callTestMethod?sz'IsolatedAsyncioTestCase._callTestMethodcCs| |j¡| ¡dSr)rrÚtearDownrrrrÚ _callTearDownBs z%IsolatedAsyncioTestCase._callTearDowncOs|j|g|¢Ri|¤ŽdSrr)r ÚfunctionrrrrrÚ _callCleanupFsz$IsolatedAsyncioTestCase._callCleanupcOs^|jdusJdƒ‚||i|¤Ž}t |¡s8J|›dƒ‚|j ¡}|j ||f¡|j |¡S)Nú$asyncio test loop is not initializedz returned non-awaitable©r ÚinspectÚ isawaitableÚ create_futurer Ú put_nowaitÚrun_until_complete©r rrrÚretÚfutrrrrIs  z"IsolatedAsyncioTestCase._callAsynccOsX|jdusJdƒ‚||i|¤Ž}t |¡rP|j ¡}|j ||f¡|j |¡S|SdS)Nr$r%r+rrrrQs   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ÚqueryÚ awaitabler,ÚexrrrÚ_asyncioLoopRunner[s   z*IsolatedAsyncioTestCase._asyncioLoopRunnercCs\|jdusJdƒ‚t ¡}t |¡| d¡||_| ¡}| | |¡¡|_|  |¡dS)Nz%asyncio test loop already initializedT) r r.Únew_event_loopÚset_event_loopÚ set_debugr(Ú create_taskr=Ú_asyncioCallsTaskr*)r Úloopr-rrrÚ_setupAsyncioLoopns  z)IsolatedAsyncioTestCase._setupAsyncioLoopc Cs&|jdusJdƒ‚|j}d|_|j d¡| |j ¡¡zÄt |¡}|spW| | ¡¡t d¡|  ¡dS|D] }|  ¡qt| tj |ddiŽ¡|D]0}|  ¡rªqœ|  ¡durœ| d|  ¡|dœ¡qœ| | ¡¡W| | ¡¡t d¡|  ¡n"| | ¡¡t d¡|  ¡0dS)Nr$Úreturn_exceptionsTz(unhandled exception during test shutdown)ÚmessageÚ exceptionÚtask)r r r)r*Újoinr.Ú all_tasksÚshutdown_default_executorr?ÚcloseÚcancelÚgatherr3rGÚcall_exception_handlerÚshutdown_asyncgens)r rCÚ to_cancelrHrrrÚ_tearDownAsyncioLoopxsD   é ÿ ý   þ z,IsolatedAsyncioTestCase._tearDownAsyncioLoopNcs.| ¡ztƒ |¡W| ¡S| ¡0dSr)rDrÚrunrR)r Úresultr rrrSœs  þzIsolatedAsyncioTestCase.runcs| ¡tƒ ¡| ¡dSr)rDrÚdebugrRrr rrrU£s zIsolatedAsyncioTestCase.debugcCs|jdur| ¡dSr)r rRrrrrÚ__del__¨s zIsolatedAsyncioTestCase.__del__)r)N)Ú__name__Ú __module__Ú __qualname__rrrrrrr!r#rrr=rDrRrSrUrVÚ __classcell__rrr rrs   $ r)r.r&ÚcaserrrrrrÚs