a  ze @sbddlZddlZddlmZddlmZddlmZddZGdddej Z e d kr^e dS) N) ContextVar)mock)utilscCstddSN)asyncioZset_event_loop_policyrrR/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_asyncio/test_threads.pytearDownModule sr csXeZdZfddZfddZddZddZd d Zd d Zd dZ ddZ Z S) ToThreadTestscs$tt|_t|jdSr)supersetUprZnew_event_looploopset_event_loopself __class__rrr s  zToThreadTests.setUpcs:|j|j|jtdd|_tdSr)r run_until_completeZshutdown_default_executorcloserrr tearDownrrrrrs  zToThreadTests.tearDowncCs&dd}|j|}||ddS)NcsttddgIdHS)N()r to_threadsumrrrrmainsz*ToThreadTests.test_to_thread..main*)r r assertEqualrrresultrrrtest_to_threadszToThreadTests.test_to_threadcsRddfdd}|td|j|Wdn1sD0YdS)NcSs tddS)Ntest) RuntimeErrorrrrr raise_runtime%sz=ToThreadTests.test_to_thread_exception..raise_runtimecstIdHdSrrrrr"rrr(sz4ToThreadTests.test_to_thread_exception..mainr )ZassertRaisesRegexr!r rrrrr$rtest_to_thread_exception$s z&ToThreadTests.test_to_thread_exceptioncs.tfdd}|j|dS)NcstIdHdSrr#rfuncrrr1sz/ToThreadTests.test_to_thread_once..main)rMockr rZassert_called_oncer%rr'rtest_to_thread_once.s z!ToThreadTests.test_to_thread_oncecs4tfdd}|j||jddS)Ncs:g}tdD]}t}||q tj|IdHdS)N )rangerrappendZgather)Zfuts_Zfutr'rrr:s    z5ToThreadTests.test_to_thread_concurrent..mainr+)rr)r rrZ call_countr%rr'rtest_to_thread_concurrent7s z'ToThreadTests.test_to_thread_concurrentcs4tfdd}|j|jddddS)NcstjdddIdHdS)Nr TZ somethingr#rr'rrrHsz6ToThreadTests.test_to_thread_args_kwargs..mainr Tr0)rr)r rZassert_called_once_withr%rr'rtest_to_thread_args_kwargsDs z(ToThreadTests.test_to_thread_args_kwargscs@tdfddfdd}|j|}||ddS)Ntest_ctxcsSr)getr)r2rrget_ctxQsz9ToThreadTests.test_to_thread_contextvars..get_ctxcsdtIdHS)Nparrot)setrrrr4r2rrrTs z6ToThreadTests.test_to_thread_contextvars..mainr5)rr rrrrr7rtest_to_thread_contextvarsNs  z(ToThreadTests.test_to_thread_contextvars) __name__ __module__ __qualname__r rrr&r*r/r1r8 __classcell__rrrrr s      r __main__) rZunittestZ contextvarsrrZtest.test_asynciorZ test_utilsr ZTestCaser r9rrrrrs   M