o
    JXhZ                     @   s\   	 d dl Z d dlZd dlmZ d dlmZ dd ZG dd dejZedkr,e	  dS dS )	    N)
ContextVar)mockc                   C   s   t d  d S N)asyncioZset_event_loop_policy r   r   H/opt/python-3.10.19/usr/lib/python3.10/test/test_asyncio/test_threads.pytearDownModule
   s   r   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )ToThreadTestsc                    s(   t tddgI d H }| |d d S )N(      *   )r   	to_threadsumassertEqual)selfresultr   r   r   test_to_thread   s   zToThreadTests.test_to_threadc                    sL   dd }|  td t|I d H  W d    d S 1 sw   Y  d S )Nc                   S   s   t d)Ntest)RuntimeErrorr   r   r   r   raise_runtime      z=ToThreadTests.test_to_thread_exception.<locals>.raise_runtimer   )ZassertRaisesRegexr   r   r   )r   r   r   r   r   test_to_thread_exception   s
   "z&ToThreadTests.test_to_thread_exceptionc                    s&   t  }t|I d H  |  d S r   )r   Mockr   r   Zassert_called_oncer   funcr   r   r   test_to_thread_once   s   z!ToThreadTests.test_to_thread_oncec                    sR   t  }g }tdD ]}t|}|| qtj| I d H  | |jd d S )N
   )	r   r   ranger   r   appendZgatherr   Z
call_count)r   r   Zfuts_futr   r   r   test_to_thread_concurrent    s   
z'ToThreadTests.test_to_thread_concurrentc                    s2   t  }tj|dddI d H  |jddd d S )Nr   T)Z	something)r   r   r   r   Zassert_called_once_withr   r   r   r   test_to_thread_args_kwargs+   s   z(ToThreadTests.test_to_thread_args_kwargsc                    s@   t d  fdd} d t|I d H }| |d d S )Ntest_ctxc                      s      S r   )getr   r#   r   r   get_ctx6   r   z9ToThreadTests.test_to_thread_contextvars.<locals>.get_ctxZparrot)r   setr   r   r   )r   r&   r   r   r%   r   test_to_thread_contextvars3   s   
z(ToThreadTests.test_to_thread_contextvarsN)	__name__
__module____qualname__r   r   r   r!   r"   r(   r   r   r   r   r	      s    r	   __main__)
r   ZunittestZcontextvarsr   r   r   ZIsolatedAsyncioTestCaser	   r)   mainr   r   r   r   <module>   s    1