%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/internet/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/internet/test/__pycache__/test_asyncioreactor.cpython-312.pyc

�

Ϫ�f�&��b�dZddlZddlZddlmZmZmZmZmZm	Z	m
Z
mZmZddl
mZddlmZddlmZddlmZdd	lmZd
Zd
Z	ej$j3d�rddlmZmZd
Zd
Ze�j;�Zeee�Z ejC�Gd�dee�Z"y#e$rY�BwxYw)z/
Tests for L{twisted.internet.asyncioreactor}.
�N)	�AbstractEventLoop�AbstractEventLoopPolicy�DefaultEventLoopPolicy�Future�SelectorEventLoop�get_event_loop�get_event_loop_policy�set_event_loop�set_event_loop_policy)�skipIf)�AsyncioSelectorReactor)�platform)�SynchronousTestCase�)�ReactorBuilderF�win32)�WindowsProactorEventLoopPolicy�WindowsSelectorEventLoopPolicyTc
��eZdZdZd�Zdedefd�Zee	djee�e
jje
jj ej$���d��Zee	djee�e
jje
jj ej$���d��Zee	d	jee�e
jje
jj ej$���d
��Zeed�d��Zeed
�d��Zeed�d��Zeed�d��Zd�Zd�Zd�Zd�Zy)�AsyncioSelectorReactorTestsz*
    L{AsyncioSelectorReactor} tests.
    c�����t�}g���fd�}|j|�|jd�|j�g�|j	�d��|j�dg�y)zn
        Ensure that C{reactor} has an event loop that works
        properly with L{asyncio.Future}.
        c�d���j|j���j�y�N)�append�result�stop)�future�reactorrs ���K/usr/lib/python3/dist-packages/twisted/internet/test/test_asyncioreactor.py�	completedzRAsyncioSelectorReactorTests.assertReactorWorksWithAsyncioFuture.<locals>.completed=s����M�M�&�-�-�/�*��L�L�N�Tr)�timeoutN)r�add_done_callback�
set_result�assertEqual�
runReactor)�selfrrr rs `  @r�#assertReactorWorksWithAsyncioFuturez?AsyncioSelectorReactorTests.assertReactorWorksWithAsyncioFuture5sf���
�����	�	� � ��+����$�������$�������+�����$��(r!�policy�returnc�����t��t��|j��|j���fd��}�S)z�
        Make a new asyncio loop from a policy for use with a reactor, and add
        appropriate cleanup to restore any global state.
        c�R���j�t��t��yr)�closer
r)�existingLoop�existingPolicyrs���r�cleanUpz4AsyncioSelectorReactorTests.newLoop.<locals>.cleanUpQs����L�L�N��<�(�!�.�1r!)rr	�new_event_loop�
addCleanup)r'r)r0r.r/rs   @@@r�newLoopz#AsyncioSelectorReactorTests.newLoopHs@���
&�'��.�0���&�&�(��	
���	2�
�	2�
�
r!zLdefault event loop: {}
is not of type SelectorEventLoop on Python {}.{} ({})c�:�t�}|j|�y)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'rs  r�-test_defaultSelectorEventLoopFromGlobalPolicyzIAsyncioSelectorReactorTests.test_defaultSelectorEventLoopFromGlobalPolicyYs��")�*���0�0��9r!c��|jt��}t|�}t|�|j	|�y)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)r3rr
r
r(�r'�
event_looprs   r�3test_newSelectorEventLoopFromDefaultEventLoopPolicyzOAsyncioSelectorReactorTests.test_newSelectorEventLoopFromDefaultEventLoopPolicyms6�� �\�\�"8�":�;�
�(��4���z�"��0�0��9r!zHdefault event loop: {}
is of type SelectorEventLoop on Python {}.{} ({})c�8�|jtt�y)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's r�1test_defaultNotASelectorEventLoopFromGlobalPolicyzMAsyncioSelectorReactorTests.test_defaultNotASelectorEventLoopFromGlobalPolicy�s��(	
���)�%;�<r!z&WindowsProactorEventLoop not availablec�l�|jt��}|jtt|�y)z�
        L{AsyncioSelectorReactor} will raise a L{TypeError}
        if instantiated with a L{asyncio.WindowsProactorEventLoop}
        N)r3rr<r=r
)r'r9s  r�test_WindowsProactorEventLoopz9AsyncioSelectorReactorTests.test_WindowsProactorEventLoop�s)���\�\�"@�"B�C�
����)�%;�Z�Hr!z(WindowsSelectorEventLoop only on Windowsc��|jt��}t|�}t|�|j	|�y)zR
        L{WindowsSelectorEventLoop} works with L{AsyncioSelectorReactor}
        N)r3rr
r
r(r8s   r�test_WindowsSelectorEventLoopz9AsyncioSelectorReactorTests.test_WindowsSelectorEventLoop�s6���\�\�"@�"B�C�
�(��4���z�"��0�0��9r!z.WindowsProactorEventLoopPolicy only on Windowsc��tt��|jd��|jt�5t�ddd�y#1swYyxYw)z�
        L{AsyncioSelectorReactor} will raise a L{TypeError}
        if L{asyncio.WindowsProactorEventLoopPolicy} is default.
        c��td�Sr�r�r!r�<lambda>zQAsyncioSelectorReactorTests.test_WindowsProactorEventLoopPolicy.<locals>.<lambda>���� 5�d� ;�r!N)rrr2r<r=r
r>s r�#test_WindowsProactorEventLoopPolicyz?AsyncioSelectorReactorTests.test_WindowsProactorEventLoopPolicy�sF��	�<�>�?����;�<�
�
�
�y�
)�	%�"�$�	%�	%�	%�s�A�Az.WindowsSelectorEventLoopPolicy only on Windowsc��tt��|jd��t�}|j	|�y)zy
        L{AsyncioSelectorReactor} will work if
        if L{asyncio.WindowsSelectorEventLoopPolicy} is default.
        c��td�SrrFrGr!rrHzQAsyncioSelectorReactorTests.test_WindowsSelectorEventLoopPolicy.<locals>.<lambda>�rIr!N)rrr2r
r(r5s  r�#test_WindowsSelectorEventLoopPolicyz?AsyncioSelectorReactorTests.test_WindowsSelectorEventLoopPolicy�s3��	�<�>�?����;�<�(�*���0�0��9r!c���tr%tt��|jd��t	�}|j�}|j
|d�|j|d�y)z0L{seconds} should return a plausible epoch time.c��td�SrrFrGr!rrHz:AsyncioSelectorReactorTests.test_seconds.<locals>.<lambda>����$9�$�$?�r!i�^l#G4N)�!hasWindowsSelectorEventLoopPolicyrrr2r
�seconds�
assertGreater�
assertLess)r'rrs   r�test_secondsz(AsyncioSelectorReactorTests.test_seconds�sT��,�!�"@�"B�C��O�O�?�@�(�*�����"��	
���6�:�.�	
����
�+r!c����tr%tt��|jd��t	��dg���fd�}�j�}�j
d|�}|jd��j
d�j��j�|j�d�|j�d|z
d�y)zQ
        L{DelayedCall.reset()} properly reschedules timer to later time
        c��td�SrrFrGr!rrHzJAsyncioSelectorReactorTests.test_delayedCallResetToLater.<locals>.<lambda>�rPr!Nc�,���j��d<y�Nr�rR�r�timer_called_ats��r�on_timerzJAsyncioSelectorReactorTests.test_delayedCallResetToLater.<locals>.on_timer�����!(���!2�O�A�r!r��?r皙�����?)rQrrr2r
rR�	callLater�resetr�run�assertIsNotNonerS)r'r]�
start_time�dcrr\s    @@r�test_delayedCallResetToLaterz8AsyncioSelectorReactorTests.test_delayedCallResetToLater�s����-�!�"@�"B�C��O�O�?�@�(�*���&��	3��_�_�&�
�
�
�
�q�(�
+��
����
����!�W�\�\�*����
����_�Q�/�0����?�1�-�
�:�C�@r!c�H���trtt��t��dg���fd�}�j	�}�jd|�}|j
d��jd�j�ddl}ddl	m
}|j�}||�5�j�ddd�|j|j�d�|j�d�|j!�d|z
d�trtd�yy#1swY�hxYw)	zS
        L{DelayedCall.reset()} properly reschedules timer to earlier time
        Nc�,���j��d<yrYrZr[s��rr]zLAsyncioSelectorReactorTests.test_delayedCallResetToEarlier.<locals>.on_timer�r^r!r_rr)�redirect_stderr�r`)rQrrr
rRrarbr�io�
contextlibrj�StringIOrcr%�getvaluerdrT)	r'r]rerfrlrj�stderrrr\s	       @@r�test_delayedCallResetToEarlierz:AsyncioSelectorReactorTests.test_delayedCallResetToEarlier�s����-�!�"@�"B�C�(�*���&��	3��_�_�&�
�
�
�
�s�H�
-��
��������!�W�\�\�*��.������
�V�
$�	��K�K�M�	�	
������*�B�/����_�Q�/�0������*�Z�7��=�,�!�$�'�-�
	�	�s� D�D!c�4�trtt��tj�}tj
�	t
tj��}d}t�}t|�D]}|jdd���|j�t
tj��}|j||z
|zd�|rtj�	trtd�yy#|rtj�wwxYw)zW
        L{AsyncioSelectorReactor.callLater()} doesn't leave cyclic references
        i�rc��yrrGrGr!rrHzOAsyncioSelectorReactorTests.test_noCycleReferencesInCallLater.<locals>.<lambda>s�r!rN)rQrr�gc�	isenabled�disable�len�get_objectsr
�rangera�runUntilCurrentrT�enable)r'�gc_was_enabled�objects_before�timer_countr�_�
objects_afters       r�!test_noCycleReferencesInCallLaterz=AsyncioSelectorReactorTests.test_noCycleReferencesInCallLaters���-�!�"@�"B�C������
�
�
��
	� ����!1�2�N��K�,�.�G��;�'�
3���!�!�!�\�2�
3��#�#�%����� 0�1�M��O�O�]�^�;�{�J�A�N���	�	��,�!�$�'�-����	�	���s
�BC>�>DN) �__name__�
__module__�__qualname__�__doc__r(rrr3r�_defaultEventLoopIsSelector�format�type�_defaultEventLoop�sys�version_info�major�minorr�getTyper6r:r?�!hasWindowsProactorEventLoopPolicyrArQrCrJrMrUrgrqr�rGr!rrr0s����)�&�5��:K��"�'�'�	�%�v��"�#����"�"����"�"��H����	 
�	�:�	�:��'�'�	�%�v��"�#����"�"����"�"��H����	 
�	�	:�	�	:��#�	�%�v��"�#����"�"����"�"��H����	 
�	�
=�	�
=��-�-�/W��I��I��-�-�2��:�	�:��-�-�8��%�	�%��-�-�8��:�	�:�,�A�0(�>(r!r)#r�rtr��asynciorrrrrrr	r
r�unittestr�twisted.internet.asyncioreactorr
�twisted.python.runtimer�twisted.trial.unittestr�
reactormixinsrr�rQ�
startswithrr�ImportErrorr1r��
isinstancer�r-rrGr!r�<module>r�s����
�
�
�
�
��B�+�6�)�$)�!�$)�!�
	�
�|�|���w�'�	
�
-1�)�,0�)�
+�,�;�;�=��(�):�<M�N������x(�.�2E�x(���	��	�s�'B&�&B.�-B.

Zerion Mini Shell 1.0