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.cpython-39.opt-1.pyc

a

��g���@sVdZddlZddlZddlZddlZddlZddlTddlmZddl	Z	Gdd�dej
�ZGdd�dej
�ZGd	d
�d
ej
�Z
Gdd�dej
�ZGd
d�dej
�ZGdd�dej
�ZGdd�de�ZGdd�dej
�ZGdd�d�ZGdd�deej
�ZGdd�d�ZGdd�deej
�ZGdd�deej
�ZGdd �d ej
�Zed!k�rRe��dS)"z9Unit tests for contextlib.py, and other context managers.�N)�*)�supportc@s$eZdZdd�Zdd�Zdd�ZdS)�TestAbstractContextManagercCs*Gdd�dt�}|�}|�|��|�dS)NcseZdZ�fdd�Z�ZS)z;TestAbstractContextManager.test_enter.<locals>.DefaultEntercst�j|�dS�N��super�__exit__��self�args��	__class__��0/usr/local/lib/python3.9/test/test_contextlib.pyrszDTestAbstractContextManager.test_enter.<locals>.DefaultEnter.__exit__��__name__�
__module__�__qualname__r�
__classcell__rrrr�DefaultEntersr)�AbstractContextManager�assertIs�	__enter__)r
r�managerrrr�
test_entersz%TestAbstractContextManager.test_entercCsDGdd�dt�}|�t��|�Wd�n1s60YdS)Nc@seZdZdS)zETestAbstractContextManager.test_exit_is_abstract.<locals>.MissingExitN�rrrrrrr�MissingExitsr)r�assertRaises�	TypeError)r
rrrr�test_exit_is_abstractsz0TestAbstractContextManager.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)zRTestAbstractContextManager.test_structural_subclassing.<locals>.ManagerFromScratchcSs|Srr�r
rrrr sz\TestAbstractContextManager.test_structural_subclassing.<locals>.ManagerFromScratch.__enter__cSsdSrr)r
�exc_type�	exc_value�	tracebackrrrr"sz[TestAbstractContextManager.test_structural_subclassing.<locals>.ManagerFromScratch.__exit__N�rrrrrrrrr�ManagerFromScratchsr%cseZdZ�fdd�Z�ZS)zLTestAbstractContextManager.test_structural_subclassing.<locals>.DefaultEntercst�j|�dSrrr	rrrr(szUTestAbstractContextManager.test_structural_subclassing.<locals>.DefaultEnter.__exit__rrrrrr'src@seZdZdZdS)zGTestAbstractContextManager.test_structural_subclassing.<locals>.NoEnterN)rrrrrrrr�NoEnter-sr&c@seZdZdZdS)zFTestAbstractContextManager.test_structural_subclassing.<locals>.NoExitN)rrrrrrrr�NoExit2sr')�
assertTrue�
issubclassr�assertFalse)r
r%rr&r'rrr�test_structural_subclassingsz6TestAbstractContextManager.test_structural_subclassingN)rrrrrr+rrrrr
src@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Ze
jdd��Ze
jdd��Zdd�Zdd�Zdd�Zdd �Zd!S)"�ContextManagerTestCasecsrg�t�fdd��}|��4}|��dg�|�|d���|�Wd�n1sT0Y|��gd��dS)Nc3s��d�dV��d�dS�N��*����appendr��staterr�woohoo<s
z@ContextManagerTestCase.test_contextmanager_plain.<locals>.woohoor.r/�r.r/r0)�contextmanager�assertEqualr2�r
r5�xrr3r�test_contextmanager_plain:s(z0ContextManagerTestCase.test_contextmanager_plainc	s�g�t�fdd��}|�t��`|��:}|��dg�|�|d���|�t��Wd�n1sf0YWd�n1s�0Y|��gd��dS)Nc	3s0��d�zdVW��d�n��d�0dSr-r1rr3rrr5Is
zBContextManagerTestCase.test_contextmanager_finally.<locals>.woohoor.r/r6)r7r�ZeroDivisionErrorr8r2r9rr3r�test_contextmanager_finallyGs
Bz2ContextManagerTestCase.test_contextmanager_finallycCs6tdd��}|�}|��|�|�ttd�d��dS)Ncss
dVdSrrrrrr�wheeYszCContextManagerTestCase.test_contextmanager_no_reraise.<locals>.whee�foo)r7rr*rr)r
r>�ctxrrr�test_contextmanager_no_reraiseXs

z5ContextManagerTestCase.test_contextmanager_no_reraisecCs6tdd��}|�}|��|�t|jttd�d�dS)Ncss"z
dVWndVYn0dSrrrrrr�whoobs
zOContextManagerTestCase.test_contextmanager_trap_yield_after_throw.<locals>.whoor?)r7rr�RuntimeErrorrr)r
rBr@rrr�*test_contextmanager_trap_yield_after_throwas
�zAContextManagerTestCase.test_contextmanager_trap_yield_after_throwcs|g�t��fdd��}|��<}���dg���|d���|�td��Wd�n1s^0Y���gd��dS)Nc
3s^��d�z
dVWnDtyX}z,��|jd����gd��WYd}~n
d}~00dS)Nr.r/rr6)r2r<rr8)�e�r
r4rrr5ps

zAContextManagerTestCase.test_contextmanager_except.<locals>.woohoor.r/r0r6)r7r8r2r<r9rrFr�test_contextmanager_exceptns
&z1ContextManagerTestCase.test_contextmanager_exceptcCs�tdd��}Gdd�dt�}td�|d�fD]�}|jt|�d���z.|��|�Wd�n1sd0YWn0ty�}z|�||�WYd}~nd}~00|�|�d��Wd�q,1s�0Yq,dS)Ncss
dVdSrrrrrrr5�szJContextManagerTestCase.test_contextmanager_except_stopiter.<locals>.woohooc@seZdZdS)zYContextManagerTestCase.test_contextmanager_except_stopiter.<locals>.StopIterationSubclassNrrrrr�StopIterationSubclass�srH�spam)�typez was suppressed)r7�
StopIteration�subTestrJ�	Exceptionr�fail)r
r5rH�stop_exc�exrrr�#test_contextmanager_except_stopiters
&"z:ContextManagerTestCase.test_contextmanager_except_stopiterc
Cs�d}i}t|||�|d}td�}z.|��|�Wd�n1sF0YWn0ty�}z|�||�WYd}~nd}~00|�d�dS)Nztfrom __future__ import generator_stop
from contextlib import contextmanager
@contextmanager
def woohoo():
    yield
r5rIzStopIteration was suppressed)�execrKrMrrN)r
�code�localsr5rOrPrrr�!test_contextmanager_except_pep479�s&"z8ContextManagerTestCase.test_contextmanager_except_pep479c
Cstdd��}z.|��t�Wd�n1s.0YWnTty�}z<|�t|�t�|�|jdd�|�|j	t�WYd}~n
d}~00z2|��t
d��Wd�n1s�0YWnTt�y}z:|�t|�t
�|�|jdd�|�|j	�WYd}~n
d}~00dS)Nc
ss>z
dVWn.ty8}ztd�|�WYd}~n
d}~00dS)N�issue29692:Chained)rMrC��excrrr�test_issue29692�s
zoContextManagerTestCase.test_contextmanager_do_not_unchain_non_stopiteration_exceptions.<locals>.test_issue29692rrVzissue29692:Unchained)r7r<rMrrJrCr8r�assertIsInstance�	__cause__rK�assertIsNone)r
rYrPrrr�?test_contextmanager_do_not_unchain_non_stopiteration_exceptions�s 
&$*zVContextManagerTestCase.test_contextmanager_do_not_unchain_non_stopiteration_exceptionscCs"dd�}t|dd�dd���}|S)Ncs�fdd�}|S)Ncs"���D]\}}t|||�q|Sr)�items�setattr)�func�k�v��kwrr�decorate�szXContextManagerTestCase._create_contextmanager_attribs.<locals>.attribs.<locals>.decorater)rdrerrcr�attribs�szFContextManagerTestCase._create_contextmanager_attribs.<locals>.attribs�bar)r?cSsdS)�Whee!Nr)rIrrr�baz�szBContextManagerTestCase._create_contextmanager_attribs.<locals>.baz�r7)r
rfrirrr�_create_contextmanager_attribs�s
z5ContextManagerTestCase._create_contextmanager_attribscCs(|��}|�|jd�|�|jd�dS)Nrirg)rkr8rr?�r
rirrr�test_contextmanager_attribs�sz2ContextManagerTestCase.test_contextmanager_attribscCs|��}|�|jd�dS�Nrh�rkr8�__doc__rlrrr�test_contextmanager_doc_attrib�sz5ContextManagerTestCase.test_contextmanager_doc_attribcCs|��d�}|�|jd�dSrnrorlrrr�*test_instance_docstring_given_cm_docstring�szAContextManagerTestCase.test_instance_docstring_given_cm_docstringcCsLtdd��}|ddddd��}|�|d�Wd�n1s>0YdS)	Ncss||||fVdSrr�r
r`r�kwdsrrrr5�sz4ContextManagerTestCase.test_keywords.<locals>.woohoo���!�,rs)rurvrwrx�r7r8)r
r5�targetrrr�
test_keywords�s
z$ContextManagerTestCase.test_keywordscsRGdd�d�}t�fdd��}||�|�d��Wd�n1sD0YdS)Nc@seZdZdS)z0ContextManagerTestCase.test_nokeepref.<locals>.ANrrrrr�A�sr|c3s6t�|�}t�|�}��|����|��dVdSr)�weakref�refr\��a�br rrr5�s


z5ContextManagerTestCase.test_nokeepref.<locals>.woohoo�r�rj)r
r|r5rr r�test_nokeepref�s
z%ContextManagerTestCase.test_nokeeprefcCs�tdd��}|�t��|�Wd�n1s20Y|�t��|dd�Wd�n1sf0Y|�t��|dd�Wd�n1s�0YdS)Ncss
dVdSrrrrrrr5�sz8ContextManagerTestCase.test_param_errors.<locals>.woohoo��r�)r7rr�r
r5rrr�test_param_errors�s
$(z(ContextManagerTestCase.test_param_errorscs@d�t��fdd��}|���fdd��������d�dS)Nrc3s*�}�d7�dV�d8����|�dS�Nr.)r8)�before)�depthr
rrr5�s
z5ContextManagerTestCase.test_recursive.<locals>.woohoocs�dkr��dS)N�
rr)r��	recursiverrr�sz8ContextManagerTestCase.test_recursive.<locals>.recursiveryr�r)r�r�r
r�test_recursive�sz%ContextManagerTestCase.test_recursiveN)rrrr;r=rArDrGrQrUr]rkrmr�requires_docstringsrqrrr{r�r�r�rrrrr,8s$
	



r,c@s*eZdZejdd��Zdd�Zdd�ZdS)�ClosingTestCasecCs tj}td�}|�|j|�dSr)�closingrpr8�r
Zcm_docstring�objrrr�test_instance_docssz"ClosingTestCase.test_instance_docscsng�G�fdd�d�}|�}|��g�t|��}|�||�Wd�n1sR0Y|��dg�dS)NcseZdZ�fdd�ZdS)z'ClosingTestCase.test_closing.<locals>.Ccs��d�dSr�r1r r3rr�closesz-ClosingTestCase.test_closing.<locals>.C.closeN�rrrr�rr3rr�Csr�r.)r8r��r
r�r:�yrr3r�test_closings
*zClosingTestCase.test_closingc	s�g�G�fdd�d�}|�}|��g�|�t��Lt|��$}|�||�ddWd�n1sf0YWd�n1s�0Y|��dg�dS)NcseZdZ�fdd�ZdS)z-ClosingTestCase.test_closing_error.<locals>.Ccs��d�dSr�r1r r3rrr�'sz3ClosingTestCase.test_closing_error.<locals>.C.closeNr�rr3rrr�&sr�r.r)r8rr<r�r�rr3r�test_closing_error$s
Dz"ClosingTestCase.test_closing_errorN)rrrrr�r�r�r�rrrrr�s
r�c@seZdZdd�ZdS)�NullcontextTestCasecCsLGdd�d�}|�}t|��}|�||�Wd�n1s>0YdS)Nc@seZdZdS)z/NullcontextTestCase.test_nullcontext.<locals>.CNrrrrrr�4sr�)�nullcontextr)r
r��cZc_inrrr�test_nullcontext3s
z$NullcontextTestCase.test_nullcontextN)rrrr�rrrrr�2sr�c@seZdZdd�ZdS)�FileContextTestCasec	Cst��}z�d}t|d��&}|�|j�|�d�Wd�n1sD0Y|�|j�d}|�t��^t|d��4}|�|j�|�	|�
�d�ddWd�n1s�0YWd�n1s�0Y|�|j�Wt�|�nt�|�0dS)N�wzBooh
�rr.r)
�tempfile�mktemp�openr*�closed�writer(rr<r8�readr�unlink)r
Ztfn�frrr�testWithOpen=s(Dz FileContextTestCase.testWithOpenN)rrrr�rrrrr�;sr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�LockContextTestCasec	Cs�|�|��|�|�|��Wd�n1s20Y|�|��|�t��H|�$|�|��ddWd�n1s�0YWd�n1s�0Y|�|��dS�Nr.r)r*r(rr<)r
�lock�lockedrrr�boilerPlateQs*DzLockContextTestCase.boilerPlatecCst��}|�||j�dSr)�	threading�Lockr�r��r
r�rrr�testWithLock\sz LockContextTestCase.testWithLockcCst��}|�||j�dSr)r��RLockr��	_is_ownedr�rrr�
testWithRLock`sz!LockContextTestCase.testWithRLockcs$t����fdd�}|��|�dS)Ncs���Sr)r�r�r�rrr�fsz5LockContextTestCase.testWithCondition.<locals>.locked)r��	Conditionr��r
r�rr�r�testWithConditiondsz%LockContextTestCase.testWithConditioncs$t����fdd�}|��|�dS)Ncs��d�r���dSdSdS�NFT��acquire�releaserr�rrr�ls
z5LockContextTestCase.testWithSemaphore.<locals>.locked)r��	Semaphorer�r�rr�r�testWithSemaphorejsz%LockContextTestCase.testWithSemaphorecs$t����fdd�}|��|�dS)Ncs��d�r���dSdSdSr�r�rr�rrr�vs
z<LockContextTestCase.testWithBoundedSemaphore.<locals>.locked)r��BoundedSemaphorer�r�rr�r�testWithBoundedSemaphoretsz,LockContextTestCase.testWithBoundedSemaphoreN)	rrrr�r�r�r�r�r�rrrrr�Os
r�c@s,eZdZdZdZdZdZdd�Zdd�ZdS)�	mycontextz9Example decoration-compatible context manager for testingFNcCs
d|_|S�NT��startedr rrrr�szmycontext.__enter__cGs||_|jSr)rX�catch�r
rXrrrr�szmycontext.__exit__)	rrrrpr�rXr�rrrrrrr�sr�c@sbeZdZejdd��Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�ZdS)�TestContextDecoratorcCstj}t�}|�|j|�dSr)r�rpr8r�rrrr��sz'TestContextDecorator.test_instance_docscCsTt�}|�(}|�||�|�|j�Wd�n1s80Y|�|jd�dS)N�NNN)r�rr(r�r8rX)r
�context�resultrrr�test_contextdecorator�s
*z*TestContextDecorator.test_contextdecoratorc	Cs�t�}|�td��<|�td��Wd�n1s60YWd�n1sT0Y|�|j�|�|jdt�t�}d|_|�td��Wd�n1s�0Y|�|j�|�|jdt�dS)Nr?rT)r��assertRaisesRegex�	NameError�assertIsNotNonerXrr�)r
r�rrr�$test_contextdecorator_with_exception�sD&z9TestContextDecorator.test_contextdecorator_with_exceptioncs0t�����fdd��}|����jd�dS)Ncs���j����j�dSr�r\rXr(r�r�r�r
rr�test�sz1TestContextDecorator.test_decorator.<locals>.testr�)r�r8rX�r
r�rr�r�test_decorator�s
z#TestContextDecorator.test_decoratorcslt�����fdd��}��td��|�Wd�n1s@0Y���j����jdt�dS)Ncs$���j����j�td��dS)Nr?)r\rXr(r�r�rr�rrr��sz@TestContextDecorator.test_decorator_with_exception.<locals>.testr?r)r�r�r�r�rXrr�rr�r�test_decorator_with_exception�s$z2TestContextDecorator.test_decorator_with_exceptioncs�t��G�fdd�dt�}|�}|�dd�|�|jd�|�|jd�|�|jd�|�}|�ddd�|�|jd�|�|jd�|�|jd�|�}|jddd�|�|jd�|�|jd�dS)	NcseZdZ�ddd��ZdS)z9TestContextDecorator.test_decorating_method.<locals>.TestNcSs||_||_||_dSr)r�r�r�)r
r�r�r�rrr�method�sz@TestContextDecorator.test_decorating_method.<locals>.Test.method)N)rrrr�r�r�rr�Test�sr�r.�r�r�r�r)r��objectr�r8r�r�r�)r
r�r�rr�r�test_decorating_method�s 	z+TestContextDecorator.test_decorating_methodc	CsdGdd�dt�}|�t��6|��Wd�n1s80YWd�n1sV0YdS)Nc@seZdZdd�Zdd�ZdS)z7TestContextDecorator.test_typo_enter.<locals>.mycontextcSsdSrrr rrr�	__unter__�szATestContextDecorator.test_typo_enter.<locals>.mycontext.__unter__cWsdSrrr�rrrr�sz@TestContextDecorator.test_typo_enter.<locals>.mycontext.__exit__N)rrrr�rrrrrr��sr���ContextDecoratorr�AttributeError�r
r�rrr�test_typo_enter�sz$TestContextDecorator.test_typo_enterc	CsdGdd�dt�}|�t��6|��Wd�n1s80YWd�n1sV0YdS)Nc@seZdZdd�Zdd�ZdS)z6TestContextDecorator.test_typo_exit.<locals>.mycontextcSsdSrrr rrrr�sz@TestContextDecorator.test_typo_exit.<locals>.mycontext.__enter__cWsdSrrr�rrr�__uxit__�sz?TestContextDecorator.test_typo_exit.<locals>.mycontext.__uxit__N)rrrrr�rrrrr��sr�r�r�rrr�test_typo_exit�sz#TestContextDecorator.test_typo_exitcsRGdd�dt�}Gdd�d|t�}|�����fdd��}|����jd�dS)Nc@s$eZdZdZdZdd�Zdd�ZdS)zHTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontextFNcSs
d|_|Sr�r�r rrrrszRTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontext.__enter__cWs
||_dSrrWr�rrrr
szQTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontext.__exit__)rrrr�rXrrrrrr�somecontextsr�c@seZdZdS)zFTestContextDecorator.test_contextdecorator_as_mixin.<locals>.mycontextNrrrrrr�
sr�cs���j����j�dSrr�rr�rrr�szATestContextDecorator.test_contextdecorator_as_mixin.<locals>.testr�)r�r�r8rX)r
r�r�r�rr�r�test_contextdecorator_as_mixinsz3TestContextDecorator.test_contextdecorator_as_mixincsbt�fdd��}g�|d���fdd��}|d����gd��g�|d����gd	��dS)
Nc3s��|�dV��d�dS)Nr0r1)r�r3rrr5s
zETestContextDecorator.test_contextmanager_as_decorator.<locals>.woohoor.cs���dg���|�dSr�)r8r2)r:rFrrr�!szCTestContextDecorator.test_contextmanager_as_decorator.<locals>.test�	something)r.r�r0�something else)r.r�r0ry)r
r5r�rrFr� test_contextmanager_as_decoratorsz5TestContextDecorator.test_contextmanager_as_decoratorN)rrrrr�r�r�r�r�r�r�r�r�r�r�rrrrr��s
	r�c@s�eZdZdZejdd��Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�ZdS)*�TestBaseExitStackNcCs"|jj}|��}|�|j|�dSr)�
exit_stackrpr8r�rrrr�1sz$TestBaseExitStack.test_instance_docscCs,|���Wd�n1s0YdSr)r�r rrr�test_no_resources8s
z#TestBaseExitStack.test_no_resourcescs8difdifdifdtdd�fdtdd�fdtdd�fdtddd�fg}g��fd	d
�}|����}t|�D]p\}}|r�|r�|j|g|�Ri|��}n:|r�|j|g|�R�}n"|r�|j|fi|��}n
|�|�}|�||�qj|jD]>}|�|dj|�|�|dj|j�|�	|dj
|j
�q�Wd�n1�s80Y|��|�g�|����}|�t
��|jdd�Wd�n1�s�0Y|�t
��|jjdd�Wd�n1�s�0Y|�t
��|j|dd
�Wd�n1�s�0YWd�n1�s0Y|��g�dS)Nr)r.)r.r�r.)Zexampler��)r
�callbackcs��||f�dS)zTest metadata propagationNr1)rrt�r�rr�_exitGsz.TestBaseExitStack.test_callback.<locals>._exit)�argr�)r�r�)�dictr��reversedr�r�_exit_callbacks�__wrapped__ZassertNotEqualrr\rpr8rr)r
Zexpectedr��stackrrtr��wrapperrr�r�
test_callback<sD�	


6
,.NzTestBaseExitStack.test_callbackcs@t���fdd�}dd�}�fdd�}Gdd�dt�}�����}|�|���|jd	d
|�||�}|�|���|jd	d
j|�|�|���|jd	d
|�||�}|�|���|jd	d
j|�|�|���|jd	d
|�|�|���|jd	d
|�d
dWd�n1�s20YdS)Ncs��|��dSr)r�r!rX�exc_tb�Z
exc_raisedr
rr�_expect_excgsz0TestBaseExitStack.test_push.<locals>._expect_exccWsdSr�r��exc_detailsrrr�
_suppress_excisz2TestBaseExitStack.test_push.<locals>._suppress_exccs"��|���|���|�dSr)r\r�r rr�
_expect_okks

z/TestBaseExitStack.test_push.<locals>._expect_okc@s$eZdZdd�Zdd�Zdd�ZdS)z+TestBaseExitStack.test_push.<locals>.ExitCMcSs
||_dSr��	check_exc)r
rrrr�__init__psz4TestBaseExitStack.test_push.<locals>.ExitCM.__init__cSs|�d�dS)NzShould not be called!)rNr rrrrrsz5TestBaseExitStack.test_push.<locals>.ExitCM.__enter__cWs|j|�dSrr�r
r�rrrrtsz4TestBaseExitStack.test_push.<locals>.ExitCM.__exit__N�rrrrrrrrrr�ExitCMosr���r.r)r<r�r��pushrr��__self__)r
r�rrrr��cmrr�r�	test_pushes*






zTestBaseExitStack.test_pushcs�G�fdd�dt�}g�|�}|���X}|j�fdd��}|�|�|�|�|�|jddj|���d�Wd�n1s�0Y|�	�gd��dS)	Ncs$eZdZ�fdd�Z�fdd�ZdS)z4TestBaseExitStack.test_enter_context.<locals>.TestCMcs��d�dSr�r1r r�rrr�sz>TestBaseExitStack.test_enter_context.<locals>.TestCM.__enter__cs��d�dS�Nr�r1rr�rrr�sz=TestBaseExitStack.test_enter_context.<locals>.TestCM.__exit__Nr$rr�rr�TestCM�srcs��d�dS)Nr�r1rr�rrr��sz3TestBaseExitStack.test_enter_context.<locals>._exitrr.r�)r.r�r�r�)
r�r�r�r��
enter_contextrr�r
r2r8)r
rrr�r�rr�r�test_enter_context�s


(z$TestBaseExitStack.test_enter_contextcsng�|���>}|j�fdd��}|�|�|����d�Wd�n1sP0Y|��ddg�dS)Ncs��d�dSr�r1rr�rrr��sz+TestBaseExitStack.test_close.<locals>._exitr�r.)r�r�r�r�r2r8)r
r�r�rr�r�
test_close�s

(zTestBaseExitStack.test_closecs�g�|���>}|j�fdd��}|�|�|��}��d�Wd�n1sP0Y��d�|��|��gd��dS)Ncs��d�dSr
r1rr�rrr��sz-TestBaseExitStack.test_pop_all.<locals>._exitr.r�)r.r�r�)r�r�r��pop_allr2r�r8)r
r�r��	new_stackrr�r�test_pop_all�s

(
zTestBaseExitStack.test_pop_allc	Csl|�t��N|���&}|�dd��ddWd�n1s@0YWd�n1s^0YdS)NcWsdS)NFrrWrrr�<lambda>��z3TestBaseExitStack.test_exit_raise.<locals>.<lambda>r.r)rr<r�r	�r
r�rrr�test_exit_raise�s
z!TestBaseExitStack.test_exit_raisecCsB|���&}|�dd��ddWd�n1s40YdS)NcWsdSr�rrWrrrr�rz6TestBaseExitStack.test_exit_suppress.<locals>.<lambda>r.r�r�r	rrrr�test_exit_suppress�s
z$TestBaseExitStack.test_exit_suppresscCs^Gdd�d�}Gdd�d�}Gdd�d�}z�|t���|tt��f|��@|t��ddWd�n1sp0YWd�n1s�0YWd�n1s�0YWd�n1s�0YWnTt�y*}z:|�|jt�|�|jjt�|�|jjj�WYd}~nd}~00|�d	�|jd}|�|t�|�|jt	�dS)
Nc@s$eZdZdd�Zdd�Zdd�ZdS)zJTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExccSs
||_dSrrWr�rrrr�szSTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__init__cSs|Srrr rrrr�szTTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__enter__cWs
|j�dSrrWrrrrr�szSTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__exit__Nrrrrr�RaiseExc�src@s$eZdZdd�Zdd�Zdd�ZdS)zUTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContextcSs||_||_dSr)�outer�inner)r
rrrrrr�sz^TestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContext.__init__cSs|Srrr rrrr�sz_TestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContext.__enter__cWs"z
|j�Wn|j�Yn0dSr)rrrrrrr�s
z^TestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContext.__exit__Nrrrrr�RaiseExcWithContext�src@seZdZdd�Zdd�ZdS)zMTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExccSs|Srrr rrrr�szWTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExc.__enter__cWs|t|�_dSr�)rJ�
saved_detailsrrrrr�s
zVTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExc.__exit__Nr$rrrr�SuppressExc�sr r.r�0Expected IndexError, but no exception was raised)
�
IndexError�KeyErrorr��
ValueErrorrZ�__context__r\rNrr<)r
rrr rX�	inner_excrrr�&test_exit_exception_chaining_reference�s"

�&

z8TestBaseExitStack.test_exit_exception_chaining_referencec
s
dd�}d��fdd�}zn|���R}|�|t�|�|t�|�|t�|�|�|�|t�ddWd�n1sz0YWnRty�}z:|�|jt�|�|jjt�|�	|jjj�WYd}~nd}~00|�
d��d}|�|t�|�|jt�dS)NcSs|�dSrrrWrrr�	raise_exc�szATestBaseExitStack.test_exit_exception_chaining.<locals>.raise_exccs|�dSr�rr��rrr�suppress_exc�szDTestBaseExitStack.test_exit_exception_chaining.<locals>.suppress_excr.rr!)r�r�r"r#r�r	r$rZr%r\rNr<)r
r(r*r�rXr&rr)r�test_exit_exception_chaining�s&

*&
z.TestBaseExitStack.test_exit_exception_chainingcs�Gdd�dt��t�fdd���t��fdd��}�|fD]�}����|z0|��t��Wd�n1sl0YWn0�y�}z��|j�WYd}~nd}~00��d�Wd�q:1s�0Yq:dS)Nc@seZdZdS)zPTestBaseExitStack.test_exit_exception_explicit_none_context.<locals>.MyExceptionNrrrrr�MyExceptionsr,c3s@z
dVWn0ty:��}z|�Wd|_nd|_0Yn0dSr)�
BaseExceptionr%rW)r,rr�my_cms
zJTestBaseExitStack.test_exit_exception_explicit_none_context.<locals>.my_cmc3s>����"}|����|VWd�n1s00YdSr)r�r)r�)r.r
rr�my_cm_with_exit_stacks
zZTestBaseExitStack.test_exit_exception_explicit_none_context.<locals>.my_cm_with_exit_stackr!)rMr7rLr"r\r%rN)r
r/rrXr)r,r.r
r�)test_exit_exception_explicit_none_contexts

("z;TestBaseExitStack.test_exit_exception_explicit_none_contextc
Cs"dd�}dd�}zF|���*}|�dd��|�|t�Wd�n1sJ0YWn0ty�}z|�|t�WYd}~nd}~00|�d�zN|���2}|�|t�|�|�|�|t�Wd�n1s�0YWn2t�y}z|�|t�WYd}~nd}~00|�d�dS)	NcSs|�dSrrrWrrrr(0szHTestBaseExitStack.test_exit_exception_non_suppressing.<locals>.raise_exccWsdSr�rr�rrrr*3szKTestBaseExitStack.test_exit_exception_non_suppressing.<locals>.suppress_exccSsdSrrrrrrr8rzGTestBaseExitStack.test_exit_exception_non_suppressing.<locals>.<lambda>r!z.Expected KeyError, but no exception was raised)r�r�r"rMrZrNr#r	)r
r(r*r�rXrrr�#test_exit_exception_non_suppressing.s"
."


."z5TestBaseExitStack.test_exit_exception_non_suppressingc
Cs�tdd��}td�}td�}td�}td�}zZ|���>}|�||��|�||��|�||��|�Wd�n1sz0YWnrty�}zZ|�||�|�|j|�|�|jj|�|�|jjj|�|�|jjjj�WYd}~n
d}~00dS)NcsszdVW|�n|�0dSrrrWrrr�gets_the_context_rightKszZTestBaseExitStack.test_exit_exception_with_correct_context.<locals>.gets_the_context_rightr.r�r�r�)r7rMr�rrr%r\)r
r2�exc1�exc2�exc3�exc4r�rXrrr�(test_exit_exception_with_correct_contextIs(

&
�z:TestBaseExitStack.test_exit_exception_with_correct_contextc	
Csdd�}td�}td�}td�}td�}td�}zL|���0}|�|||�|�|||�|�Wd�n1sp0YWn�t�y}zp|�||�|�|j|�|�|jj|�|�|jjj|�|�|jjjj|�|�|jjjjj�WYd}~n
d}~00dS)NcSsz|�W|�n|�0dSrr)r&Z	outer_excrrr�raise_nestedkszQTestBaseExitStack.test_exit_exception_with_existing_context.<locals>.raise_nestedr.r�r�r�r�)rMr�r�rr%r\)	r
r8r3r4r5r6Zexc5r�rXrrr�)test_exit_exception_with_existing_contexths,
&��z;TestBaseExitStack.test_exit_exception_with_existing_contextc
Cszdd�}z>|���"}|�|�ddWd�n1s:0YWn.tyt}z|�d�WYd}~n
d}~00dS)NcWsdSr�rr�rrrr*�szDTestBaseExitStack.test_body_exception_suppress.<locals>.suppress_excr.rz%Expected no exception, got IndexError)r�r	r"rN)r
r*r�rXrrr�test_body_exception_suppress�s

*z.TestBaseExitStack.test_body_exception_suppresscCsV|���:}|�dd��|�dd��|�dd��Wd�n1sH0YdS)NcWsdSr�rrWrrrr�rzITestBaseExitStack.test_exit_exception_chaining_suppress.<locals>.<lambda>cWsddSr�rrWrrrr�rcWsidSr�rrWrrrr�rrrrrr�%test_exit_exception_chaining_suppress�s
z7TestBaseExitStack.test_exit_exception_chaining_suppresscCsD|���(}td�D]}|�t�qWd�n1s60YdS)Ni')r��ranger��int)r
r��irrr�test_excessive_nesting�s
z(TestBaseExitStack.test_excessive_nestingcCsZGdd�dt�}|�}t�|_|��}|�t|j|�|�|�|�|jdd|�dS)Nc@seZdZdS)z7TestBaseExitStack.test_instance_bypass.<locals>.ExampleNrrrrr�Example�rr@rr.)	r�rr�rr�rr	rr�)r
r@rr�rrr�test_instance_bypass�s
z&TestBaseExitStack.test_instance_bypassc	s�Gdd�dt��Gdd�dt�}t�fdd��}tdd��}|����X}|���0}|�|��|�|��|d	��Wd�n1s�0YWd�n1s�0Y|j}|�|��|�|j|�|�	|jj�|�	|jj
�|�|j
|j�dS)
Nc@seZdZdS)zITestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.UniqueExceptionNrrrrr�UniqueException�rrBc@seZdZdS)zLTestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.UniqueRuntimeErrorNrrrrr�UniqueRuntimeError�rrCc
3s>z
dVWn.ty8}z�d�|�WYd}~n
d}~00dS)Nr.z
new exception�rMrW�rBrr�second�s
z@TestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.secondc
ss8z
dVWn(ty2}z|�WYd}~n
d}~00dSr�rDrWrrr�first�s
z?TestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.firstzplease no infinite loop.)rMrCr7rr�r�	exceptionrZr%r\r[r)r
rCrFrGZerr_ctxZes_ctxrXrrEr�test_dont_reraise_RuntimeError�s"

Dz0TestBaseExitStack.test_dont_reraise_RuntimeError)rrrr�rr�r�r�r�rrrrrrr'r+r0r1r7r9r:r;r?rArIrrrrr�.s,
)"
0"
	r�c@seZdZeZdS)�
TestExitStackN)rrr�	ExitStackr�rrrrrJ�srJc@sJeZdZdZdZejdd��Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�ZdS)�TestRedirectStreamNcCs$|jj}|�d�}|�|j|�dSr)�redirect_streamrpr8r�rrrr��s
z%TestRedirectStream.test_instance_docscCs.tt|j�}|�d�|�tt|j�|�dSr)�getattr�sys�orig_streamrMr)r
�orig_stdoutrrr�test_no_redirect_in_init�s
z+TestRedirectStream.test_no_redirect_in_initcCs�t��}d}tt|j�}|�|��$t|tt|j�d�Wd�n1sL0Y|�tt|j�|�|���	�}|�
||�dS)Nz<Consider an API like help(), which prints directly to stdout��file)�io�StringIOrNrOrPrM�printr�getvalue�stripr8)r
r��msgrQ�srrr�test_redirect_to_string_io�s2z-TestRedirectStream.test_redirect_to_string_iocCsBt��}|�|��}|�||�Wd�n1s40YdSr)rUrVrMr)r
r��enter_resultrrr�test_enter_result_is_target�sz.TestRedirectStream.test_enter_result_is_targetcCs�t��}|�|�}tt|j�}|�&tddtt|j�d�Wd�n1sN0Y|�$tdtt|j�d�Wd�n1s�0Y|�tt|j�|�|��}|�	|d�dS�N�Hello� )�endrTzWorld!rSz
Hello World!
�
rUrVrMrNrOrPrWrrXr8�r
r�Z
write_to_frQr[rrr�test_cm_is_reusable�s
42z&TestRedirectStream.test_cm_is_reusablec	Cs�t��}|�|�}tt|j�}|�^tddtt|j�d�|�$tdtt|j�d�Wd�n1sh0YWd�n1s�0Y|�tt|j�|�|��}|�	|d�dSr_rcrdrrr�test_cm_is_reentrant�s
Pz'TestRedirectStream.test_cm_is_reentrant)
rrrrMrPrr�r�rRr\r^rerfrrrrrL�s

rLc@seZdZeZdZdS)�TestRedirectStdout�stdoutN)rrr�redirect_stdoutrMrPrrrrrgsrgc@seZdZeZdZdS)�TestRedirectStderr�stderrN)rrr�redirect_stderrrMrPrrrrrj	srjc@sZeZdZejdd��Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dS)�TestSuppresscCstj}t�}|�|j|�dSr)�suppressrpr8r�rrrr�szTestSuppress.test_instance_docscCs6tt��}|�|�Wd�n1s(0YdSr)rnr$r\)r
r]rrr�test_no_result_from_enters
z&TestSuppress.test_no_result_from_entercCs>tt��"|�tdd�d�Wd�n1s00YdS)Nr�r�� )rnr$r8�powr rrr�test_no_exceptions
zTestSuppress.test_no_exceptioncCs4tt��td�Wd�n1s&0YdS)Nr�)rnr�lenr rrr�test_exact_exception s
z!TestSuppress.test_exact_exceptioncCs4tt��ddWd�n1s&0YdS)Nr`�2)rn�LookupErrorr rrr�test_exception_hierarchy$s
z%TestSuppress.test_exception_hierarchyc	Cs^|�t��@tt��ddWd�n1s20YWd�n1sP0YdSr�)rr<rnrr rrr�test_other_exception(s
z!TestSuppress.test_other_exceptionc	Cs\|�t��>t��ddWd�n1s00YWd�n1sN0YdSr�)rr<rnr rrr�test_no_args-szTestSuppress.test_no_argscCshttt��ddWd�n1s(0Yttt��td�Wd�n1sZ0YdS)Nr.rr�)rnr<rrsr rrr�test_multiple_exception_args2s&z)TestSuppress.test_multiple_exception_argsc	Cs�tt�}|�Wd�n1s"0Y|�td�Wd�n1sN0Y|�H|�td�Wd�n1s�0Yd}ddWd�n1s�0Y|�|�dS)Nr�Tr.r)rnrMrsr()r
Zignore_exceptionsZouter_continuedrrrrf8s&&&z!TestSuppress.test_cm_is_reentrantN)rrrrr�r�rorrrtrwrxryrzrfrrrrrms
rm�__main__)rprUrOr�r�Zunittest�
contextlibr�rr}ZTestCaserr,r�r�r�r�r�r�r�r�rJrLrgrjrmr�mainrrrr�<module>s:+Y"	0!96


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