HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/test/__pycache__/test_contextlib.cpython-310.pyc
o

�i���@sldZddlZddlZddlZddlZddlZddlZddlTddlm	Z	ddl
mZddlZGdd�dej
�ZGdd	�d	ej
�ZGd
d�dej
�ZGdd
�d
ej
�ZGdd�dej
�ZGdd�dej
�ZGdd�de�ZGdd�dej
�ZGdd�d�ZGdd�deej
�ZGdd�d�ZGdd�deej
�ZGdd�deej
�ZGd d!�d!ej
�Zed"kr�e��dSdS)#z9Unit tests for contextlib.py, and other context managers.�N)�*)�support)�	os_helperc@�$eZdZdd�Zdd�Zdd�ZdS)�TestAbstractContextManagercCs*Gdd�dt�}|�}|�|��|�dS)Nc�eZdZ�fdd�Z�ZS)z;TestAbstractContextManager.test_enter.<locals>.DefaultEnterc�t�j|�dS�N��super�__exit__��self�args��	__class__��1/usr/local/lib/python3.10/test/test_contextlib.pyr�zDTestAbstractContextManager.test_enter.<locals>.DefaultEnter.__exit__��__name__�
__module__�__qualname__r�
__classcell__rrrr�DefaultEnter�r)�AbstractContextManager�assertIs�	__enter__)rr�managerrrr�
test_entersz%TestAbstractContextManager.test_entercCsFGdd�dt�}|�t��|�Wd�dS1swYdS)Nc@�eZdZdS)zETestAbstractContextManager.test_exit_is_abstract.<locals>.MissingExitN�rrrrrrr�MissingExit�r#)r�assertRaises�	TypeError)rr#rrr�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@�eZdZdd�Zdd�ZdS)zRTestAbstractContextManager.test_structural_subclassing.<locals>.ManagerFromScratchcS�|Sr	r�rrrrr"�z\TestAbstractContextManager.test_structural_subclassing.<locals>.ManagerFromScratch.__enter__cS�dSr	r)r�exc_type�	exc_value�	tracebackrrrr$r+z[TestAbstractContextManager.test_structural_subclassing.<locals>.ManagerFromScratch.__exit__N�rrrrrrrrr�ManagerFromScratch!�r1cr)zLTestAbstractContextManager.test_structural_subclassing.<locals>.DefaultEntercrr	r
r
rrrr*rzUTestAbstractContextManager.test_structural_subclassing.<locals>.DefaultEnter.__exit__rrrrrr)rrc@�eZdZdZdS)zGTestAbstractContextManager.test_structural_subclassing.<locals>.NoEnterN)rrrrrrrr�NoEnter/�r4c@r3)zFTestAbstractContextManager.test_structural_subclassing.<locals>.NoExitN)rrrrrrrr�NoExit4r5r6)�
assertTrue�
issubclassr�assertFalse)rr1rr4r6rrr�test_structural_subclassing sz6TestAbstractContextManager.test_structural_subclassingN)rrrr r'r:rrrrrsrc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
ejdd��Zejdd��Zdd�Zdd�Zdd �Zd!d"�Zd#S)$�ContextManagerTestCasecsrg�t�fdd��}|��}|��dg�|�|d���|�Wd�n1s*wY|��gd��dS)Nc3s ���d�dV��d�dS�N��*����appendr��staterr�woohoo>��
z@ContextManagerTestCase.test_contextmanager_plain.<locals>.woohoor=r>�r=r>r?)�contextmanager�assertEqualrA�rrD�xrrBr�test_contextmanager_plain<s�z0ContextManagerTestCase.test_contextmanager_plainc	s�g�t�fdd��}|�t��)|��}|��dg�|�|d���|�t��1s,wYWd�n1s;wY|��gd��dS)Nc	3s0���d�zdVW��d�dS��d�wr<r@rrBrrrDKs
�
zBContextManagerTestCase.test_contextmanager_finally.<locals>.woohoor=r>rF)rGr%�ZeroDivisionErrorrHrArIrrBr�test_contextmanager_finallyIs
��z2ContextManagerTestCase.test_contextmanager_finallycCs@tdd��}z|��ddWd�n1swYWnty7}zt�|j�}WYd}~nd}~ww|�t|�d�|�|djd�|�|djd�Gdd�dt	�}z|��|d	��1sfwYWn|y�}zt�|j�}WYd}~nd}~ww|�t|�d�|�|djd�|�|djd
�Gdd�dt
�}t
d
�|d
�fD]n}|jt|�d��[z|��|�1s�wYWn t|�y�}z|�
||�t�|j�}WYd}~n
d}~ww|�|�d��|�t|�d�|�|djd�|�|djd�Wd�n	1�swYq�dS)Ncs��dVdSr	rrrrr�f[��
z?ContextManagerTestCase.test_contextmanager_traceback.<locals>.fr=r�test_contextmanager_traceback�1/0c@r!)zRContextManagerTestCase.test_contextmanager_traceback.<locals>.RuntimeErrorSubclassNr"rrrr�RuntimeErrorSubclassjr$rSr>zraise RuntimeErrorSubclass(42)c@r!)zSContextManagerTestCase.test_contextmanager_traceback.<locals>.StopIterationSubclassNr"rrrr�StopIterationSubclasswr$rT�spam��type� was suppressedzraise stop_exc)rGrLr/�
extract_tb�
__traceback__rH�len�name�line�RuntimeError�
StopIteration�subTestrWr�fail)rrO�eZframesrSrT�stop_excrrrrQZs^

��������������z4ContextManagerTestCase.test_contextmanager_tracebackcCs6tdd��}|�}|��|�|�ttd�d��dS)NcsrNr	rrrrr�whee�rPzCContextManagerTestCase.test_contextmanager_no_reraise.<locals>.whee�foo)rGrr9rr&)rrd�ctxrrr�test_contextmanager_no_reraise�s

z5ContextManagerTestCase.test_contextmanager_no_reraisecCs6tdd��}|�}|��|�t|jttd�d�dS)Ncss"�zdVWdSdVYdSr	rrrrr�whoo�s
�zOContextManagerTestCase.test_contextmanager_trap_yield_after_throw.<locals>.whoore)rGrr%r^rr&)rrhrfrrr�*test_contextmanager_trap_yield_after_throw�s
�zAContextManagerTestCase.test_contextmanager_trap_yield_after_throwcsng�t��fdd��}|��}���dg���|d���|�td��1s(wY���gd��dS)Nc
3s`���d�zdVWdSty/}z��|jd����gd��WYd}~dSd}~ww)Nr=r>rrF)rArLrrH)rb�rrCrrrD�s�
��zAContextManagerTestCase.test_contextmanager_except.<locals>.woohoor=r>r?rF)rGrHrArLrIrrjr�test_contextmanager_except�s
�z1ContextManagerTestCase.test_contextmanager_exceptcCs�tdd��}Gdd�dt�}td�|d�fD]K}|jt|�d��9z|��|�1s+wYWntyI}z|�||�WYd}~n
d}~ww|�|�d��Wd�n1s\wYqdS)NcsrNr	rrrrrrD�rPzJContextManagerTestCase.test_contextmanager_except_stopiter.<locals>.woohooc@r!)zYContextManagerTestCase.test_contextmanager_except_stopiter.<locals>.StopIterationSubclassNr"rrrrrT�r$rTrUrVrX)rGr_r`rW�	Exceptionrra)rrDrTrc�exrrr�#test_contextmanager_except_stopiter�s$
�������z:ContextManagerTestCase.test_contextmanager_except_stopiterc
Cs�d}i}t|||�|d}td�}z|��|�1swYWnty;}z
|�||�WYd}~dSd}~ww|�d�dS)Nztfrom __future__ import generator_stop
from contextlib import contextmanager
@contextmanager
def woohoo():
    yield
rDrUzStopIteration was suppressed)�execr_rlrra)r�code�localsrDrcrmrrr�!test_contextmanager_except_pep479�s���z8ContextManagerTestCase.test_contextmanager_except_pep479c
Cs�tdd��}z|��t�1swYWn*ty@}z|�t|�t�|�|jdd�|�|j	t�WYd}~nd}~wwz|��t
d��1sMwYWdSty~}z|�t|�t
�|�|jdd�|�|j	�WYd}~dSd}~ww)Nc
ss2�zdVWdSty}ztd�|�d}~ww)N�issue29692:Chained)rlr^��excrrr�test_issue29692���
��zoContextManagerTestCase.test_contextmanager_do_not_unchain_non_stopiteration_exceptions.<locals>.test_issue29692rrszissue29692:Unchained)rGrLrlrrWr^rHr�assertIsInstance�	__cause__r_�assertIsNone)rrvrmrrr�?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)r�r�rr�r�attribs�szFContextManagerTestCase._create_contextmanager_attribs.<locals>.attribs�bar)recS�dS)�Whee!Nr)rUrrr�baz��zBContextManagerTestCase._create_contextmanager_attribs.<locals>.baz�rG)rr�r�rrr�_create_contextmanager_attribs�s
z5ContextManagerTestCase._create_contextmanager_attribscCs(|��}|�|jd�|�|jd�dS)Nr�r�)r�rHrre�rr�rrr�test_contextmanager_attribs�sz2ContextManagerTestCase.test_contextmanager_attribscCs|��}|�|jd�dS�Nr��r�rH�__doc__r�rrr�test_contextmanager_doc_attribsz5ContextManagerTestCase.test_contextmanager_doc_attribcCs|��d�}|�|jd�dSr�r�r�rrr�*test_instance_docstring_given_cm_docstringszAContextManagerTestCase.test_instance_docstring_given_cm_docstringcCsNtdd��}|ddddd��}|�|d�Wd�dS1s wYdS)	Ncss�||||fVdSr	r�rr~r�kwdsrrrrDs�z4ContextManagerTestCase.test_keywords.<locals>.woohoo���!�,r�)r�r�r�r��rGrH)rrD�targetrrr�
test_keywords
s

"�z$ContextManagerTestCase.test_keywordscsTGdd�d�}t�fdd��}||�|�d��	Wd�dS1s#wYdS)Nc@r!)z0ContextManagerTestCase.test_nokeepref.<locals>.ANr"rrrr�Ar$r�c3s@�t�|�}t�|�}t����|����|��dVdSr	)�weakref�refr�
gc_collectrz��a�br*rrrDs�


z5ContextManagerTestCase.test_nokeepref.<locals>.woohoo�r�r�)rr�rDrr*r�test_nokeeprefs	"�z%ContextManagerTestCase.test_nokeeprefcCs�tdd��}|�t��|�Wd�n1swY|�t��
|dd�Wd�n1s3wY|�t��|dd�Wd�dS1sNwYdS)NcsrNr	rr�rrrrD'rPz8ContextManagerTestCase.test_param_errors.<locals>.woohoo��r�)rGr%r&�rrDrrr�test_param_errors&s
��"�z(ContextManagerTestCase.test_param_errorscs@d�t��fdd��}|���fdd��������d�dS)Nrc3s,��}�d7�dV�d8����|�dS�Nr=)rH)�before)�depthrrrrD4s�z5ContextManagerTestCase.test_recursive.<locals>.woohoocs�dkr	��dSdS)N�
rr)r��	recursiverrr�=s
�z8ContextManagerTestCase.test_recursive.<locals>.recursiver�r�r)r�r�rr�test_recursive2sz%ContextManagerTestCase.test_recursiveN)rrrrKrMrQrgrirkrnrrr{r�r�r�requires_docstringsr�r�r�r�r�r�rrrrr;:s(
2	



r;c@s*eZdZejdd��Zdd�Zdd�ZdS)�ClosingTestCasecCs tj}td�}|�|j|�dSr	)�closingr�rH�rZcm_docstring�objrrr�test_instance_docsHsz"ClosingTestCase.test_instance_docscsng�G�fdd�d�}|�}|��g�t|��}|�||�Wd�n1s)wY|��dg�dS)Nc�eZdZ�fdd�ZdS)z'ClosingTestCase.test_closing.<locals>.Cc���d�dSr�r@r*rBrr�closeR�z-ClosingTestCase.test_closing.<locals>.C.closeN�rrrr�rrBrr�CQ�r�r=)rHr��rr�rJ�yrrBr�test_closingOs
�zClosingTestCase.test_closingc	s�g�G�fdd�d�}|�}|��g�|�t��&t|��}|�||�ddWd�n1s3wYWd�n1sBwY|��dg�dS)Ncr�)z-ClosingTestCase.test_closing_error.<locals>.Ccr�r�r@r*rBrrr�]r�z3ClosingTestCase.test_closing_error.<locals>.C.closeNr�rrBrrr�\r�r�r=r)rHr%rLr�r�rrBr�test_closing_errorZs

���z"ClosingTestCase.test_closing_errorN)rrrrr�r�r�r�rrrrr�Fs

r�c@�eZdZdd�ZdS)�NullcontextTestCasecCsNGdd�d�}|�}t|��}|�||�Wd�dS1s wYdS)Nc@r!)z/NullcontextTestCase.test_nullcontext.<locals>.CNr"rrrrr�jr$r�)�nullcontextr)rr��cZc_inrrr�test_nullcontextis

"�z$NullcontextTestCase.test_nullcontextN)rrrr�rrrrr�hsr�c@r�)�FileContextTestCasec	Cst��}zxd}t|ddd��}|�|j�|�d�Wd�n1s$wY|�|j�d}|�t��1t|ddd��}|�|j�|�	|�
�d�ddWd�n1s[wYWd�n1sjwY|�|j�Wt�|�dSt�|�w)N�wzutf-8)�encodingzBooh
�rr=r)
�tempfile�mktemp�openr9�closed�writer7r%rLrH�readr�unlink)rZtfnrOrrr�testWithOpenss&�
���z FileContextTestCase.testWithOpenN)rrrr�rrrrr�qsr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�LockContextTestCasec	Cs�|�|��|�|�|��Wd�n1swY|�|��|�t��$|�|�|��ddWd�n1sAwYWd�n1sPwY|�|��dS�Nr=r)r9r7r%rL)r�lock�lockedrrr�boilerPlate�s�
���zLockContextTestCase.boilerPlatecC�t��}|�||j�dSr	)�	threading�Lockr�r��rr�rrr�testWithLock��z LockContextTestCase.testWithLockcCr�r	)r��RLockr��	_is_ownedr�rrr�
testWithRLock�r�z!LockContextTestCase.testWithRLockc�$t����fdd�}|��|�dS)Ncs���Sr	)r�r�r�rrr��sz5LockContextTestCase.testWithCondition.<locals>.locked)r��	Conditionr��rr�rr�r�testWithCondition�sz%LockContextTestCase.testWithConditioncr�)Nc���d�r���dSdS�NFT��acquire�releaserr�rrr���
z5LockContextTestCase.testWithSemaphore.<locals>.locked)r��	Semaphorer�r�rr�r�testWithSemaphore��z%LockContextTestCase.testWithSemaphorecr�)Ncr�r�r�rr�rrr��r�z<LockContextTestCase.testWithBoundedSemaphore.<locals>.locked)r��BoundedSemaphorer�r�rr�r�testWithBoundedSemaphore�r�z,LockContextTestCase.testWithBoundedSemaphoreN)	rrrr�r�r�r�r�r�rrrrr��s
r�c@s,eZdZdZdZdZdZdd�Zdd�ZdS)�	mycontextz9Example decoration-compatible context manager for testingFNcC�
d|_|S�NT��startedr*rrrr��zmycontext.__enter__cGs||_|jSr	)ru�catch�rrurrrr�szmycontext.__exit__)	rrrr�r�rur�rrrrrrr��sr�c@sbeZdZejdd��Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�ZdS)�TestContextDecoratorcC�tj}t�}|�|j|�dSr	)r�r�rHr�rrrr���z'TestContextDecorator.test_instance_docscCsTt�}|�}|�||�|�|j�Wd�n1swY|�|jd�dS)N�NNN)r�rr7r�rHru)r�context�resultrrr�test_contextdecorator�s�z*TestContextDecorator.test_contextdecoratorc	Cs�t�}|�td��|�td��1swYWd�n1s#wY|�|j�|�|jdt�t�}d|_|�td��1sGwY|�|j�|�|jdt�dS)NrerT)r��assertRaisesRegex�	NameError�assertIsNotNonerurr�)rr�rrr�$test_contextdecorator_with_exception�s���z9TestContextDecorator.test_contextdecorator_with_exceptioncs0t�����fdd��}|����jd�dS)Nc����j����j�dSr	�rzrur7r�r�r�rrr�test��z1TestContextDecorator.test_decorator.<locals>.testr�)r�rHru�rrrrr�test_decorator�s
z#TestContextDecorator.test_decoratorcslt�����fdd��}��td��|�Wd�n1s wY���j����jdt�dS)Ncs ���j����j�td��)Nre)rzrur7r�r�rrrrr�sz@TestContextDecorator.test_decorator_with_exception.<locals>.testrer)r�r�r�rrurrrrr�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�)rr�r�r�rrr�methods
z@TestContextDecorator.test_decorating_method.<locals>.Test.methodr	)rrrr
r�r�rr�Testsrr=�r�r�r�r�)r��objectr
rHr�r�r�)rrrrrr�test_decorating_methods 	z+TestContextDecorator.test_decorating_methodc	C�vGdd�dt�}|�t��$|��Wd�n1swYWd�dSWd�dS1s4wYdS)Nc@r()z7TestContextDecorator.test_typo_enter.<locals>.mycontextcSr,r	rr*rrr�	__unter__!r+zATestContextDecorator.test_typo_enter.<locals>.mycontext.__unter__cWr,r	rr�rrrr#r+z@TestContextDecorator.test_typo_enter.<locals>.mycontext.__exit__N)rrrrrrrrrr� r2r���ContextDecoratorr%�AttributeError�rr�rrr�test_typo_enter���"�z$TestContextDecorator.test_typo_enterc	Cr)Nc@r()z6TestContextDecorator.test_typo_exit.<locals>.mycontextcSr,r	rr*rrrr-r+z@TestContextDecorator.test_typo_exit.<locals>.mycontext.__enter__cWr,r	rr�rrr�__uxit__/r+z?TestContextDecorator.test_typo_exit.<locals>.mycontext.__uxit__N)rrrrrrrrrr�,r2r�rrrrr�test_typo_exit+rz#TestContextDecorator.test_typo_exitcsRGdd�dt�}Gdd�d|t�}|�����fdd��}|����jd�dS)Nc@s$eZdZdZdZdd�Zdd�ZdS)zHTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontextFNcSr�r�r�r*rrrr<r�zRTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontext.__enter__cW�
||_dSr	rtr�rrrr@�
zQTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontext.__exit__)rrrr�rurrrrrr�somecontext8s
rc@r!)zFTestContextDecorator.test_contextdecorator_as_mixin.<locals>.mycontextNr"rrrrr�Cr$r�crr	rrrrrrGrzATestContextDecorator.test_contextdecorator_as_mixin.<locals>.testr�)rrrHru)rrr�rrrr�test_contextdecorator_as_mixin7sz3TestContextDecorator.test_contextdecorator_as_mixincsbt�fdd��}g�|d���fdd��}|d����gd��g�|d����gd	��dS)
Nc3s ���|�dV��d�dS)Nr?r@)r�rBrrrDPrEzETestContextDecorator.test_contextmanager_as_decorator.<locals>.woohoor=cs���dg���|�dSr�)rHrA)rJrjrrrWszCTestContextDecorator.test_contextmanager_as_decorator.<locals>.test�	something)r=rr?�something else)r=rr?r�)rrDrrrjr� test_contextmanager_as_decoratorOsz5TestContextDecorator.test_contextmanager_as_decoratorN)rrrrr�r�r�rrr	rrrrr 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)�Zd*d+�ZdS),�TestBaseExitStackNcCs"|jj}|��}|�|j|�dSr	)�
exit_stackr�rHr�rrrr�gsz$TestBaseExitStack.test_instance_docscCs.|���	Wd�dS1swYdSr	)r"r*rrr�test_no_resourcesns
"�z#TestBaseExitStack.test_no_resourcescs0difdifdifdtdd�fdtdd�fdtdd�fdtddd�fg}g��fd	d
�}|���h}t|�D]8\}}|rJ|rJ|j|g|�Ri|��}n|rV|j|g|�R�}n|rb|j|fi|��}n|�|�}|�||�q5|jD]}|�|dj|�|�|dj|j�|�	|dj
|j
�qqWd�n1s�wY|��|�g�|���[}|�t
��|jdd�Wd�n1s�wY|�t
��|jjdd�Wd�n1s�wY|�t
��|j|dd
�Wd�n1s�wYWd�n	1�swY|��g�dS)Nr)r=)r=r
r=)Zexampler��)r�callbackcs��||f�dS)zTest metadata propagationNr@)rr��r�rr�_exit}sz.TestBaseExitStack.test_callback.<locals>._exit)�argr
)r%r()�dictr"�reversedr%r�_exit_callbacks�__wrapped__ZassertNotEqualrrzr�rHr%r&)r�expectedr'�stackrr�rO�wrapperrr&r�
test_callbackrsR�	


��
�����zTestBaseExitStack.test_callbackcs@t���fdd�}dd�}�fdd�}Gdd�dt�}����w}|�|���|jd	d
|�||�}|�|���|jd	d
j|�|�|���|jd	d
|�||�}|�|���|jd	d
j|�|�|���|jd	d
|�|�|���|jd	d
|�d
dWd�dS1s�wYdS)Ncs��|��dSr	)r�r-ru�exc_tb�Z
exc_raisedrrr�_expect_exc�rz0TestBaseExitStack.test_push.<locals>._expect_exccWr�r�r��exc_detailsrrr�
_suppress_exc�r+z2TestBaseExitStack.test_push.<locals>._suppress_exccs"��|���|���|�dSr	)rzr1r*rr�
_expect_ok�s

z/TestBaseExitStack.test_push.<locals>._expect_okc@r)z+TestBaseExitStack.test_push.<locals>.ExitCMcSrr	��	check_exc)rr:rrr�__init__�rz4TestBaseExitStack.test_push.<locals>.ExitCM.__init__cSs|�d�dS)NzShould not be called!)rar*rrrr�r�z5TestBaseExitStack.test_push.<locals>.ExitCM.__enter__cWs|j|�dSr	r9�rr6rrrr�r�z4TestBaseExitStack.test_push.<locals>.ExitCM.__exit__N�rrrr;rrrrrr�ExitCM��r>���r=r)rLrr"�pushrr+�__self__)rr4r7r8r>r.�cmrr3r�	test_push�s,







"�zTestBaseExitStack.test_pushcs�G�fdd�dt�}g�|�}|���,}|j�fdd��}|�|�|�|�|�|jddj|���d�Wd�n1sBwY|�	�gd��dS)	Ncs$eZdZ�fdd�Z�fdd�ZdS)z4TestBaseExitStack.test_enter_context.<locals>.TestCMcr�r�r@r*r&rrr�r�z>TestBaseExitStack.test_enter_context.<locals>.TestCM.__enter__cr��Nr�r@r<r&rrr�r�z=TestBaseExitStack.test_enter_context.<locals>.TestCM.__exit__Nr0rr&rr�TestCM�srFcr�)Nr$r@rr&rrr'��z3TestBaseExitStack.test_enter_context.<locals>._exitr@r=r
)r=r
r�r$)
rr"r%r�
enter_contextrr+rBrArH)rrFrCr.r'rr&r�test_enter_context�s


�z$TestBaseExitStack.test_enter_contextcsng�|���}|j�fdd��}|�|�|����d�Wd�n1s(wY|��ddg�dS)Ncr�r�r@rr&rrr'�rGz+TestBaseExitStack.test_close.<locals>._exitr
r=)r"r%rr�rArH)rr.r'rr&r�
test_close�s

�zTestBaseExitStack.test_closecs�g�|���}|j�fdd��}|�|�|��}��d�Wd�n1s(wY��d�|��|��gd��dS)Ncr�rEr@rr&rrr'�rGz-TestBaseExitStack.test_pop_all.<locals>._exitr=r
)r=r
r�)r"r%r�pop_allrAr�rH)rr.r'�	new_stackrr&r�test_pop_all�s

�
zTestBaseExitStack.test_pop_allc	Cs~|�t��0|���}|�dd��ddWd�n1s wYWd�dSWd�dS1s8wYdS)NcWr�)NFrrtrrr�<lambda>�r�z3TestBaseExitStack.test_exit_raise.<locals>.<lambda>r=r)r%rLr"rA�rr.rrr�test_exit_raise�s

��"�z!TestBaseExitStack.test_exit_raisecCsD|���}|�dd��ddWd�dS1swYdS)NcWr�r�rrtrrrrN�r�z6TestBaseExitStack.test_exit_suppress.<locals>.<lambda>r=r�r"rArOrrr�test_exit_suppress�s

"�z$TestBaseExitStack.test_exit_suppressc
Cs�dd�}z |���}|�|t�ddWd�n1swYWnty8}z|}WYd}~nd}~ww|�|t�t�|j�}dg|jddg}|�dd	�|D�|�|�|j	t
�t�|j	j�}|�d
d	�|D�dg�dS)NcS�|�r	rrtrrr�	raise_exc�r+zBTestBaseExitStack.test_exit_exception_traceback.<locals>.raise_excr=r)�test_exit_exception_tracebackz with self.exit_stack() as stack:)�
_exit_wrapperzcallback(*args, **kwds))rTz	raise exccS�g|]}|j|jf�qSr�r\r]��.0rOrrr�
<listcomp>�zCTestBaseExitStack.test_exit_exception_traceback.<locals>.<listcomp>cSrWrrXrYrrrr[r\)rUrR)r"r%�
ValueErrorrxr/rYrZ�callback_error_internal_framesrH�__context__rL)rrTr.rbruZ	ve_framesr-Z
zde_framesrrrrU�s:

����������z/TestBaseExitStack.test_exit_exception_tracebackcCs\Gdd�d�}Gdd�d�}Gdd�d�}zV|t��H|tt��3|�� |t��ddWd�n1s8wYWd�n1sGwYWd�n1sVwYWd�n1sewYWn)ty�}z|�|jt�|�|jjt�|�|jjj�WYd}~n
d}~ww|�d	�|jd}|�|t�|�|jt	�dS)
Nc@r)zJTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExccSrr	rtr�rrrr;rzSTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__init__cSr)r	rr*rrrrr+zTTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__enter__cWs|j�r	rtr<rrrrszSTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__exit__Nr=rrrr�RaiseExcr?r`c@r)zUTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContextcSs||_||_dSr	)�outer�inner)rrarbrrrr;s
z^TestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContext.__init__cSr)r	rr*rrrr"r+z_TestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContext.__enter__cWsz|j�|j�r	)rbrar<rrrr$sz^TestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContext.__exit__Nr=rrrr�RaiseExcWithContextsrcc@r()zMTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExccSr)r	rr*rrrr+r+zWTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExc.__enter__cWs|t|�_dSr�)rW�
saved_detailsr<rrrr-s
zVTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExc.__exit__Nr0rrrr�SuppressExc*r2rer=r�0Expected IndexError, but no exception was raised)
�
IndexError�KeyErrorrr]rxr_rzrardrL)rr`rcreru�	inner_excrrr�&test_exit_exception_chaining_references6


����������

z8TestBaseExitStack.test_exit_exception_chaining_referencec
s
dd�}d��fdd�}z7|���)}|�|t�|�|t�|�|t�|�|�|�|t�ddWd�n1s=wYWn)tyl}z|�|jt�|�|jjt�|�	|jjj�WYd}~n
d}~ww|�
d��d}|�|t�|�|jt�dS)NcSrSr	rrtrrrrTEr+zATestBaseExitStack.test_exit_exception_chaining.<locals>.raise_exccs|�dSr�rr5�rdrr�suppress_excIszDTestBaseExitStack.test_exit_exception_chaining.<locals>.suppress_excr=rrf)r"r%rgrhrrAr]rxr_rzrarL)rrTrlr.rurirrkr�test_exit_exception_chainingCs.


����
z.TestBaseExitStack.test_exit_exception_chainingcs�Gdd�dt��t�fdd���t��fdd��}�|fD]E}����7z|��t��1s/wYWn�yM}z��|j�WYd}~n
d}~ww��d�Wd�n1s]wYqdS)Nc@r!)zPTestBaseExitStack.test_exit_exception_explicit_none_context.<locals>.MyExceptionNr"rrrr�MyExceptionfr$rnc3s2�zdVWdSty��}z|�d|_wwr	)�
BaseExceptionr_rt)rnrr�my_cmis��zJTestBaseExitStack.test_exit_exception_explicit_none_context.<locals>.my_cmc3sB�����}|����|VWd�dS1swYdSr	)r"rH)r.)rprrr�my_cm_with_exit_stackts
�
"�zZTestBaseExitStack.test_exit_exception_explicit_none_context.<locals>.my_cm_with_exit_stackrf)rlrGr`rgrzr_ra)rrqrCrur)rnrprr�)test_exit_exception_explicit_none_contextbs(

���
����z;TestBaseExitStack.test_exit_exception_explicit_none_contextc
Cs"dd�}dd�}z#|���}|�dd��|�|t�Wd�n1s%wYWntyC}z|�|t�WYd}~n
d}~ww|�d�z'|���}|�|t�|�|�|�|t�Wd�n1sjwYWnty�}z
|�|t�WYd}~dSd}~ww|�d�dS)	NcSrSr	rrtrrrrT�r+zHTestBaseExitStack.test_exit_exception_non_suppressing.<locals>.raise_exccWr�r�rr5rrrrl�r+zKTestBaseExitStack.test_exit_exception_non_suppressing.<locals>.suppress_exccSr,r	rrrrrrN�r�zGTestBaseExitStack.test_exit_exception_non_suppressing.<locals>.<lambda>rfz.Expected KeyError, but no exception was raised)r"r%rgrlrxrarhrA)rrTrlr.rurrr�#test_exit_exception_non_suppressing�s2
����


����z5TestBaseExitStack.test_exit_exception_non_suppressingc
Cs�tdd��}td�}td�}td�}td�}z'|���}|�||��|�||��|�||��|�1s6wYWdStyw}z.|�||�|�|j|�|�|jj|�|�|jjj|�|�|jjjj�WYd}~dSd}~ww)Ncss�zdVW|�|�r	rrtrrr�gets_the_context_right�s�zZTestBaseExitStack.test_exit_exception_with_correct_context.<locals>.gets_the_context_rightr=r
r�r$)rGrlr"rHrr_rz)rrt�exc1�exc2�exc3�exc4r.rurrr�(test_exit_exception_with_correct_context�s.

�
���z:TestBaseExitStack.test_exit_exception_with_correct_contextc	
Cs�dd�}td�}td�}td�}td�}td�}z |���}|�|||�|�|||�|�1s1wYWdSty}}z9|�||�|�|j|�|�|jj|�|�|jjj|�|�|jjjj|�|�|jjjjj�WYd}~dSd}~ww)NcSs
z|�|�r	r)riZ	outer_excrrr�raise_nested�szQTestBaseExitStack.test_exit_exception_with_existing_context.<locals>.raise_nestedr=r
r�r$r�)rlr"r%rr_rz)	rrzrurvrwrxZexc5r.rurrr�)test_exit_exception_with_existing_context�s2
�����z;TestBaseExitStack.test_exit_exception_with_existing_contextc
Cs~dd�}z"|���}|�|�ddWd�WdS1swYWdSty>}z|�d�WYd}~dSd}~ww)NcWr�r�rr5rrrrl�r+zDTestBaseExitStack.test_body_exception_suppress.<locals>.suppress_excr=rz%Expected no exception, got IndexError)r"rArgra)rrlr.rurrr�test_body_exception_suppress�s


&���z.TestBaseExitStack.test_body_exception_suppresscCsX|���}|�dd��|�dd��|�dd��Wd�dS1s%wYdS)NcWr�r�rrtrrrrN�r�zITestBaseExitStack.test_exit_exception_chaining_suppress.<locals>.<lambda>cWsddSr�rrtrrrrN��cWsidSr�rrtrrrrN�r}rQrOrrr�%test_exit_exception_chaining_suppress�s

"�z7TestBaseExitStack.test_exit_exception_chaining_suppresscCsF|���}td�D]}|�t�q	Wd�dS1swYdS)Ni')r"�ranger%�int)rr.�irrr�test_excessive_nesting�s

�"�z(TestBaseExitStack.test_excessive_nestingcCsZGdd�dt�}|�}t�|_|��}|�t|j|�|�|�|�|jdd|�dS)Nc@r!)z7TestBaseExitStack.test_instance_bypass.<locals>.ExampleNr"rrrr�Example��r�r@r=)	rrr"r%rrHrArr+)rr�rCr.rrr�test_instance_bypass�s
z&TestBaseExitStack.test_instance_bypassc	s�Gdd�dt��Gdd�dt�}t�fdd��}tdd��}|����%}|���}|�|��|�|��|d	��1s<wYWd�n1sKwY|j}|�|��|�|j|�|�	|jj�|�	|jj
�|�|j
|j�dS)
Nc@r!)zITestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.UniqueExceptionNr"rrrr�UniqueException�r�r�c@r!)zLTestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.UniqueRuntimeErrorNr"rrrr�UniqueRuntimeError�r�r�c
3s2�zdVWdSty}z�d�|�d}~ww)Nr=z
new exception�rlrt�r�rr�second�rwz@TestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.secondc
ss,�zdVWdSty}z|�d}~wwr�r�rtrrr�firsts���z?TestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.firstzplease no infinite loop.)rlr^rGr%r"rH�	exceptionrxr_rzryr)rr�r�r�Zerr_ctxZes_ctxrurr�r�test_dont_reraise_RuntimeError�s&

��z0TestBaseExitStack.test_dont_reraise_RuntimeError)rrrr"rr�r�r#r0rDrIrJrMrPrRrUrjrmrrrsryr{r|r~r�r�r�rrrrr!ds0
)"
 0"
	r!c@seZdZeZddgZdS)�
TestExitStack)rzraise exc_details[1])rzif cb(*exc_details):N)rrr�	ExitStackr"r^rrrrr�s
�r�c@sJeZdZdZdZejdd��Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�ZdS)�TestRedirectStreamNcCs$|jj}|�d�}|�|j|�dSr	)�redirect_streamr�rHr�rrrr�)s
z%TestRedirectStream.test_instance_docscCs.tt|j�}|�d�|�tt|j�|�dSr	)�getattr�sys�orig_streamr�r)r�orig_stdoutrrr�test_no_redirect_in_init0s
z+TestRedirectStream.test_no_redirect_in_initcCs�t��}d}tt|j�}|�|��t|tt|j�d�Wd�n1s&wY|�tt|j�|�|���	�}|�
||�dS)Nz<Consider an API like help(), which prints directly to stdout��file)�io�StringIOr�r�r�r��printr�getvalue�striprH)rrO�msgr��srrr�test_redirect_to_string_io5s�z-TestRedirectStream.test_redirect_to_string_iocCsDt��}|�|��}|�||�Wd�dS1swYdSr	)r�r�r�r)rrO�enter_resultrrr�test_enter_result_is_target?s"�z.TestRedirectStream.test_enter_result_is_targetcCs�t��}|�|�}tt|j�}|�tddtt|j�d�Wd�n1s'wY|�tdtt|j�d�Wd�n1sCwY|�tt|j�|�|��}|�	|d�dS�N�Hello� )�endr�zWorld!r�z
Hello World!
�
r�r�r�r�r�r�r�rr�rH�rrOZ
write_to_fr�r�rrr�test_cm_is_reusableDs
��z&TestRedirectStream.test_cm_is_reusablec	Cs�t��}|�|�}tt|j�}|�/tddtt|j�d�|�tdtt|j�d�Wd�n1s4wYWd�n1sCwY|�tt|j�|�|��}|�	|d�dSr�r�r�rrr�test_cm_is_reentrantPs
���z'TestRedirectStream.test_cm_is_reentrant)
rrrr�r�rr�r�r�r�r�r�r�rrrrr�$s

r�c@�eZdZeZdZdS)�TestRedirectStdout�stdoutN)rrr�redirect_stdoutr�r�rrrrr�]�r�c@r�)�TestRedirectStderr�stderrN)rrr�redirect_stderrr�r�rrrrr�cr�r�c@sZeZdZejdd��Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dS)�TestSuppresscCr�r	)�suppressr�rHr�rrrr�kr�zTestSuppress.test_instance_docscCs8tt��}|�|�Wd�dS1swYdSr	)r�r]rz)rr�rrr�test_no_result_from_enterrs
"�z&TestSuppress.test_no_result_from_entercCs@tt��|�tdd�d�Wd�dS1swYdS)Nr
r�� )r�r]rH�powr*rrr�test_no_exceptionvs
"�zTestSuppress.test_no_exceptioncCs6tt��
td�Wd�dS1swYdS)Nr�)r�r&r[r*rrr�test_exact_exceptionz�

"�z!TestSuppress.test_exact_exceptioncCs6tt��
ddWd�dS1swYdS)Nr��2)r��LookupErrorr*rrr�test_exception_hierarchy~r�z%TestSuppress.test_exception_hierarchyc	Csp|�t��)tt��ddWd�n1swYWd�dSWd�dS1s1wYdSr�)r%rLr�r&r*rrr�test_other_exception�s

��"�z!TestSuppress.test_other_exceptionc	Csn|�t��(t��ddWd�n1swYWd�dSWd�dS1s0wYdSr�)r%rLr�r*rrr�test_no_args�s
��"�zTestSuppress.test_no_argscCsjttt��ddWd�n1swYttt��
td�Wd�dS1s.wYdS)Nr=rr�)r�rLr&r[r*rrr�test_multiple_exception_args�s
�
"�z)TestSuppress.test_multiple_exception_argsc	Cs�tt�}|�Wd�n1swY|�td�Wd�n1s'wY|�$|�td�Wd�n1s@wYd}ddWd�n1sUwY|�|�dS)Nr�Tr=r)r�rlr[r7)rZignore_exceptionsZouter_continuedrrrr��s�
�
�
�z!TestSuppress.test_cm_is_reentrantN)rrrrr�r�r�r�r�r�r�r�r�r�rrrrr�is
r��__main__)r�r�r�r�r�r/Zunittest�
contextlibrrZtest.supportrr�ZTestCaserr;r�r�r�r�rr�r�r!r�r�r�r�r�r�mainrrrr�<module>sD+"	0!;96�