File: //lib/python3/dist-packages/twisted/internet/test/__pycache__/test_asyncioreactor.cpython-310.pyc
o
�bo$ � @ s� d Z ddlZddlZddlmZmZmZmZmZ ddl m
Z
ddlmZ ddl
mZ ddlmZ dd lmZ d
Zd
Zzej�d�rMddlmZmZ d
Zd
ZW n eyW Y nw G dd� dee�ZdS )z/
Tests for L{twisted.internet.asyncioreactor}.
� N)�DefaultEventLoopPolicy�Future�SelectorEventLoop�set_event_loop�set_event_loop_policy)�skipIf)�AsyncioSelectorReactor)�platform)�SynchronousTestCase� )�ReactorBuilderF�win32)�WindowsProactorEventLoopPolicy�WindowsSelectorEventLoopPolicyTc @ s* e Zd ZdZe� �� Zeee�Z dd� Z
ee d�e
e�ejjejje�� ��dd� �Zee d�e
e�ejjejje�� ��dd� �Zee d �e
e�ejjejje�� ��d
d� �Zee d�d
d� �Zee d�dd� �Zee d�dd� �Zee d�dd� �Zdd� Zdd� Zdd� Zdd� Z d S )!�AsyncioSelectorReactorTestsz*
L{AsyncioSelectorReactor} tests.
c sX t � }g �� �fdd�}|�|� |�d� | ��g � | j� dd� | ��dg� dS )zn
Ensure that C{reactor} has an event loop that works
properly with L{asyncio.Future}.
c s �� | �� � � �� d S �N)�append�result�stop)�future��reactorr � �K/usr/lib/python3/dist-packages/twisted/internet/test/test_asyncioreactor.py� completed7 s zRAsyncioSelectorReactorTests.assertReactorWorksWithAsyncioFuture.<locals>.completedTr )�timeoutN)r �add_done_callback�
set_result�assertEqual�
runReactor)�selfr r r r r r �#assertReactorWorksWithAsyncioFuture/ s
z?AsyncioSelectorReactorTests.assertReactorWorksWithAsyncioFuturezLdefault event loop: {}
is not of type SelectorEventLoop on Python {}.{} ({})c C s t � }| �|� dS )a
L{AsyncioSelectorReactor} wraps the global policy's event loop
by default. This ensures that L{asyncio.Future}s and
coroutines created by library code that uses
L{asyncio.get_event_loop} are bound to the same loop.
N)r r! �r r r r r �-test_defaultSelectorEventLoopFromGlobalPolicyB s zIAsyncioSelectorReactorTests.test_defaultSelectorEventLoopFromGlobalPolicyc C �0 t � �� }t|�}t|� | �|� td� dS )z�
If we use the L{asyncio.DefaultLoopPolicy} to create a new event loop,
and then pass that event loop to a new L{AsyncioSelectorReactor},
this reactor should work properly with L{asyncio.Future}.
N)r �new_event_loopr r r! r �r �
event_loopr r r r �3test_newSelectorEventLoopFromDefaultEventLoopPolicyV s
zOAsyncioSelectorReactorTests.test_newSelectorEventLoopFromDefaultEventLoopPolicyzHdefault event loop: {}
is of type SelectorEventLoop on Python {}.{} ({})c C s | � tt� dS )ay
On Windows Python 3.5 to 3.7, L{get_event_loop()} returns a
L{WindowsSelectorEventLoop} by default.
On Windows Python 3.8+, L{get_event_loop()} returns a
L{WindowsProactorEventLoop} by default.
L{AsyncioSelectorReactor} should raise a
L{TypeError} if the default event loop is not a
L{WindowsSelectorEventLoop}.
N)�assertRaises� TypeErrorr �r r r r �1test_defaultNotASelectorEventLoopFromGlobalPolicyl s zMAsyncioSelectorReactorTests.test_defaultNotASelectorEventLoopFromGlobalPolicyz&WindowsProactorEventLoop not availablec C s t � �� }| �tt|� dS )z�
L{AsyncioSelectorReactor} will raise a L{TypeError}
if instantiated with a L{asyncio.WindowsProactorEventLoop}
N)r r% r) r* r )r r'