Sindbad~EG File Manager
�
(ΜgZ � � � d Z ddlZddlZddlmZ ddlmZ d� Z G d� dej � Ze dk( r ej � yy) zTests for asyncio/threads.py� N)�
ContextVar)�mockc �. � t j d � y �N)�asyncio�set_event_loop_policy� � �;/usr/local/lib/python3.12/test/test_asyncio/test_threads.py�tearDownModuler
s � ��!�!�$�'r
c �0 � e Zd Zd� Zd� Zd� Zd� Zd� Zd� Zy)�
ToThreadTestsc � �| K � t j t ddg� � d { ��� }| j |d� y 7 ��w)N�( � �* )r � to_thread�sum�assertEqual)�self�results r �test_to_threadzToThreadTests.test_to_thread s4 � �� ��(�(��r�1�g�6�6�������$� 7�s � <�:�<c � � K � d� }| j t d� 5 t j |� � d { ��� d d d � y 7 �
# 1 sw Y y xY 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 sE � �� � '� �
#�
#�L�&�
9��#�#�M�2�2�2� :�
9�2�� :�
9�s+ �A�A�A�A� A�A�A�
Ac � � K � t j � }t j |� � d { ��� |j � y 7 ��wr )r �Mockr r �assert_called_once�r �funcs r �test_to_thread_oncez!ToThreadTests.test_to_thread_once s6 � �� ��y�y�{������%�%�%����!� &�s �-A�A�Ac � � 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 sm � �� ��y�y�{�����r��A��#�#�D�)�C��K�K��� � �n�n�d�#�#�#�������"�-� $�s �A"B�$B�%"Bc � � K � t j � }t j |dd�� � d { ��� |j dd�� 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 � �� ��y�y�{������f��=�=�=��$�$�V�t�$�<� >�s �0A
�A�A
c � � �K � t d� ��fd�}�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�������*� 2�s �:A�A�AN) �__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<