
    dafZ                         d Z ddlZddlZddlmZ ddlmZ d Z G d dej                        Ze	dk(  r ej                          yy)	zTests for asyncio/threads.py    N)
ContextVar)mockc                  .    t        j                  d        y N)asyncioset_event_loop_policy     9/root/Python-3.12.4/Lib/test/test_asyncio/test_threads.pytearDownModuler   
   s    !!$'r
   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)ToThreadTestsc                 |   K   t        j                  t        ddg       d {   }| j                  |d       y 7 w)N(      *   )r   	to_threadsumassertEqual)selfresults     r   test_to_threadzToThreadTests.test_to_thread   s4     ((r1g66$ 7s    <:<c                    K   d }| j                  t        d      5  t        j                  |       d {    d d d        y 7 # 1 sw Y   y xY ww)Nc                      t        d      )Ntest)RuntimeErrorr	   r
   r   raise_runtimez=ToThreadTests.test_to_thread_exception.<locals>.raise_runtime   s    v&&r
   r   )assertRaisesRegexr   r   r   )r   r   s     r   test_to_thread_exceptionz&ToThreadTests.test_to_thread_exception   sN     	' ##L&9 	3##M222	3 	32	3 	3s+   AAAA	AAA
Ac                    K   t        j                         }t        j                  |       d {    |j	                          y 7 wr   )r   Mockr   r   assert_called_oncer   funcs     r   test_to_thread_oncez!ToThreadTests.test_to_thread_once   s6     yy{%%%! 	&s   -AAAc                   K   t        j                         }g }t        d      D ](  }t        j                  |      }|j                  |       * t        j                  |  d {    | j                  |j                  d       y 7 !w)N
   )	r   r!   ranger   r   appendgatherr   
call_count)r   r$   futs_futs        r   test_to_thread_concurrentz'ToThreadTests.test_to_thread_concurrent    sr     yy{r 	A##D)CKK	 nnd###"- 	$s   A"B$B%"Bc                    K   t        j                         }t        j                  |dd       d {    |j	                  dd       y 7 w)Nr   T)	something)r   r!   r   r   assert_called_once_withr#   s     r   test_to_thread_args_kwargsz(ToThreadTests.test_to_thread_args_kwargs+   sA     yy{f===$$Vt$< 	>s   0AAAc                    K   t        d      fd}j                  d       t        j                  |       d {   }| j	                  |d       y 7 w)Ntest_ctxc                  $     j                         S r   )get)r5   s   r   get_ctxz9ToThreadTests.test_to_thread_contextvars.<locals>.get_ctx6   s    <<>!r
   parrot)r   setr   r   r   )r   r8   r   r5   s      @r   test_to_thread_contextvarsz(ToThreadTests.test_to_thread_contextvars3   sL     j)	" 	X((11* 2s   :AAAN)	__name__
__module____qualname__r   r   r%   r/   r3   r;   r	   r
   r   r   r      s     %3"	.=	+r
   r   __main__)__doc__r   unittestcontextvarsr   r   r   IsolatedAsyncioTestCaser   r<   mainr	   r
   r   <module>rE      sF    "   " (.+H44 .+b zHMMO r
   