o à*¢gàã@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/lib/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)Ú 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._callTearDowncOrrr)r ÚfunctionrrrrrÚ _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 ÚinspectÚ 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.rrrr Qs   z'IsolatedAsyncioTestCase._callMaybeAsyncc Ãs¸t ¡|_}| d¡ | ¡IdH}| ¡|durdS|\}}z|IdH}| ¡s2| |¡Wn'ttfy=‚t tj fyZ}z| ¡sP|  |¡WYd}~nd}~wwqr) ÚasyncioÚQueuer Ú set_resultÚgetÚ task_doneÚ cancelledÚ SystemExitÚKeyboardInterruptÚ BaseExceptionÚCancelledErrorÚ set_exception)r r0ÚqueueÚqueryÚ awaitabler/ÚexrrrÚ_asyncioLoopRunner[s,€   € €þôz*IsolatedAsyncioTestCase._asyncioLoopRunnercCs\|jdus Jdƒ‚t ¡}t |¡| d¡||_| ¡}| | |¡¡|_|  |¡dS)Nz%asyncio test loop already initializedT) r r1Únew_event_loopÚset_event_loopÚ set_debugr+Ú create_taskr@Ú_asyncioCallsTaskr-)r Úloopr0rrrÚ_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'Úreturn_exceptionsTz(unhandled exception during test shutdown)ÚmessageÚ exceptionÚtask)r r r,r-Újoinr1Ú all_tasksÚshutdown_default_executorrBÚcloseÚcancelÚgatherr6rJÚcall_exception_handlerÚshutdown_asyncgens)r rFÚ to_cancelrKrrrÚ_tearDownAsyncioLoopxsD    ë ÿ ý€  þ  z,IsolatedAsyncioTestCase._tearDownAsyncioLoopNcs*| ¡z tƒ |¡W| ¡S| ¡wr)rGrÚrunrU)r Úresultr rrrVœs zIsolatedAsyncioTestCase.runcs| ¡tƒ ¡| ¡dSr)rGrÚdebugrUrr rrrX£s  zIsolatedAsyncioTestCase.debugcCs|jdur | ¡dSdSr)r rUrrrrÚ__del__¨s  ÿzIsolatedAsyncioTestCase.__del__)rr)Ú__name__Ú __module__Ú __qualname__rrrrrr"r$r&rr r@rGrUrVrXrYÚ __classcell__rrr rrs"  $ r)r1r)ÚcaserrrrrrÚs