Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_contextlib.cpython-34.pyc

�
g fg�
@s�dZddlZddlZddlZddlZddlTddlmZyddlZWne	k
rzdZYnXGdd�dej
�ZGdd�dej
�ZGd	d
�d
ej
�Z
ejed�Gdd
�d
ej
��ZGdd�de�ZGdd�dej
�ZGdd�dej
�ZGdd�dej
�ZGdd�dej
�Zedkr�ej�ndS)z9Unit tests for contextlib.py, and other context managers.�N)�*)�supportc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
jdd��Ze
jdd��Z
dd�ZdS)�ContextManagerTestCasecs}g�t�fdd��}|��7}|j�dg�|j|d��j|�WdQX|j�dddg�dS)Nc3s#�jd�dV�jd�dS)N��*i�)�append�)�stater�9/opt/alt/python34/lib64/python3.4/test/test_contextlib.py�woohoos
z@ContextManagerTestCase.test_contextmanager_plain.<locals>.woohoorri�)�contextmanager�assertEqualr)�selfr�xr)r	r
�test_contextmanager_plainsz0ContextManagerTestCase.test_contextmanager_plaincs�g�t�fdd��}|jt��P|��@}|j�dg�|j|d��j|�t��WdQXWdQX|j�dddg�dS)Nc3s+�jd�z	dVWd�jd�XdS)Nrri�)rr)r	rr
r s
	zBContextManagerTestCase.test_contextmanager_finally.<locals>.woohoorri�)r�assertRaises�ZeroDivisionErrorr
r)rrrr)r	r
�test_contextmanager_finallys
z2ContextManagerTestCase.test_contextmanager_finallycCsKtdd��}|�}|j�|j|jttd�d��dS)Ncss	dVdS)Nrrrrr
�whee0szCContextManagerTestCase.test_contextmanager_no_reraise.<locals>.whee�foo)r�	__enter__�assertFalse�__exit__�	TypeError)rr�ctxrrr
�test_contextmanager_no_reraise/s	
z5ContextManagerTestCase.test_contextmanager_no_reraisecCsKtdd��}|�}|j�|jt|jttd�d�dS)Nc	ssy	dVWn
dVYnXdS)Nrrrrr
�whoo9s	zOContextManagerTestCase.test_contextmanager_trap_yield_after_throw.<locals>.whoor)rrr�RuntimeErrorrr)rrrrrr
�*test_contextmanager_trap_yield_after_throw8s
	
zAContextManagerTestCase.test_contextmanager_trap_yield_after_throwcs�g�t��fdd��}|��C}�j�dg��j|d��j|�td��WdQX�j�dddg�dS)Nc3so�jd�y	dVWnRtk
rj}z2�j|jd��j�dddg�WYdd}~XnXdS)Nrrri�)rr�argsr
)�e)rr	rr
rGs
	zAContextManagerTestCase.test_contextmanager_except.<locals>.woohoorri�)rr
rr)rrrr)rr	r
�test_contextmanager_exceptEs
z1ContextManagerTestCase.test_contextmanager_exceptcCs1dd�}t|dd�dd���}|S)Ncs�fdd�}|S)Ncs1x*�j�D]\}}t|||�q
W|S)N)�items�setattr)�func�k�v)�kwrr
�decorateXszXContextManagerTestCase._create_contextmanager_attribs.<locals>.attribs.<locals>.decorater)r'r(r)r'r
�attribsWszFContextManagerTestCase._create_contextmanager_attribs.<locals>.attribsr�barcSsdS)zWhee!Nr)Zspamrrr
�baz]szBContextManagerTestCase._create_contextmanager_attribs.<locals>.baz)r)rr)r+rrr
�_create_contextmanager_attribsVsz5ContextManagerTestCase._create_contextmanager_attribscCs6|j�}|j|jd�|j|jd�dS)Nr+r*)r,r
�__name__r)rr+rrr
�test_contextmanager_attribscsz2ContextManagerTestCase.test_contextmanager_attribscCs#|j�}|j|jd�dS)NzWhee!)r,r
�__doc__)rr+rrr
�test_contextmanager_doc_attribhsz5ContextManagerTestCase.test_contextmanager_doc_attribcCs)|j�d�}|j|jd�dS)NzWhee!)r,r
r/)rr+rrr
�*test_instance_docstring_given_cm_docstringmszAContextManagerTestCase.test_instance_docstring_given_cm_docstringc
CsPtdd��}|ddddddd	d
��}|j|d�WdQXdS)Ncss||||fVdS)Nr)rr$r�kwdsrrr
rtsz4ContextManagerTestCase.test_keywords.<locals>.woohoor�r$�r�!r2�,)r3r4r5r6)rr
)rr�targetrrr
�
test_keywordsrs$z$ContextManagerTestCase.test_keywordsN)r-�
__module__�__qualname__rrrrr!r,r.r�requires_docstringsr0r1r8rrrr
rs
	

rc@s=eZdZejdd��Zdd�Zdd�ZdS)�ClosingTestCasecCs,tj}td�}|j|j|�dS)N)�closingr/r
)r�cm_docstring�objrrr
�test_instance_docs}s	z"ClosingTestCase.test_instance_docsc
stg�G�fdd�d�}|�}|j�g�t|��}|j||�WdQX|j�dg�dS)Ncs"eZdZ�fdd�ZdS)z'ClosingTestCase.test_closing.<locals>.Ccs�jd�dS)Nr)r)r)r	rr
�close�sz-ClosingTestCase.test_closing.<locals>.C.closeN)r-r9r:rAr)r	rr
�C�srBr)r
r=)rrBr�yr)r	r
�test_closing�s	zClosingTestCase.test_closingcs�g�G�fdd�d�}|�}|j�g�|jt��2t|��}|j||�ddWdQXWdQX|j�dg�dS)Ncs"eZdZ�fdd�ZdS)z-ClosingTestCase.test_closing_error.<locals>.Ccs�jd�dS)Nr)r)r)r	rr
rA�sz3ClosingTestCase.test_closing_error.<locals>.C.closeN)r-r9r:rAr)r	rr
rB�srBrr)r
rrr=)rrBrrCr)r	r
�test_closing_error�s	z"ClosingTestCase.test_closing_errorN)r-r9r:rr;r@rDrErrrr
r<{sr<c@seZdZdd�ZdS)�FileContextTestCasecCs�tj�}z�d}t|d��$}|j|j�|jd�WdQX|j|j�d}|jt��Kt|d��5}|j|j�|j	|j
�d�ddWdQXWdQX|j|j�Wdtj|�XdS)N�wzBooh
�rrr)
�tempfileZmktemp�openr�closed�write�
assertTruerrr
�readr�unlink)rZtfn�frrr
�testWithOpen�sz FileContextTestCase.testWithOpenN)r-r9r:rQrrrr
rF�srFz!Threading required for this test.c@sXeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�LockContextTestCasecCs�|j|��|�|j|��WdQX|j|��|jt��*|�|j|��ddWdQXWdQX|j|��dS)Nrr)rrMrr)r�lock�lockedrrr
�boilerPlate�szLockContextTestCase.boilerPlatecCs#tj�}|j||j�dS)N)�	threadingZLockrUrT)rrSrrr
�testWithLock�sz LockContextTestCase.testWithLockcCs#tj�}|j||j�dS)N)rV�RLockrU�	_is_owned)rrSrrr
�
testWithRLock�sz!LockContextTestCase.testWithRLockcs2tj���fdd�}|j�|�dS)Ncs
�j�S)N)rYr)rSrr
rT�sz5LockContextTestCase.testWithCondition.<locals>.locked)rVZ	ConditionrU)rrTr)rSr
�testWithCondition�sz%LockContextTestCase.testWithConditioncs2tj���fdd�}|j�|�dS)Ncs%�jd�r�j�dSdSdS)NFT)�acquire�releaser)rSrr
rT�s
z5LockContextTestCase.testWithSemaphore.<locals>.locked)rVZ	SemaphorerU)rrTr)rSr
�testWithSemaphore�sz%LockContextTestCase.testWithSemaphorecs2tj���fdd�}|j�|�dS)Ncs%�jd�r�j�dSdSdS)NFT)r\r]r)rSrr
rT�s
z<LockContextTestCase.testWithBoundedSemaphore.<locals>.locked)rVZBoundedSemaphorerU)rrTr)rSr
�testWithBoundedSemaphore�sz,LockContextTestCase.testWithBoundedSemaphoreN)	r-r9r:rUrWrZr[r^r_rrrr
rR�s
rRc@s@eZdZdZdZdZdZdd�Zdd�ZdS)�	mycontextz9Example decoration-compatible context manager for testingFNcCs
d|_|S)NT)�started)rrrr
r�s	zmycontext.__enter__cGs||_|jS)N)�exc�catch)rrbrrr
r�s	zmycontext.__exit__)	r-r9r:r/rarbrcrrrrrr
r`�sr`c@s�eZdZejdd��Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�ZdS)�TestContextDecoratorcCs)tj}t�}|j|j|�dS)N)r`r/r
)rr>r?rrr
r@�s		z'TestContextDecorator.test_instance_docscCsOt�}|�'}|j||�|j|j�WdQX|j|jd�dS)N)NNN)r`�assertIsrMrar
rb)r�context�resultrrr
�test_contextdecorator�s
		z*TestContextDecorator.test_contextdecoratorcCs�t�}|jtd��|�td��WdQXWdQX|j|j�|j|jdt�t�}d|_|�td��WdQX|j|j�|j|jdt�dS)NrrT)r`�assertRaisesRegex�	NameError�assertIsNotNonerbrerc)rrfrrr
�$test_contextdecorator_with_exceptions			z9TestContextDecorator.test_contextdecorator_with_exceptioncsBt�����fdd��}|��j�jd�dS)Ncs$�j�j��j�j�dS)N)�assertIsNonerbrMrar)rfrrr
�testsz1TestContextDecorator.test_decorator.<locals>.test)NNN)r`r
rb)rrnr)rfrr
�test_decorators	z#TestContextDecorator.test_decoratorc	sot�����fdd��}�jtd��|�WdQX�j�j��j�jdt�dS)Ncs0�j�j��j�j�td��dS)Nr)rmrbrMrarjr)rfrrr
rn!sz@TestContextDecorator.test_decorator_with_exception.<locals>.testrr)r`rirjrkrbre)rrnr)rfrr
�test_decorator_with_exceptions	
z2TestContextDecorator.test_decorator_with_exceptioncst��G�fdd�dt�}|�}|jdd�|j|jd�|j|jd�|j|jd�|�}|jddd�|j|jd�|j|jd�|j|jd�|�}|jdddd�|j|jd�|j|jd�dS)Ncs%eZdZ�ddd��ZdS)z9TestContextDecorator.test_decorating_method.<locals>.TestNcSs||_||_||_dS)N)�a�b�c)rrqrrrsrrr
�method2s		z@TestContextDecorator.test_decorating_method.<locals>.Test.method)r-r9r:rtr)rfrr
�Test0srur�rqrrrs)r`�objectrtr
rqrrrs)rrurnr)rfr
�test_decorating_method-s 					z+TestContextDecorator.test_decorating_methodcCs@Gdd�dt�}|jt��|��WdQXWdQXdS)Nc@s(eZdZdd�Zdd�ZdS)z7TestContextDecorator.test_typo_enter.<locals>.mycontextcSsdS)Nr)rrrr
�	__unter__MszATestContextDecorator.test_typo_enter.<locals>.mycontext.__unter__cWsdS)Nr)rrbrrr
rOsz@TestContextDecorator.test_typo_enter.<locals>.mycontext.__exit__N)r-r9r:ryrrrrr
r`Lsr`)�ContextDecoratorr�AttributeError)rr`rrr
�test_typo_enterKs
z$TestContextDecorator.test_typo_entercCs@Gdd�dt�}|jt��|��WdQXWdQXdS)Nc@s(eZdZdd�Zdd�ZdS)z6TestContextDecorator.test_typo_exit.<locals>.mycontextcSsdS)Nr)rrrr
rYsz@TestContextDecorator.test_typo_exit.<locals>.mycontext.__enter__cWsdS)Nr)rrbrrr
�__uxit__[sz?TestContextDecorator.test_typo_exit.<locals>.mycontext.__uxit__N)r-r9r:rr}rrrr
r`Xsr`)rzrr{)rr`rrr
�test_typo_exitWs
z#TestContextDecorator.test_typo_exitcsqGdd�dt�}Gdd�d|t�}|�����fdd��}|��j�jd�dS)Nc@s4eZdZdZdZdd�Zdd�ZdS)zHTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontextFNcSs
d|_|S)NT)ra)rrrr
rhs	zRTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontext.__enter__cWs
||_dS)N)rb)rrbrrr
rlszQTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontext.__exit__)r-r9r:rarbrrrrrr
�somecontextdsrc@seZdZdS)zFTestContextDecorator.test_contextdecorator_as_mixin.<locals>.mycontextN)r-r9r:rrrr
r`osr`cs$�j�j��j�j�dS)N)rmrbrMrar)rfrrr
rnsszATestContextDecorator.test_contextdecorator_as_mixin.<locals>.test)NNN)rwrzr
rb)rrr`rnr)rfrr
�test_contextdecorator_as_mixincs	z3TestContextDecorator.test_contextdecorator_as_mixincs�t�fdd��}g�|d���fdd��}|d��j�dddg�g�|d��j�dddg�dS)	Nc3s#�j|�dV�jd�dS)Ni�)r)rC)r	rr
r|s
zETestContextDecorator.test_contextmanager_as_decorator.<locals>.woohoorcs$�j�dg��j|�dS)Nr)r
r)r)rr	rr
rn�szCTestContextDecorator.test_contextmanager_as_decorator.<locals>.testZ	somethingi�zsomething else)rr
)rrrnr)rr	r
� test_contextmanager_as_decorator{s!

z5TestContextDecorator.test_contextmanager_as_decoratorN)r-r9r:rr;r@rhrlrorprxr|r~r�r�rrrr
rd�s	rdc@s�eZdZejdd��Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%S)&�
TestExitStackcCs)tj}t�}|j|j|�dS)N)�	ExitStackr/r
)rr>r?rrr
r@�s		z TestExitStack.test_instance_docscCst��WdQXdS)N)r�)rrrr
�test_no_resources�s
zTestExitStack.test_no_resourcescs~fifdifdifftdd�fdtdd�fd	tdd�fg}g��fdd�}t���}x�t|�D]�\}}|r�|r�|j|||�}nE|r�|j||�}n*|r�|j||�}n|j|�}|j||�q�WxP|jD]E}|j|j|�|j|j|j�|j	|j
|j
�qWWdQX|j�|�dS)
NrrvZexamplecs�j||f�dS)zTest metadata propagationN)r)rr2)rgrr
�_exit�sz*TestExitStack.test_callback.<locals>._exit)r)rrv)r)rrv)�dictr��reversed�callbackre�_exit_callbacks�__wrapped__ZassertNotEqualr-rmr/r
)rZexpectedr��stackrr2rP�wrapperr)rgr
�
test_callback�s.			 zTestExitStack.test_callbackc
sct���fdd�}dd�}�fdd�}Gdd�dt�}t��}|j|��j|jd|�||�}|j|��j|jdj|�|j|��j|jd
|�||�}|j|��j|jdj|�|j|��j|jd|�|j|��j|jd|�d	d
WdQXdS)Ncs�j|��dS)N)re)�exc_typerb�exc_tb)�
exc_raisedrrr
�_expect_exc�sz,TestExitStack.test_push.<locals>._expect_exccWsdS)NTr)�exc_detailsrrr
�
_suppress_exc�sz.TestExitStack.test_push.<locals>._suppress_exccs+�j|��j|��j|�dS)N)rm)r�rbr�)rrr
�
_expect_ok�s

z+TestExitStack.test_push.<locals>._expect_okc@s4eZdZdd�Zdd�Zdd�ZdS)z'TestExitStack.test_push.<locals>.ExitCMcSs
||_dS)N)�	check_exc)rr�rrr
�__init__�sz0TestExitStack.test_push.<locals>.ExitCM.__init__cSs|jd�dS)NzShould not be called!)�fail)rrrr
r�sz1TestExitStack.test_push.<locals>.ExitCM.__enter__cWs|j|�dS)N)r�)rr�rrr
r�sz0TestExitStack.test_push.<locals>.ExitCM.__exit__N)r-r9r:r�rrrrrr
�ExitCM�sr�rr���r�r�r�r�r�)rrwr��pushrer��__self__)rr�r�r�r�r��cmr)r�rr
�	test_push�s*





zTestExitStack.test_pushcs�G�fdd�dt�}g�|�}t��c}|j�fdd��}|j|�|j|�|j|jd	j|��jd�WdQX|j	�ddddg�dS)
Ncs4eZdZ�fdd�Z�fdd�ZdS)z0TestExitStack.test_enter_context.<locals>.TestCMcs�jd�dS)Nr)r)r)rgrr
r�sz:TestExitStack.test_enter_context.<locals>.TestCM.__enter__cs�jd�dS)N�)r)rr�)rgrr
r�sz9TestExitStack.test_enter_context.<locals>.TestCM.__exit__N)r-r9r:rrr)rgrr
�TestCM�sr�cs�jd�dS)N�)rr)rgrr
r��sz/TestExitStack.test_enter_context.<locals>._exitrrvr�r�r�)
rwr�r�rk�
enter_contextrer�r�rr
)rr�r�r�r�r)rgr
�test_enter_context�s	

z TestExitStack.test_enter_contextcsqg�t��F}|j�fdd��}|j|�|j��jd�WdQX|j�ddg�dS)Ncs�jd�dS)Nr)rr)rgrr
r��sz'TestExitStack.test_close.<locals>._exitrvr)r�r�rkrArr
)rr�r�r)rgr
�
test_close�s

zTestExitStack.test_closecs�g�t��H}|j�fdd��}|j|�|j�}�jd�WdQX�jd�|j�|j�dddg�dS)Ncs�jd�dS)Nr�)rr)rgrr
r��sz)TestExitStack.test_pop_all.<locals>._exitrrvr�)r�r�rk�pop_allrrAr
)rr�r��	new_stackr)rgr
�test_pop_all�s


zTestExitStack.test_pop_allcCsG|jt��2t��"}|jdd��ddWdQXWdQXdS)NcWsdS)NFr)rbrrr
�<lambda>sz/TestExitStack.test_exit_raise.<locals>.<lambda>rr)rrr�r�)rr�rrr
�test_exit_raiseszTestExitStack.test_exit_raisec
Cs1t��"}|jdd��ddWdQXdS)NcWsdS)NTr)rbrrr
r�sz2TestExitStack.test_exit_suppress.<locals>.<lambda>rr)r�r�)rr�rrr
�test_exit_suppresssz TestExitStack.test_exit_suppressc$Cs9Gdd�d�}Gdd�d�}Gdd�d�}yX|t��F|tt��0|�� |t��
ddWdQXWdQXWdQXWdQXWndtk
r�}zD|j|jt�|j|jjt�|j|jjj�WYdd}~XnX|jd	�|jd}|j|t�|j|jt	�dS)
Nc@s4eZdZdd�Zdd�Zdd�ZdS)zFTestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExccSs
||_dS)N)rb)rrbrrr
r�szOTestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__init__cSs|S)Nr)rrrr
rszPTestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__enter__cWs
|j�dS)N)rb)rr�rrr
rszOTestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__exit__N)r-r9r:r�rrrrrr
�RaiseExcsr�c@s4eZdZdd�Zdd�Zdd�ZdS)zQTestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContextcSs||_||_dS)N)�outer�inner)rr�r�rrr
r�s	zZTestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContext.__init__cSs|S)Nr)rrrr
r"sz[TestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContext.__enter__c	Ws%y
|j�Wn|j�YnXdS)N)r�r�)rr�rrr
r$s
zZTestExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContext.__exit__N)r-r9r:r�rrrrrr
�RaiseExcWithContextsr�c@s(eZdZdd�Zdd�ZdS)zITestExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExccSs|S)Nr)rrrr
r+szSTestExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExc.__enter__cWs|t|�_dS)NT)�type�
saved_details)rr�rrr
r-szRTestExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExc.__exit__N)r-r9r:rrrrrr
�SuppressExc*sr�rrz0Expected IndexError, but no exception was raised)
�
IndexError�KeyErrorr{�
ValueError�assertIsInstance�__context__rmr�r�r)rr�r�r�rb�	inner_excrrr
�&test_exit_exception_chaining_references"


$)

z4TestExitStack.test_exit_exception_chaining_referencecs4dd�}d��fdd�}ykt��\}|j|t�|j|t�|j|t�|j|�|j|t�ddWdQXWndtk
r�}zD|j|jt�|j|jjt�|j	|jjj�WYdd}~XnX|j
d��d}|j|t�|j|jt�dS)NcSs
|�dS)Nr)rbrrr
�	raise_excEsz=TestExitStack.test_exit_exception_chaining.<locals>.raise_exccs
|�dS)NTr)r�)r�rr
�suppress_excIsz@TestExitStack.test_exit_exception_chaining.<locals>.suppress_excrrz0Expected IndexError, but no exception was raised)r�r�r�r�r{r�r�r�r�rmr�r)rr�r�r�rbr�r)r�r
�test_exit_exception_chainingCs&
)

z*TestExitStack.test_exit_exception_chainingcCs"dd�}dd�}y9t��*}|jdd��|j|t�WdQXWn5tk
r�}z|j|t�WYdd}~XnX|jd�yCt��4}|j|t�|j|�|j|t�WdQXWn5tk
r}z|j|t�WYdd}~XnX|jd�dS)	NcSs
|�dS)Nr)rbrrr
r�dszDTestExitStack.test_exit_exception_non_suppressing.<locals>.raise_exccWsdS)NTr)r�rrr
r�gszGTestExitStack.test_exit_exception_non_suppressing.<locals>.suppress_exccSsdS)Nrrrrr
r�lszCTestExitStack.test_exit_exception_non_suppressing.<locals>.<lambda>z0Expected IndexError, but no exception was raisedz.Expected KeyError, but no exception was raised)r�r�r��	Exceptionr�r�r�r�)rr�r�r�rbrrr
�#test_exit_exception_non_suppressingbs"#

#z1TestExitStack.test_exit_exception_non_suppressingcCs.tdd��}td�}td�}td�}td�}yUt��F}|j||��|j||��|j||��|�WdQXWn�tk
r)}zp|j||�|j|j|�|j|jj|�|j|jjj|�|j|jjjj�WYdd}~XnXdS)Nc
ssz	dVWd|�XdS)Nr)rbrrr
�gets_the_context_rights	zVTestExitStack.test_exit_exception_with_correct_context.<locals>.gets_the_context_rightrrvr�r�)rr�r�r�rer�rm)rr��exc1�exc2�exc3�exc4r�rbrrr
�(test_exit_exception_with_correct_context}s$z6TestExitStack.test_exit_exception_with_correct_contextc	Cs@dd�}td�}td�}td�}td�}td�}yBt��3}|j|||�|j|||�|�WdQXWn�tk
r;}z�|j||�|j|j|�|j|jj|�|j|jjj|�|j|jjjj|�|j|jjjjj�WYdd}~XnXdS)Nc
Ssz
|�Wd|�XdS)Nr)r�Z	outer_excrrr
�raise_nested�s
zMTestExitStack.test_exit_exception_with_existing_context.<locals>.raise_nestedrrvr�r��)r�r�r�rer�rm)	rr�r�r�r�r�Zexc5r�rbrrr
�)test_exit_exception_with_existing_context�s(z7TestExitStack.test_exit_exception_with_existing_contextcCspdd�}y+t��}|j|�ddWdQXWn2tk
rk}z|jd�WYdd}~XnXdS)NcWsdS)NTr)r�rrr
r��sz@TestExitStack.test_body_exception_suppress.<locals>.suppress_excrrz%Expected no exception, got IndexError)r�r�r�r�)rr�r�rbrrr
�test_body_exception_suppress�s
z*TestExitStack.test_body_exception_suppressc
CsOt��@}|jdd��|jdd��|jdd��WdQXdS)NcWsdS)NTr)rbrrr
r��szETestExitStack.test_exit_exception_chaining_suppress.<locals>.<lambda>cWsddS)Nrrr)rbrrr
r��scWsidS)Nrr)rbrrr
r��s)r�r�)rr�rrr
�%test_exit_exception_chaining_suppress�sz3TestExitStack.test_exit_exception_chaining_suppressc
Cs:t��+}x!td�D]}|jt�qWWdQXdS)Ni')r��ranger��int)rr��irrr
�test_excessive_nesting�sz$TestExitStack.test_excessive_nestingcCsrGdd�dt�}|�}t�|_t�}|jt|j|�|j|�|j|jd|�dS)Nc@seZdZdS)z3TestExitStack.test_instance_bypass.<locals>.ExampleN)r-r9r:rrrr
�Example�sr�rr�)	rwrr�rr{r�r�rer�)rr�r�r�rrr
�test_instance_bypass�s		
z"TestExitStack.test_instance_bypassN)r-r9r:rr;r@r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr
r��s$"
0
r�c@saeZdZejdd��Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
S)�TestRedirectStdoutcCs,tj}td�}|j|j|�dS)N)�redirect_stdoutr/r
)rr>r?rrr
r@�s	z%TestRedirectStdout.test_instance_docscCs*tj}td�|jtj|�dS)N)�sys�stdoutr�re)r�orig_stdoutrrr
�test_no_redirect_in_init�s	
z+TestRedirectStdout.test_no_redirect_in_initc	Csqtj�}d}tj}t|��t|�WdQX|jtj|�|j�j�}|j	||�dS)Nz<Consider an API like help(), which prints directly to stdout)
�io�StringIOr�r�r��printre�getvalue�stripr
)rrP�msgr��srrr
�test_redirect_to_string_io�s	
z-TestRedirectStdout.test_redirect_to_string_ioc
Cs5tj�}t|��}|j||�WdQXdS)N)r�r�r�re)rrP�enter_resultrrr
�test_enter_result_is_target�sz.TestRedirectStdout.test_enter_result_is_targetcCs�tj�}t|�}tj}|�tddd�WdQX|�td�WdQX|jtj|�|j�}|j|d�dS)N�Hello�end� zWorld!z
Hello World!
)	r�r�r�r�r�r�rer�r
)rrP�
write_to_fr�r�rrr
�test_cm_is_reusable�s	z&TestRedirectStdout.test_cm_is_reusablecCs�tj�}t|�}tj}|�,tddd�|�td�WdQXWdQX|jtj|�|j�}|j|d�dS)Nr�r�r�zWorld!z
Hello World!
)	r�r�r�r�r�r�rer�r
)rrPr�r�r�rrr
�test_cm_is_reentrants	z'TestRedirectStdout.test_cm_is_reentrantN)r-r9r:rr;r@r�r�r�r�r�rrrr
r��s
r�c@s�eZdZejdd��Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dS)�TestSuppresscCs)tj}t�}|j|j|�dS)N)�suppressr/r
)rr>r?rrr
r@s		zTestSuppress.test_instance_docsc	Cs&tt��}|j|�WdQXdS)N)r�r�rm)rr�rrr
�test_no_result_from_entersz&TestSuppress.test_no_result_from_entercCs0tt��|jtdd�d�WdQXdS)Nrvr�� )r�r�r
�pow)rrrr
�test_no_exceptions
zTestSuppress.test_no_exceptionc	Cs!tt��td�WdQXdS)Nr�)r�r�len)rrrr
�test_exact_exception s
z!TestSuppress.test_exact_exceptionc	Cstt��
ddWdQXdS)Nr��2)r��LookupError)rrrr
�test_exception_hierarchy$s
z%TestSuppress.test_exception_hierarchycCs5|jt�� tt��
ddWdQXWdQXdS)Nrr)rrr�r)rrrr
�test_other_exception(s
z!TestSuppress.test_other_exceptioncCs2|jt��t��
ddWdQXWdQXdS)Nrr)rrr�)rrrr
�test_no_args-s
zTestSuppress.test_no_argscCsBttt��
ddWdQXttt��td�WdQXdS)Nrrr�)r�rrr�)rrrr
�test_multiple_exception_args2sz)TestSuppress.test_multiple_exception_argscCsstt�}|�WdQX|�td�WdQX|�*|�td�WdQXd}ddWdQX|j|�dS)Nr�Trr)r�r�r�rM)rZignore_exceptionsZouter_continuedrrr
r�8sz!TestSuppress.test_cm_is_reentrantN)r-r9r:rr;r@r�r�r�r�r�r�r�r�rrrr
r�sr��__main__)r/r�r�rIZunittest�
contextlibrnrrV�ImportErrorZTestCaserr<rFZ
skipUnlessrRrzr`rdr�r�r�r-�mainrrrr
�<module>s.

l!0��J66