Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_contextlib.cpython-38.opt-1.pyc
U

>��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__��3/opt/cppython/lib/python3.8/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_enterc	Cs0Gdd�dt�}|�t��|�W5QRXdS)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)"�ContextManagerTestCasec	s`g�t�fdd��}|��*}|��dg�|�|d���|�W5QRX|��dddg�dS)Nc3s��d�dV��d�dS)N��*����appendr��staterr�woohoo<s
z@ContextManagerTestCase.test_contextmanager_plain.<locals>.woohoor-r.r/)�contextmanager�assertEqualr1�r
r4�xrr2r�test_contextmanager_plain:sz0ContextManagerTestCase.test_contextmanager_plainc
s|g�t�fdd��}|�t��B|��0}|��dg�|�|d���|�t��W5QRXW5QRX|��dddg�dS)Nc	3s&��d�z
dVW5��d�XdS)Nr-r/r.r0rr2rrr4Is

zBContextManagerTestCase.test_contextmanager_finally.<locals>.woohoor-r.r/)r5r�ZeroDivisionErrorr6r1r7rr2r�test_contextmanager_finallyGs
z2ContextManagerTestCase.test_contextmanager_finallycCs6tdd��}|�}|��|�|�ttd�d��dS)Ncss
dVdSrrrrrr�wheeYszCContextManagerTestCase.test_contextmanager_no_reraise.<locals>.whee�foo)r5rr*rr)r
r<�ctxrrr�test_contextmanager_no_reraiseXs

z5ContextManagerTestCase.test_contextmanager_no_reraisecCs6tdd��}|�}|��|�t|jttd�d�dS)Ncss"z
dVWndVYnXdSrrrrrr�whoobs
zOContextManagerTestCase.test_contextmanager_trap_yield_after_throw.<locals>.whoor=)r5rr�RuntimeErrorrr)r
r@r>rrr�*test_contextmanager_trap_yield_after_throwas
�zAContextManagerTestCase.test_contextmanager_trap_yield_after_throwc	sjg�t��fdd��}|��2}���dg���|d���|�td��W5QRX���dddg�dS)Nc
3s^��d�z
dVWnDtk
rX}z&��|jd����dddg�W5d}~XYnXdS)Nr-r.rr/)r1r:rr6)�e�r
r3rrr4ps

zAContextManagerTestCase.test_contextmanager_except.<locals>.woohoor-r.r/)r5r6r1r:r7rrDr�test_contextmanager_exceptns
z1ContextManagerTestCase.test_contextmanager_exceptc
Cs�td�}tdd��}z2|�td��|��
|�W5QRXW5QRXWn.tk
rt}z|�||�W5d}~XYnX|�d�dS)N�spamcss
dVdSrrrrrrr4�szJContextManagerTestCase.test_contextmanager_except_stopiter.<locals>.woohoo�
StopIteration�StopIteration was suppressed)rGr5ZassertWarnsRegex�DeprecationWarning�	Exceptionr�fail)r
�stop_excr4�exrrr�#test_contextmanager_except_stopiters
�z:ContextManagerTestCase.test_contextmanager_except_stopiterc
Cs|d}i}t|||�|d}td�}z|��
|�W5QRXWn.tk
rl}z|�||�W5d}~XYnX|�d�dS)Nztfrom __future__ import generator_stop
from contextlib import contextmanager
@contextmanager
def woohoo():
    yield
r4rFrH)�execrGrJrrK)r
�code�localsr4rLrMrrr�!test_contextmanager_except_pep479�sz8ContextManagerTestCase.test_contextmanager_except_pep479c
Cs�tdd��}z|��
t�W5QRXWnRtk
rx}z4|�t|�t�|�|jdd�|�|j	t�W5d}~XYnXz|��t
d��W5QRXWnPtk
r�}z2|�t|�t
�|�|jdd�|�|j	�W5d}~XYnXdS)Nc
ss<z
dVWn,tk
r6}ztd�|�W5d}~XYnXdS)N�issue29692:Chained)rJrA��excrrr�test_issue29692�s
zoContextManagerTestCase.test_contextmanager_do_not_unchain_non_stopiteration_exceptions.<locals>.test_issue29692rrSzissue29692:Unchained)r5r:rJr�typerAr6r�assertIsInstance�	__cause__rG�assertIsNone)r
rVrMrrr�?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)rbrcrrar�attribs�szFContextManagerTestCase._create_contextmanager_attribs.<locals>.attribs�bar)r=cSsdS)�Whee!Nr)rFrrr�baz�szBContextManagerTestCase._create_contextmanager_attribs.<locals>.baz�r5)r
rdrgrrr�_create_contextmanager_attribs�s
z5ContextManagerTestCase._create_contextmanager_attribscCs(|��}|�|jd�|�|jd�dS)Nrgre)rir6rr=�r
rgrrr�test_contextmanager_attribs�sz2ContextManagerTestCase.test_contextmanager_attribscCs|��}|�|jd�dS�Nrf�rir6�__doc__rjrrr�test_contextmanager_doc_attrib�sz5ContextManagerTestCase.test_contextmanager_doc_attribcCs|��d�}|�|jd�dSrlrmrjrrr�*test_instance_docstring_given_cm_docstring�szAContextManagerTestCase.test_instance_docstring_given_cm_docstringc	Cs8tdd��}|ddddd��}|�|d�W5QRXdS)	Ncss||||fVdSrr�r
r^r�kwdsrrrr4�sz4ContextManagerTestCase.test_keywords.<locals>.woohoo���!�,rq)rsrtrurv�r5r6)r
r4�targetrrr�
test_keywords�s
z$ContextManagerTestCase.test_keywordsc	s>Gdd�d�}t�fdd��}||�|�d��W5QRXdS)Nc@seZdZdS)z0ContextManagerTestCase.test_nokeepref.<locals>.ANrrrrr�A�srzc3s6t�|�}t�|�}��|����|��dVdSr)�weakref�refrZ��a�br rrr4�s


z5ContextManagerTestCase.test_nokeepref.<locals>.woohoo�rrh)r
rzr4rr r�test_nokeepref�s
z%ContextManagerTestCase.test_nokeeprefc	Csltdd��}|�t��|�W5QRX|�t��|dd�W5QRX|�t��|dd�W5QRXdS)Ncss
dVdSrrr}rrrr4�sz8ContextManagerTestCase.test_param_errors.<locals>.woohoo��r�)r5rr�r
r4rrr�test_param_errors�s
z(ContextManagerTestCase.test_param_errorscs@d�t��fdd��}|���fdd��������d�dS)Nrc3s*�}�d7�dV�d8����|�dS�Nr-)r6)�before)�depthr
rrr4�s
z5ContextManagerTestCase.test_recursive.<locals>.woohoocs�dkr��dS)N�
rr)r��	recursiverrr�sz8ContextManagerTestCase.test_recursive.<locals>.recursiverwr�r)r�r�r
r�test_recursive�sz%ContextManagerTestCase.test_recursiveN)rrrr9r;r?rBrErNrRr[rirkr�requires_docstringsrorpryr�r�r�rrrrr,8s$
	



r,c@s*eZdZejdd��Zdd�Zdd�ZdS)�ClosingTestCasecCs tj}td�}|�|j|�dSr)�closingrnr6�r
Zcm_docstring�objrrr�test_instance_docssz"ClosingTestCase.test_instance_docsc	sZg�G�fdd�d�}|�}|��g�t|��}|�||�W5QRX|��dg�dS)NcseZdZ�fdd�ZdS)z'ClosingTestCase.test_closing.<locals>.Ccs��d�dSr�r0r r2rr�closesz-ClosingTestCase.test_closing.<locals>.C.closeN�rrrr�rr2rr�Csr�r-)r6r��r
r�r8�yrr2r�test_closings
zClosingTestCase.test_closingc
sxg�G�fdd�d�}|�}|��g�|�t��.t|��}|�||�ddW5QRXW5QRX|��dg�dS)NcseZdZ�fdd�ZdS)z-ClosingTestCase.test_closing_error.<locals>.Ccs��d�dSr�r0r r2rrr�$sz3ClosingTestCase.test_closing_error.<locals>.C.closeNr�rr2rrr�#sr�r-r)r6rr:r�r�rr2r�test_closing_error!s
z"ClosingTestCase.test_closing_errorN)rrrrr�r�r�r�rrrrr�
s
r�c@seZdZdd�ZdS)�NullcontextTestCasec	Cs8Gdd�d�}|�}t|��}|�||�W5QRXdS)Nc@seZdZdS)z/NullcontextTestCase.test_nullcontext.<locals>.CNrrrrrr�1sr�)�nullcontextr)r
r��cZc_inrrr�test_nullcontext0s
z$NullcontextTestCase.test_nullcontextN)rrrr�rrrrr�/sr�c@seZdZdd�ZdS)�FileContextTestCasec
Cs�t��}z�d}t|d��}|�|j�|�d�W5QRX|�|j�d}|�	t
��@t|d��*}|�|j�|�|��d�ddW5QRXW5QRX|�|j�W5t�|�XdS)N�wzBooh
�rr-r)
�tempfile�mktempr�unlink�openr*�closed�writer(rr:r6�read)r
Ztfn�frrr�testWithOpen:sz FileContextTestCase.testWithOpenN)rrrr�rrrrr�8sr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�LockContextTestCasec
Cs~|�|��|�|�|��W5QRX|�|��|�t��*|�|�|��ddW5QRXW5QRX|�|��dS�Nr-r)r*r(rr:)r
�lock�lockedrrr�boilerPlateNszLockContextTestCase.boilerPlatecCst��}|�||j�dSr)�	threading�Lockr�r��r
r�rrr�testWithLockYsz LockContextTestCase.testWithLockcCst��}|�||j�dSr)r��RLockr��	_is_ownedr�rrr�
testWithRLock]sz!LockContextTestCase.testWithRLockcs$t����fdd�}|��|�dS)Ncs���Sr)r�r�r�rrr�csz5LockContextTestCase.testWithCondition.<locals>.locked)r��	Conditionr��r
r�rr�r�testWithConditionasz%LockContextTestCase.testWithConditioncs$t����fdd�}|��|�dS)Ncs��d�r���dSdSdS�NFT��acquire�releaserr�rrr�is
z5LockContextTestCase.testWithSemaphore.<locals>.locked)r��	Semaphorer�r�rr�r�testWithSemaphoregsz%LockContextTestCase.testWithSemaphorecs$t����fdd�}|��|�dS)Ncs��d�r���dSdSdSr�r�rr�rrr�ss
z<LockContextTestCase.testWithBoundedSemaphore.<locals>.locked)r��BoundedSemaphorer�r�rr�r�testWithBoundedSemaphoreqsz,LockContextTestCase.testWithBoundedSemaphoreN)	rrrr�r�r�r�r�r�rrrrr�Ls
r�c@s,eZdZdZdZdZdZdd�Zdd�ZdS)�	mycontextz9Example decoration-compatible context manager for testingFNcCs
d|_|S�NT��startedr rrrr�szmycontext.__enter__cGs||_|jSr)rU�catch�r
rUrrrr�szmycontext.__exit__)	rrrrnr�rUr�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�rnr6r�rrrr��sz'TestContextDecorator.test_instance_docsc	Cs@t�}|�}|�||�|�|j�W5QRX|�|jd�dS)N�NNN)r�rr(r�r6rU)r
�context�resultrrr�test_contextdecorator�s
z*TestContextDecorator.test_contextdecoratorc
Cs�t�}|�td��|�td��W5QRXW5QRX|�|j�|�|jdt�t�}d|_|�td��W5QRX|�|j�|�|jdt�dS)Nr=rT)r��assertRaisesRegex�	NameError�assertIsNotNonerUrr�)r
r�rrr�$test_contextdecorator_with_exception�sz9TestContextDecorator.test_contextdecorator_with_exceptioncs0t�����fdd��}|����jd�dS)Ncs���j����j�dSr�rZrUr(r�r�r�r
rr�test�sz1TestContextDecorator.test_decorator.<locals>.testr�)r�r6rU�r
r�rr�r�test_decorator�s
z#TestContextDecorator.test_decoratorc	sXt�����fdd��}��td��|�W5QRX���j����jdt�dS)Ncs$���j����j�td��dS)Nr=)rZrUr(r�r�rr�rrr��sz@TestContextDecorator.test_decorator_with_exception.<locals>.testr=r)r�r�r�r�rUrr�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~rr�)r
r~rr�rrr�method�sz@TestContextDecorator.test_decorating_method.<locals>.Test.method)N)rrrr�r�r�rr�Test�sr�r-�r~rr�r})r��objectr�r6r~rr�)r
r�r�rr�r�test_decorating_method�s 	z+TestContextDecorator.test_decorating_methodc
Cs<Gdd�dt�}|�t��|��W5QRXW5QRXdS)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
Cs<Gdd�dt�}|�t��|��W5QRXW5QRXdS)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
||_dSrrTr�rrrrszQTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontext.__exit__)rrrr�rUrrrrrr�somecontext�sr�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�r6rU)r
r�r�r�rr�r�test_contextdecorator_as_mixin�sz3TestContextDecorator.test_contextdecorator_as_mixincsft�fdd��}g�|d���fdd��}|d����dddg�g�|d����dddg�dS)	Nc3s��|�dV��d�dS)Nr/r0)r�r2rrr4s
zETestContextDecorator.test_contextmanager_as_decorator.<locals>.woohoor-cs���dg���|�dSr�)r6r1)r8rDrrr�szCTestContextDecorator.test_contextmanager_as_decorator.<locals>.testZ	somethingr/zsomething elserw)r
r4r�rrDr� 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'�ZdS)(�TestBaseExitStackNcCs"|jj}|��}|�|j|�dSr)�
exit_stackrnr6r�rrrr�.sz$TestBaseExitStack.test_instance_docsc	Cs|���W5QRXdSr)r�r rrr�test_no_resources5s
z#TestBaseExitStack.test_no_resourcescs�difdifdifdtdd�fdtdd�fdtdd�fdtddd�fg}g��fd	d
�}|����}t|�D]d\}}|r�|r�|j|f|�|�}n4|r�|j|f|��}n|r�|j|f|�}n
|�|�}|�||�qj|jD]>}|�|dj|�|�|dj|j�|�	|dj
|j
�q�W5QRX|��|�g�|���p}|�t
��|jdd�W5QRX|�t
��|jjdd�W5QRX|�t��|j|dd
�W5QRXW5QRX|��dddifg�dS)Nr)r-)r-r�r-)Zexampler��)r
�callbackcs��||f�dS)zTest metadata propagationNr0)rrr�r�rr�_exitDsz.TestBaseExitStack.test_callback.<locals>._exit)�argr�)r�r�r�)�dictr��reversedr�r�_exit_callbacks�__wrapped__ZassertNotEqualrrZrnr6rrZassertWarnsrI)r
Zexpectedr��stackrrrr��wrapperrr�r�
test_callback9sD�	


 
"zTestBaseExitStack.test_callbackc	s*t���fdd�}dd�}�fdd�}Gdd�dt�}�����}|�|���|jd	d
|�||�}|�|���|jd	d
j|�|�|���|jd	d
|�||�}|�|���|jd	d
j|�|�|���|jd	d
|�|�|���|jd	d
|�d
dW5QRXdS)Ncs��|��dSr)r�r!rU�exc_tb�Z
exc_raisedr
rr�_expect_excdsz0TestBaseExitStack.test_push.<locals>._expect_exccWsdSr�r��exc_detailsrrr�
_suppress_excfsz2TestBaseExitStack.test_push.<locals>._suppress_exccs"��|���|���|�dSr)rZr�r rr�
_expect_okhs

z/TestBaseExitStack.test_push.<locals>._expect_okc@s$eZdZdd�Zdd�Zdd�ZdS)z+TestBaseExitStack.test_push.<locals>.ExitCMcSs
||_dSr��	check_exc)r
r�rrr�__init__msz4TestBaseExitStack.test_push.<locals>.ExitCM.__init__cSs|�d�dS)NzShould not be called!)rKr rrrrosz5TestBaseExitStack.test_push.<locals>.ExitCM.__enter__cWs|j|�dSrr��r
r�rrrrqsz4TestBaseExitStack.test_push.<locals>.ExitCM.__exit__N�rrrrrrrrrr�ExitCMlsr���r-r)r:r�r��pushrr��__self__)r
r�r�r�rr��cmrr�r�	test_pushbs*






zTestBaseExitStack.test_pushc	s�G�fdd�dt�}g�|�}|���N}|j�fdd��}|�|�|�|�|�|jddj|���d�W5QRX|�	�dddd	g�dS)
Ncs$eZdZ�fdd�Z�fdd�ZdS)z4TestBaseExitStack.test_enter_context.<locals>.TestCMcs��d�dSr�r0r r�rrr�sz>TestBaseExitStack.test_enter_context.<locals>.TestCM.__enter__cs��d�dS�Nr�r0rr�rrr�sz=TestBaseExitStack.test_enter_context.<locals>.TestCM.__exit__Nr$rr�rr�TestCM�sr
cs��d�dS)Nr�r0rr�rrr��sz3TestBaseExitStack.test_enter_context.<locals>._exitrr-r�r�r�)
r�r�r�r��
enter_contextrr�rr1r6)r
r
rr�r�rr�r�test_enter_context�s


z$TestBaseExitStack.test_enter_contextc	sZg�|���4}|j�fdd��}|�|�|����d�W5QRX|��ddg�dS)Ncs��d�dSr�r0rr�rrr��sz+TestBaseExitStack.test_close.<locals>._exitr�r-)r�r�r�r�r1r6)r
r�r�rr�r�
test_close�s

zTestBaseExitStack.test_closec	sng�|���4}|j�fdd��}|�|�|��}��d�W5QRX��d�|��|��dddg�dS)Ncs��d�dSr	r0rr�rrr��sz-TestBaseExitStack.test_pop_all.<locals>._exitr-r�r�)r�r�r��pop_allr1r�r6)r
r�r��	new_stackrr�r�test_pop_all�s


zTestBaseExitStack.test_pop_allc
CsD|�t��0|���}|�dd��ddW5QRXW5QRXdS)NcWsdS)NFrrTrrr�<lambda>��z3TestBaseExitStack.test_exit_raise.<locals>.<lambda>r-r)rr:r�r�r
r�rrr�test_exit_raise�s
z!TestBaseExitStack.test_exit_raisec	Cs.|���}|�dd��ddW5QRXdS)NcWsdSr�rrTrrrr�rz6TestBaseExitStack.test_exit_suppress.<locals>.<lambda>r-r�r�rrrrr�test_exit_suppress�s
z$TestBaseExitStack.test_exit_suppresscCs
Gdd�d�}Gdd�d�}Gdd�d�}z\|t��J|tt��4|��"|t��ddW5QRXW5QRXW5QRXW5QRXWnPtk
r�}z2|�|jt�|�|jjt�|�|jjj�W5d}~XYnX|�d	�|jd}|�|t�|�|jt	�dS)
Nc@s$eZdZdd�Zdd�Zdd�ZdS)zJTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExccSs
||_dSrrTr�rrrr�szSTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__init__cSs|Srrr rrrr�szTTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__enter__cWs
|j�dSrrTrrrrr�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�YnXdSr)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�)rW�
saved_detailsrrrrr�s
zVTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExc.__exit__Nr$rrrr�SuppressExc�srr-r�0Expected IndexError, but no exception was raised)
�
IndexError�KeyErrorr��
ValueErrorrX�__context__rZrKrr:)r
rrrrU�	inner_excrrr�&test_exit_exception_chaining_reference�s"

4"

z8TestBaseExitStack.test_exit_exception_chaining_referencec
s�dd�}d��fdd�}zZ|���H}|�|t�|�|t�|�|t�|�|�|�|t�ddW5QRXWnPtk
r�}z2|�|jt�|�|jjt�|�	|jjj�W5d}~XYnX|�
d��d}|�|t�|�|jt�dS)NcSs|�dSrrrTrrr�	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�rrr�rr rXr!rZrKr:)r
r$r&r�rUr"rr%r�test_exit_exception_chaining�s&

"
z.TestBaseExitStack.test_exit_exception_chainingc
Cs�dd�}dd�}z2|��� }|�dd��|�|t�W5QRXWn.tk
rp}z|�|t�W5d}~XYnX|�d�z:|���(}|�|t�|�|�|�|t�W5QRXWn.tk
r�}z|�|t�W5d}~XYnX|�d�dS)	NcSs|�dSrrrTrrrr$szHTestBaseExitStack.test_exit_exception_non_suppressing.<locals>.raise_exccWsdSr�rr�rrrr&szKTestBaseExitStack.test_exit_exception_non_suppressing.<locals>.suppress_exccSsdSrrrrrrrrzGTestBaseExitStack.test_exit_exception_non_suppressing.<locals>.<lambda>rz.Expected KeyError, but no exception was raised)r�r�rrJrXrKrr)r
r$r&r�rUrrr�#test_exit_exception_non_suppressing	s"



z5TestBaseExitStack.test_exit_exception_non_suppressingc
Cs�tdd��}td�}td�}td�}td�}zF|���4}|�||��|�||��|�||��|�W5QRXWnptk
r�}zR|�||�|�|j|�|�|jj|�|�|jjj|�|�|jjjj�W5d}~XYnXdS)Ncssz
dVW5|�XdSrrrTrrr�gets_the_context_right&s
zZTestBaseExitStack.test_exit_exception_with_correct_context.<locals>.gets_the_context_rightr-r�r�r�)r5rJr�rrr!rZ)r
r)�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�}z8|���&}|�|||�|�|||�|�W5QRXWn�tk
r�}zh|�||�|�|j|�|�|jj|�|�|jjj|�|�|jjjj|�|�|jjjjj�W5d}~XYnXdS)NcSsz|�W5|�XdSrr)r"Z	outer_excrrr�raise_nestedFszQTestBaseExitStack.test_exit_exception_with_existing_context.<locals>.raise_nestedr-r�r�r�r�)rJr�r�rr!rZ)	r
r/r*r+r,r-Zexc5r�rUrrr�)test_exit_exception_with_existing_contextCs.

��z;TestBaseExitStack.test_exit_exception_with_existing_contextc
Csddd�}z*|���}|�|�ddW5QRXWn,tk
r^}z|�d�W5d}~XYnXdS)NcWsdSr�rr�rrrr&`szDTestBaseExitStack.test_body_exception_suppress.<locals>.suppress_excr-rz%Expected no exception, got IndexError)r�rrrK)r
r&r�rUrrr�test_body_exception_suppress_s

z.TestBaseExitStack.test_body_exception_suppressc	CsB|���0}|�dd��|�dd��|�dd��W5QRXdS)NcWsdSr�rrTrrrrkrzITestBaseExitStack.test_exit_exception_chaining_suppress.<locals>.<lambda>cWsddSr�rrTrrrrlrcWsidSr�rrTrrrrmrrrrrr�%test_exit_exception_chaining_suppressis
z7TestBaseExitStack.test_exit_exception_chaining_suppressc	Cs0|���}td�D]}|�t�qW5QRXdS)Ni')r��ranger��int)r
r��irrr�test_excessive_nestingos
z(TestBaseExitStack.test_excessive_nestingcCsZGdd�dt�}|�}t�|_|��}|�t|j|�|�|�|�|jdd|�dS)Nc@seZdZdS)z7TestBaseExitStack.test_instance_bypass.<locals>.ExampleNrrrrr�Examplevsr7rr-)	r�rr�rr�rrrr�)r
r7rr�rrr�test_instance_bypassus
z&TestBaseExitStack.test_instance_bypassc
s�Gdd�dt��Gdd�dt�}t�fdd��}tdd��}|����:}|���&}|�|��|�|��|d	��W5QRXW5QRX|j}|�|��|�|j|�|�	|jj�|�	|jj
�|�|j
|j�dS)
Nc@seZdZdS)zITestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.UniqueExceptionNrrrrr�UniqueException�sr9c@seZdZdS)zLTestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.UniqueRuntimeErrorNrrrrr�UniqueRuntimeError�sr:c
3s<z
dVWn,tk
r6}z�d�|�W5d}~XYnXdS)Nr-z
new exception�rJrT�r9rr�second�s
z@TestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.secondc
ss6z
dVWn&tk
r0}z|�W5d}~XYnXdSr�r;rTrrr�first�s
z?TestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.firstzplease no infinite loop.)rJrAr5rr�r�	exceptionrXr!rZrYr)r
r:r=r>Zerr_ctxZes_ctxrUrr<r�test_dont_reraise_RuntimeError~s"

z0TestBaseExitStack.test_dont_reraise_RuntimeError)rrrr�rr�r�r�r�rrr
rrrr#r'r(r.r0r1r2r6r8r@rrrrr�+s*
)"
0
	r�c@seZdZeZdS)�
TestExitStackN)rrr�	ExitStackr�rrrrrA�srAc@sJeZdZdZdZejdd��Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�ZdS)�TestRedirectStreamNcCs$|jj}|�d�}|�|j|�dSr)�redirect_streamrnr6r�rrrr��s
z%TestRedirectStream.test_instance_docscCs.tt|j�}|�d�|�tt|j�|�dSr)�getattr�sys�orig_streamrDr)r
�orig_stdoutrrr�test_no_redirect_in_init�s
z+TestRedirectStream.test_no_redirect_in_initc	Csrt��}d}tt|j�}|�|��t|tt|j�d�W5QRX|�tt|j�|�|���	�}|�
||�dS)Nz<Consider an API like help(), which prints directly to stdout��file)�io�StringIOrErFrGrD�printr�getvalue�stripr6)r
r��msgrH�srrr�test_redirect_to_string_io�sz-TestRedirectStream.test_redirect_to_string_ioc	Cs.t��}|�|��}|�||�W5QRXdSr)rLrMrDr)r
r��enter_resultrrr�test_enter_result_is_target�sz.TestRedirectStream.test_enter_result_is_targetc	Cs�t��}|�|�}tt|j�}|�tddtt|j�d�W5QRX|�tdtt|j�d�W5QRX|�tt|j�|�|��}|�	|d�dS�N�Hello� )�endrKzWorld!rJz
Hello World!
�
rLrMrDrErFrGrNrrOr6�r
r�Z
write_to_frHrRrrr�test_cm_is_reusable�s
 z&TestRedirectStream.test_cm_is_reusablec
Cs�t��}|�|�}tt|j�}|�@tddtt|j�d�|�tdtt|j�d�W5QRXW5QRX|�tt|j�|�|��}|�	|d�dSrVrZr[rrr�test_cm_is_reentrant�s
(z'TestRedirectStream.test_cm_is_reentrant)
rrrrDrGrr�r�rIrSrUr\r]rrrrrC�s

rCc@seZdZeZdZdS)�TestRedirectStdout�stdoutN)rrr�redirect_stdoutrDrGrrrrr^�sr^c@seZdZeZdZdS)�TestRedirectStderr�stderrN)rrr�redirect_stderrrDrGrrrrra�srac@sZeZdZejdd��Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dS)�TestSuppresscCstj}t�}|�|j|�dSr)�suppressrnr6r�rrrr��szTestSuppress.test_instance_docsc	Cs"tt��}|�|�W5QRXdSr)rer rZ)r
rTrrr�test_no_result_from_enter�s
z&TestSuppress.test_no_result_from_enterc	Cs*tt��|�tdd�d�W5QRXdS)Nr�r�� )rer r6�powr rrr�test_no_exception�s
zTestSuppress.test_no_exceptionc	Cs tt��td�W5QRXdS)Nr�)rer�lenr rrr�test_exact_exception�s
z!TestSuppress.test_exact_exceptionc	Cs tt��ddW5QRXdS)NrW�2)re�LookupErrorr rrr�test_exception_hierarchy�s
z%TestSuppress.test_exception_hierarchyc
Cs6|�t��"tt��ddW5QRXW5QRXdSr�)rr:rerr rrr�test_other_exceptions
z!TestSuppress.test_other_exceptionc
Cs4|�t�� t��ddW5QRXW5QRXdSr�)rr:rer rrr�test_no_argsszTestSuppress.test_no_argsc	Cs@ttt��ddW5QRXttt��td�W5QRXdS)Nr-rr�)rer:rrjr rrr�test_multiple_exception_args
sz)TestSuppress.test_multiple_exception_argsc
Csrtt�}|�W5QRX|�td�W5QRX|�*|�td�W5QRXd}ddW5QRX|�|�dS)Nr�Tr-r)rerJrjr()r
Zignore_exceptionsZouter_continuedrrrr]s
z!TestSuppress.test_cm_is_reentrantN)rrrrr�r�rfrirkrnrorprqr]rrrrrd�s
rd�__main__)rnrLrFr�r�Zunittest�
contextlibr�rr{ZTestCaserr,r�r�r�r�r�r�r�r�rArCr^rardr�mainrrrr�<module>s8+V"	0!x96


F1le Man4ger