Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_contextlib_async.cpython-39.pyc

a

��g�@�@s�ddlZddlmZmZmZddlZddlmZddlZddl	m
Z
dd�ZGdd�dej�Z
Gd	d
�d
ej�ZGdd�de
ej�Zed
kr�e��dS)�N)�asynccontextmanager�AbstractAsyncContextManager�AsyncExitStack)�support)�TestBaseExitStackcst����fdd��}|S)z5Decorator to turn an async function into a test case.c	sX�|i|��}t��}t�|�z|�|�W|��t�d�S|��t�d�0dS�N)�asyncio�new_event_loop�set_event_loopZrun_until_complete�close�set_event_loop_policy)�args�kwargs�coro�loop��func��6/usr/local/lib/python3.9/test/test_contextlib_async.py�wrappers


��z_async_test.<locals>.wrapper)�	functools�wraps)rrrrr�_async_test
s	rc@s4eZdZedd��Zedd��Zdd�Zdd�Zd	S)
�TestAbstractAsyncContextManagerc	�stGdd�dt�}|�}|�|��IdH|�|4IdH�"}|�||�Wd�IdHqp1IdHsf0YdS)NcseZdZ�fdd�Z�ZS)z@TestAbstractAsyncContextManager.test_enter.<locals>.DefaultEnterc�st�j|�IdHdSr��super�	__aexit__��selfr
��	__class__rrrszJTestAbstractAsyncContextManager.test_enter.<locals>.DefaultEnter.__aexit__��__name__�
__module__�__qualname__r�
__classcell__rrrr�DefaultEntersr&)r�assertIs�
__aenter__)rr&�manager�contextrrr�
test_enters
z*TestAbstractAsyncContextManager.test_enterc
�s�tdd����fdd�}g}td�}|�t��n��4IdH�:|�2z3dHW}|�|�|�qF6Wd�IdHq�1IdHs�0YWd�n1s�0Y|�|dg�dS)NcSs
dVdSrrrrrr�ctx+szUTestAbstractAsyncContextManager.test_async_gen_propagates_generator_exit.<locals>.ctxc	sD��4IdH�dVWd�IdHq@1IdHs60YdS)N�rr�r,rr�gen/szUTestAbstractAsyncContextManager.test_async_gen_propagates_generator_exit.<locals>.gen�r-)r�
ValueError�assertRaises�append�assertEqual)rr/�ret�exc�valrr.r�(test_async_gen_propagates_generator_exit's

PzHTestAbstractAsyncContextManager.test_async_gen_propagates_generator_exitcCsDGdd�dt�}|�t��|�Wd�n1s60YdS)Nc@seZdZdS)zKTestAbstractAsyncContextManager.test_exit_is_abstract.<locals>.MissingAexitN�r"r#r$rrrr�MissingAexit>sr:)rr2�	TypeError)rr:rrr�test_exit_is_abstract=sz5TestAbstractAsyncContextManager.test_exit_is_abstractcCs�Gdd�d�}|�t|t��Gdd�dt�}|�t|t��Gdd�d|�}|�t|t��Gdd�d|�}|�t|t��dS)	Nc@seZdZdd�Zdd�ZdS)zWTestAbstractAsyncContextManager.test_structural_subclassing.<locals>.ManagerFromScratchc�s|Srr�rrrrr(FszbTestAbstractAsyncContextManager.test_structural_subclassing.<locals>.ManagerFromScratch.__aenter__c�sdSrr)r�exc_type�	exc_value�	tracebackrrrrHszaTestAbstractAsyncContextManager.test_structural_subclassing.<locals>.ManagerFromScratch.__aexit__N�r"r#r$r(rrrrr�ManagerFromScratchEsrBcseZdZ�fdd�Z�ZS)zQTestAbstractAsyncContextManager.test_structural_subclassing.<locals>.DefaultEnterc�st�j|�IdHdSrrrrrrrNsz[TestAbstractAsyncContextManager.test_structural_subclassing.<locals>.DefaultEnter.__aexit__r!rrrrr&Msr&c@seZdZdZdS)zOTestAbstractAsyncContextManager.test_structural_subclassing.<locals>.NoneAenterN)r"r#r$r(rrrr�
NoneAenterSsrCc@seZdZdZdS)zNTestAbstractAsyncContextManager.test_structural_subclassing.<locals>.NoneAexitN)r"r#r$rrrrr�	NoneAexitXsrD)Z
assertTrue�
issubclassr�assertFalse)rrBr&rCrDrrr�test_structural_subclassingDsz;TestAbstractAsyncContextManager.test_structural_subclassingN)r"r#r$rr+r8r<rGrrrrrs

rc@s�eZdZedd��Zedd��Zedd��Zedd��Zed	d
��Zedd��Z	ed
d��Z
edd��Zedd��Zedd��Z
dd�Zdd�Zejdd��Zejedd���Zedd��ZdS) �AsyncContextManagerTestCasec	�s�g�t�fdd��}|�4IdH�:}|��dg�|�|d���|�Wd�IdHqr1IdHsh0Y|��gd��dS)Ncs��d�dV��d�dS�N��*���r3r��staterr�woohoocs
zEAsyncContextManagerTestCase.test_contextmanager_plain.<locals>.woohoorJrK�rJrKrL)rr4r3�rrP�xrrNr�test_contextmanager_plain`s4z5AsyncContextManagerTestCase.test_contextmanager_plainc
�s�g�t�fdd��}|�t��t|�4IdH�@}|��dg�|�|d���|�t��Wd�IdHq�1IdHsz0YWd�n1s�0Y|��gd��dS)Nc	s0��d�zdVW��d�n��d�0dSrIrMrrNrrrPqs
zGAsyncContextManagerTestCase.test_contextmanager_finally.<locals>.woohoorJrKrQ)rr2�ZeroDivisionErrorr4r3rRrrNr�test_contextmanager_finallyns
Nz7AsyncContextManagerTestCase.test_contextmanager_finallyc�sBtdd��}|�}|��IdH|�|�ttd�d�IdH�dS)NcSs
dVdSrrrrrr�whee�szHAsyncContextManagerTestCase.test_contextmanager_no_reraise.<locals>.whee�foo)rr(rFrr;)rrWr,rrr�test_contextmanager_no_reraise�s

z:AsyncContextManagerTestCase.test_contextmanager_no_reraisec�sftdd��}|�}|��IdH|�t��(|�ttd�d�IdHWd�n1sX0YdS)NcSs"z
dVWndVYn0dSrrrrrr�whoo�s
zTAsyncContextManagerTestCase.test_contextmanager_trap_yield_after_throw.<locals>.whoorX)rr(r2�RuntimeErrorrr;�rrZr,rrr�*test_contextmanager_trap_yield_after_throw�s
zFAsyncContextManagerTestCase.test_contextmanager_trap_yield_after_throwc�sNtdd��}|�}|�t��|��IdHWd�n1s@0YdS)NcSsdSrrrrrrrZ�szKAsyncContextManagerTestCase.test_contextmanager_trap_no_yield.<locals>.whoo)rr2r[r(r\rrr�!test_contextmanager_trap_no_yield�s

z=AsyncContextManagerTestCase.test_contextmanager_trap_no_yieldc�sbtdd��}|�}|��IdH|�t��$|�ddd�IdHWd�n1sT0YdS)NcSsdVdVdSrrrrrrrZ�szOAsyncContextManagerTestCase.test_contextmanager_trap_second_yield.<locals>.whoo)rr(r2r[rr\rrr�%test_contextmanager_trap_second_yield�s
zAAsyncContextManagerTestCase.test_contextmanager_trap_second_yieldc�sbtdd��}|�}|��IdH|�t��$|�tdd�IdHWd�n1sT0YdS)NcSs&z
dVWnty t�Yn0dSr)r[�SyntaxErrorrrrrrZ�s
zLAsyncContextManagerTestCase.test_contextmanager_non_normalised.<locals>.whoo)rr(r2r`rr[r\rrr�"test_contextmanager_non_normalised�s
z>AsyncContextManagerTestCase.test_contextmanager_non_normalisedc	�s�g�t��fdd��}|�4IdH�B}���dg���|d���|�td��Wd�IdHq|1IdHsr0Y���gd��dS)Nc
s^��d�z
dVWnDtyX}z,��|jd����gd��WYd}~n
d}~00dS)NrJrKrrQ)r3rUr
r4)�e�rrOrrrP�s

zFAsyncContextManagerTestCase.test_contextmanager_except.<locals>.woohoorJrKrLrQ)rr4r3rUrRrrcr�test_contextmanager_except�s
2z6AsyncContextManagerTestCase.test_contextmanager_exceptc�stdd��}Gdd�dt�}Gdd�dt�}td�td�|d�|d�fD]�}|jt|�d	���zB|�4IdH�|�Wd�IdHq�1IdHs�0YWn0ty�}z|�||�WYd}~nd}~00|�|�d
��Wd�qH1s�0YqHdS)NcSs
dVdSrrrrrrrP�szOAsyncContextManagerTestCase.test_contextmanager_except_stopiter.<locals>.woohooc@seZdZdS)z^AsyncContextManagerTestCase.test_contextmanager_except_stopiter.<locals>.StopIterationSubclassNr9rrrr�StopIterationSubclass�srec@seZdZdS)zcAsyncContextManagerTestCase.test_contextmanager_except_stopiter.<locals>.StopAsyncIterationSubclassNr9rrrr�StopAsyncIterationSubclass�srf�spamZham)�typez was suppressed)r�
StopIteration�StopAsyncIteration�subTestrh�	Exceptionr'�fail)rrPrerfZstop_exc�exrrr�#test_contextmanager_except_stopiter�s 
�2"z?AsyncContextManagerTestCase.test_contextmanager_except_stopiterc
�s�tdd��}|�t��R|�4IdH�ddWd�IdHqZ1IdHsP0YWd�n1sn0Y|�t��N|�4IdH�t�Wd�IdHq�1IdHs�0YWd�n1s�0YdS)Nc
SsDz
dVWn4ty>}ztd|���|�WYd}~n
d}~00dS)Nzcaught )rlr[�r6rrrrP�s
zQAsyncContextManagerTestCase.test_contextmanager_wrap_runtimeerror.<locals>.woohoorJr)rr2r[rj)rrPrrr�%test_contextmanager_wrap_runtimeerror�s
PzAAsyncContextManagerTestCase.test_contextmanager_wrap_runtimeerrorcCs"dd�}t|dd�dd���}|S)Ncs�fdd�}|S)Ncs"���D]\}}t|||�q|Sr)�items�setattr)r�k�v��kwrr�decorate�sz]AsyncContextManagerTestCase._create_contextmanager_attribs.<locals>.attribs.<locals>.decorater)rwrxrrvr�attribs�szKAsyncContextManagerTestCase._create_contextmanager_attribs.<locals>.attribs�bar)rXcSs
dVdS)�Whee!Nr)rgrrr�bazszGAsyncContextManagerTestCase._create_contextmanager_attribs.<locals>.baz)r)rryr|rrr�_create_contextmanager_attribs�s
z:AsyncContextManagerTestCase._create_contextmanager_attribscCs(|��}|�|jd�|�|jd�dS)Nr|rz)r}r4r"rX�rr|rrr�test_contextmanager_attribs	sz7AsyncContextManagerTestCase.test_contextmanager_attribscCs|��}|�|jd�dS�Nr{�r}r4�__doc__r~rrr�test_contextmanager_doc_attribsz:AsyncContextManagerTestCase.test_contextmanager_doc_attribc	�sV|��d�}|�|jd�|4IdH�Wd�IdHqR1IdHsH0YdSr�r�r~rrr�*test_instance_docstring_given_cm_docstringszFAsyncContextManagerTestCase.test_instance_docstring_given_cm_docstringc	�s`tdd��}|ddddd�4IdH�"}|�|d�Wd�IdHq\1IdHsR0YdS)	NcSs||||fVdSrr�rrr
�kwdsrrrrPsz9AsyncContextManagerTestCase.test_keywords.<locals>.woohoor-r0�!�,r�)r-r0r�r�)rr4)rrP�targetrrr�
test_keywordss
z)AsyncContextManagerTestCase.test_keywordsN)r"r#r$rrTrVrYr]r^r_rardrorqr}rrZrequires_docstringsr�r�r�rrrrrH^s:



	

	







rHc@sdeZdZGdd�de�ZeZdd�Zedd��Zedd��Z	ed	d
��Z
edd��Zed
d��ZdS)�TestAsyncExitStackc@s0eZdZedd��Zdd�Zdd�Zdd�Zd	S)
z%TestAsyncExitStack.SyncAsyncExitStackcsjt���t�|�}|��fdd�����|��}|s@|��S|j}z|�Wn||_|�Yn0dS)Ncs���Sr)�stop)�f�rrr�<lambda>,�zETestAsyncExitStack.SyncAsyncExitStack.run_coroutine.<locals>.<lambda>)rZget_event_loopZ
ensure_future�add_done_callbackZrun_forever�	exception�result�__context__)rr�r6r*rr�r�
run_coroutine's
z3TestAsyncExitStack.SyncAsyncExitStack.run_coroutinecCs|�|���Sr)r��acloser=rrrr<sz+TestAsyncExitStack.SyncAsyncExitStack.closecCs|�|���Sr)r�r(r=rrr�	__enter__?sz/TestAsyncExitStack.SyncAsyncExitStack.__enter__cGs|�|j|��Sr)r�r�r�exc_detailsrrr�__exit__Bsz.TestAsyncExitStack.SyncAsyncExitStack.__exit__N)r"r#r$�staticmethodr�rr�r�rrrr�SyncAsyncExitStack&s

r�cCs6t��|_t�|j�|�|jj�|�tjd�dSr)rr	rr
Z
addCleanuprrr=rrr�setUpGs
zTestAsyncExitStack.setUpc	�sRdifdifdifdtdd�fdtdd�fdtdd�fg}g��fdd�}t�4IdH��}t|�D]p\}}|r�|r�|j|g|�Ri|��}n:|r�|j|g|�R�}n"|r�|j|fi|��}n
|�|�}|�||�qb|jD]>}|�|dj|�|�|dj|j�|�	|dj
|j
�q�Wd�IdH�qH1IdH�s>0Y|��|�g�t�4IdH��}|�t
��|jdd�Wd�n1�s�0Y|�t
��|jjd	d�Wd�n1�s�0Y|�t
��|j|d
d�Wd�n1�s
0YWd�IdH�qB1IdH�s80Y|��g�dS)Nr)rJ)rJ�rJ)Zexamplec�s��||f�dS)zTest metadata propagationNrM)r
r��r�rr�_exitXsz5TestAsyncExitStack.test_async_callback.<locals>._exit)�argr��)�callbackr�)�dictr�reversed�push_async_callbackr'�_exit_callbacks�__wrapped__ZassertNotEqualr"�assertIsNoner�r4r2r;�
exit_stack)rZexpectedr��stackr
r�r�rrr�r�test_async_callbackMsB�

D,.\z&TestAsyncExitStack.test_async_callbackc	�sVt���fdd�}dd�}�fdd�}Gdd�dt�}���4IdH��}|�|���|jd	d
|�||�}|�|���|jd	d
j|�|�|���|jd	d
|�||�}|�|���|jd	d
j|�|�|���|jd	d
|�|�|���|jd	d
|�d
dWd�IdH�qR1IdH�sH0YdS)Nc�s��|��dSr)r'�r>r6�exc_tb�Z
exc_raisedrrr�_expect_exc{sz7TestAsyncExitStack.test_async_push.<locals>._expect_excc�sdS�NTr�r�rrr�
_suppress_exc}sz9TestAsyncExitStack.test_async_push.<locals>._suppress_excc�s"��|���|���|�dSr)r�r�r=rr�
_expect_oks

z6TestAsyncExitStack.test_async_push.<locals>._expect_okc@s$eZdZdd�Zdd�Zdd�ZdS)z2TestAsyncExitStack.test_async_push.<locals>.ExitCMcSs
||_dSr��	check_exc)rr�rrr�__init__�sz;TestAsyncExitStack.test_async_push.<locals>.ExitCM.__init__c�s|�d�dS)NzShould not be called!)rmr=rrrr(�sz=TestAsyncExitStack.test_async_push.<locals>.ExitCM.__aenter__c�s|j|�IdHdSrr�r�rrrr�sz<TestAsyncExitStack.test_async_push.<locals>.ExitCM.__aexit__N)r"r#r$r�r(rrrrr�ExitCM�sr����rJr)rU�objectr��push_async_exitr'r��__self__)rr�r�r�r�r��cmrr�r�test_async_pushxs*





z"TestAsyncExitStack.test_async_pushc	�s�G�fdd�dt�}g�|�}t�4IdH�d}|j�fdd��}|�|�|�|�IdH|�|jddj|���d�Wd�IdHq�1IdHs�0Y|�	�gd��dS)	Ncs$eZdZ�fdd�Z�fdd�ZdS)z;TestAsyncExitStack.test_async_enter_context.<locals>.TestCMc�s��d�dS)NrJrMr=r�rrr(�szFTestAsyncExitStack.test_async_enter_context.<locals>.TestCM.__aenter__c�s��d�dS)Nr�rMr�r�rrr�szETestAsyncExitStack.test_async_enter_context.<locals>.TestCM.__aexit__NrArr�rr�TestCM�sr�c�s��d�dS)N�rMrr�rrr��sz:TestAsyncExitStack.test_async_enter_context.<locals>._exitr�rJr�)rJr�r�r�)
r�rr�ZassertIsNotNone�enter_async_contextr'r�r�r3r4)rr�r�r�r�rr�r�test_async_enter_context�s
4z+TestAsyncExitStack.test_async_enter_contextc
�sdd�}d��fdd�}z�|��4IdH�X}|�|t�|�|t�|�|t�|�|�|�|t�ddWd�IdHq�1IdHs�0YWnRty�}z:|�|jt�|�|jjt�|�	|jjj�WYd}~nd}~00|�
d��d}|�|t�|�|jt�dS)Nc�s|�dSrrrprrr�	raise_exc�szHTestAsyncExitStack.test_async_exit_exception_chaining.<locals>.raise_excc�s|�dSr�rr��Z
saved_detailsrr�suppress_exc�szKTestAsyncExitStack.test_async_exit_exception_chaining.<locals>.suppress_excrJr�0Expected IndexError, but no exception was raised)r�r��
IndexError�KeyError�AttributeErrorr�r1ZassertIsInstancer�r�rmrU)rr�r�r�r6Z	inner_excrr�r�"test_async_exit_exception_chaining�s&
6&
z5TestAsyncExitStack.test_async_exit_exception_chainingc�s�Gdd�dt��t�fdd���t��fdd��}�|fD]�}�����zD|�4IdH�t��Wd�IdHq�1IdHs�0YWn0�y�}z��|j�WYd}~nd}~00��d�Wd�q:1s�0Yq:dS)Nc@seZdZdS)zWTestAsyncExitStack.test_async_exit_exception_explicit_none_context.<locals>.MyExceptionNr9rrrr�MyException�sr�cs@z
dVWn0ty:��}z|�Wd|_nd|_0Yn0dSr)�
BaseExceptionr�rp)r�rr�my_cm�s
zQTestAsyncExitStack.test_async_exit_exception_explicit_none_context.<locals>.my_cmc	sX���4IdH�.}|����IdH|VWd�IdHqT1IdHsJ0YdSr)r�r�)r�)r�rrr�my_cm_with_exit_stack�szaTestAsyncExitStack.test_async_exit_exception_explicit_none_context.<locals>.my_cm_with_exit_stackr�)rlrrkr�r�r�rm)rr�r�r6r)r�r�rr�/test_async_exit_exception_explicit_none_context�s

4"zBTestAsyncExitStack.test_async_exit_exception_explicit_none_contextN)
r"r#r$rr�r�r�rr�r�r�r�r�rrrrr�%s
*
#

r��__main__)r�
contextlibrrrr�testrZunittestZtest.test_contextlibrrZTestCaserrHr�r"�mainrrrr�<module>sEHR

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists