a ze@sRddlZddlZddlZddlZddlZddlTddlmZddlZGdddej Z Gdddej Z Gdd d ej Z Gd d d ej Z Gd d d ej ZGdddej ZGdddeZGdddej ZGdddZGdddeej ZGdddZGdddeej ZGdddeej ZGdddej Zed krNedS)!N)*)supportc@s$eZdZddZddZddZdS)TestAbstractContextManagercCs*Gdddt}|}|||dS)NcseZdZfddZZS)z;TestAbstractContextManager.test_enter..DefaultEntercstj|dSNsuper__exit__selfargs __class__H/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_contextlib.pyrszDTestAbstractContextManager.test_enter..DefaultEnter.__exit____name__ __module__ __qualname__r __classcell__rrr r DefaultEntersr)AbstractContextManagerassertIs __enter__)r rmanagerrrr test_entersz%TestAbstractContextManager.test_entercCsDGdddt}|t|Wdn1s60YdS)Nc@s eZdZdS)zETestAbstractContextManager.test_exit_is_abstract..MissingExitNrrrrrrr MissingExitsr)r assertRaises TypeError)r rrrrtest_exit_is_abstracts z0TestAbstractContextManager.test_exit_is_abstractcCsGddd}|t|tGdddt}|t|tGddd|}|t|tGddd|}|t|tdS) Nc@seZdZddZddZdS)zRTestAbstractContextManager.test_structural_subclassing..ManagerFromScratchcSs|Srrr rrrr sz\TestAbstractContextManager.test_structural_subclassing..ManagerFromScratch.__enter__cSsdSrr)r exc_type exc_value tracebackrrrr"sz[TestAbstractContextManager.test_structural_subclassing..ManagerFromScratch.__exit__NrrrrrrrrrManagerFromScratchsr%cseZdZfddZZS)zLTestAbstractContextManager.test_structural_subclassing..DefaultEntercstj|dSrrr r rrr(szUTestAbstractContextManager.test_structural_subclassing..DefaultEnter.__exit__rrrr rr'src@seZdZdZdS)zGTestAbstractContextManager.test_structural_subclassing..NoEnterN)rrrrrrrrNoEnter-sr&c@seZdZdZdS)zFTestAbstractContextManager.test_structural_subclassing..NoExitN)rrrrrrrrNoExit2sr') assertTrue issubclassr assertFalse)r r%rr&r'rrrtest_structural_subclassingsz6TestAbstractContextManager.test_structural_subclassingN)rrrrrr+rrrrr src@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ e jddZe jddZddZddZddZdd Zd!S)"ContextManagerTestCasecsrgtfdd}|4}|dg||d|Wdn1sT0Y|gddS)Nc3sddVddSN*appendrstaterrwoohoo<s z@ContextManagerTestCase.test_contextmanager_plain..woohoor.r/r.r/r0)contextmanager assertEqualr2r r5xrr3rtest_contextmanager_plain:s (z0ContextManagerTestCase.test_contextmanager_plainc sgtfdd}|t`|:}|dg||d|tWdn1sf0YWdn1s0Y|gddS)Nc 3s0dzdVWdn d0dSr-r1rr3rrr5Is zBContextManagerTestCase.test_contextmanager_finally..woohoor.r/r6)r7rZeroDivisionErrorr8r2r9rr3rtest_contextmanager_finallyGs   Bz2ContextManagerTestCase.test_contextmanager_finallycCs6tdd}|}|||ttdddS)Ncss dVdSrrrrrrwheeYszCContextManagerTestCase.test_contextmanager_no_reraise..wheefoo)r7rr*rr)r r>ctxrrrtest_contextmanager_no_reraiseXs  z5ContextManagerTestCase.test_contextmanager_no_reraisecCs6tdd}|}||t|jttdddS)Ncss"z dVWndVYn0dSrrrrrrwhoobs zOContextManagerTestCase.test_contextmanager_trap_yield_after_throw..whoor?)r7rr RuntimeErrorrr)r rBr@rrr*test_contextmanager_trap_yield_after_throwas zAContextManagerTestCase.test_contextmanager_trap_yield_after_throwcs|gtfdd}|<}dg|d|tdWdn1s^0YgddS)Nc 3s^dz dVWnDtyX}z,|jdgdWYd}~n d}~00dS)Nr.r/rr6)r2r<r r8)er r4rrr5ps   zAContextManagerTestCase.test_contextmanager_except..woohoor.r/r0r6)r7r8r2r<r9rrFrtest_contextmanager_exceptns  &z1ContextManagerTestCase.test_contextmanager_exceptc Cstdd}Gdddt}td|dfD]}|jt|dz.||Wdn1sd0YWn0ty}z|||WYd}~nd}~00||dWdq,1s0Yq,dS)Ncss dVdSrrrrrrr5szJContextManagerTestCase.test_contextmanager_except_stopiter..woohooc@s eZdZdS)zYContextManagerTestCase.test_contextmanager_except_stopiter..StopIterationSubclassNrrrrrStopIterationSubclasssrHspam)typez was suppressed)r7 StopIterationsubTestrJ Exceptionrfail)r r5rHstop_excexrrr#test_contextmanager_except_stopiters &"z:ContextManagerTestCase.test_contextmanager_except_stopiterc Csd}i}t||||d}td}z.||Wdn1sF0YWn0ty}z|||WYd}~nd}~00|ddS)Nztfrom __future__ import generator_stop from contextlib import contextmanager @contextmanager def woohoo(): yield r5rIzStopIteration was suppressed)execrKrMrrN)r codelocalsr5rOrPrrr!test_contextmanager_except_pep479s &"z8ContextManagerTestCase.test_contextmanager_except_pep479c Cstdd}z.|tWdn1s.0YWnTty}z<|t|t||jdd||j tWYd}~n d}~00z2|t dWdn1s0YWnTty}z:|t|t ||jdd| |j WYd}~n d}~00dS)Nc ss>z dVWn.ty8}ztd|WYd}~n d}~00dS)Nissue29692:Chained)rMrCexcrrrtest_issue29692s zoContextManagerTestCase.test_contextmanager_do_not_unchain_non_stopiteration_exceptions..test_issue29692rrVzissue29692:Unchained) r7r<rMrrJrCr8r assertIsInstance __cause__rK assertIsNone)r rYrPrrr?test_contextmanager_do_not_unchain_non_stopiteration_exceptionss  &$*zVContextManagerTestCase.test_contextmanager_do_not_unchain_non_stopiteration_exceptionscCs"dd}t|dddd}|S)Ncsfdd}|S)Ncs"D]\}}t|||q|Sr)itemssetattr)funckvkwrrdecorateszXContextManagerTestCase._create_contextmanager_attribs..attribs..decorater)rdrerrcrattribss zFContextManagerTestCase._create_contextmanager_attribs..attribsbar)r?cSsdSrr)rIrrrbazszBContextManagerTestCase._create_contextmanager_attribs..bazr7)r rfrhrrr_create_contextmanager_attribss  z5ContextManagerTestCase._create_contextmanager_attribscCs(|}||jd||jddS)Nrhrg)rjr8rr?r rhrrrtest_contextmanager_attribssz2ContextManagerTestCase.test_contextmanager_attribscCs|}||jddSNzWhee!rjr8__doc__rkrrrtest_contextmanager_doc_attribsz5ContextManagerTestCase.test_contextmanager_doc_attribcCs|d}||jddSrmrnrkrrr*test_instance_docstring_given_cm_docstrings zAContextManagerTestCase.test_instance_docstring_given_cm_docstringcCsLtdd}|ddddd}||dWdn1s>0YdS) Ncss||||fVdSrrr r`r kwdsrrrr5sz4ContextManagerTestCase.test_keywords..woohoo !,rr)rtrurvrwr7r8)r r5targetrrr test_keywordss z$ContextManagerTestCase.test_keywordscsRGddd}tfdd}|||dWdn1sD0YdS)Nc@s eZdZdS)z0ContextManagerTestCase.test_nokeepref..ANrrrrrAsr{c3s6t|}t|}||dVdSr)weakrefrefr\abr rrr5s     z5ContextManagerTestCase.test_nokeepref..woohoorri)r r{r5rr rtest_nokeeprefs z%ContextManagerTestCase.test_nokeeprefcCstdd}|t|Wdn1s20Y|t|ddWdn1sf0Y|t|ddWdn1s0YdS)Ncss dVdSrrr~rrrr5sz8ContextManagerTestCase.test_param_errors..woohoor)r7rrr r5rrrtest_param_errorss  $ ( z(ContextManagerTestCase.test_param_errorscs@dtfdd}|fddddS)Nrc3s*}d7dVd8|dSNr.)r8)before)depthr rrr5s z5ContextManagerTestCase.test_recursive..woohoocsdkrdS)N rr)r recursiverrrsz8ContextManagerTestCase.test_recursive..recursiverxrr)rrr rtest_recursivesz%ContextManagerTestCase.test_recursiveN)rrrr;r=rArDrGrQrUr]rjrlrrequires_docstringsrprqrzrrrrrrrr,8s$       r,c@s*eZdZejddZddZddZdS)ClosingTestCasecCs tj}td}||j|dSr)closingror8r Z cm_docstringobjrrrtest_instance_docssz"ClosingTestCase.test_instance_docscsngGfddd}|}|gt|}|||Wdn1sR0Y|dgdS)NcseZdZfddZdS)z'ClosingTestCase.test_closing..CcsddSrr1r r3rrclosesz-ClosingTestCase.test_closing..C.closeNrrrrrr3rrCsrr.)r8rr rr:yrr3r test_closings  *zClosingTestCase.test_closingc sgGfddd}|}|g|tLt|$}|||ddWdn1sf0YWdn1s0Y|dgdS)NcseZdZfddZdS)z-ClosingTestCase.test_closing_error..CcsddSrr1r r3rrr'sz3ClosingTestCase.test_closing_error..C.closeNrrr3rrr&srr.r)r8rr<rrrr3rtest_closing_error$s    Dz"ClosingTestCase.test_closing_errorN)rrrrrrrrrrrrrs  rc@seZdZddZdS)NullcontextTestCasecCsLGddd}|}t|}|||Wdn1s>0YdS)Nc@s eZdZdS)z/NullcontextTestCase.test_nullcontext..CNrrrrrr4sr) nullcontextr)r rcZc_inrrrtest_nullcontext3s z$NullcontextTestCase.test_nullcontextN)rrrrrrrrr2src@seZdZddZdS)FileContextTestCasec Cst}zd}t|d&}||j|dWdn1sD0Y||jd}|t^t|d4}||j| | dddWdn1s0YWdn1s0Y||jWt |n t |0dS)NwzBooh rr.r) tempfilemktempopenr*closedwriter(rr<r8readrunlink)r Ztfnfrrr testWithOpen=s  (    Dz FileContextTestCase.testWithOpenN)rrrrrrrrr;src@s<eZdZddZddZddZddZd d Zd d Zd S)LockContextTestCasec Cs|||||Wdn1s20Y|||tH|$||ddWdn1s0YWdn1s0Y||dSNr.r)r*r(rr<)r locklockedrrr boilerPlateQs *   DzLockContextTestCase.boilerPlatecCst}|||jdSr) threadingLockrrr rrrr testWithLock\sz LockContextTestCase.testWithLockcCst}|||jdSr)rRLockr _is_ownedrrrr testWithRLock`sz!LockContextTestCase.testWithRLockcs$tfdd}||dS)NcsSr)rrrrrrfsz5LockContextTestCase.testWithCondition..locked)r Conditionrr rrrrtestWithConditionds z%LockContextTestCase.testWithConditioncs$tfdd}||dS)NcsdrdSdSdSNFTacquirereleaserrrrrls z5LockContextTestCase.testWithSemaphore..locked)r SemaphorerrrrrtestWithSemaphorejs z%LockContextTestCase.testWithSemaphorecs$tfdd}||dS)NcsdrdSdSdSrrrrrrrvs z.locked)rBoundedSemaphorerrrrrtestWithBoundedSemaphorets z,LockContextTestCase.testWithBoundedSemaphoreN) rrrrrrrrrrrrrrOs   rc@s(eZdZdZdZdZddZddZdS) mycontextFNcCs d|_|SNTstartedr rrrrszmycontext.__enter__cGs ||_|jSr)rXcatchr rXrrrrszmycontext.__exit__)rrrrrXrrrrrrrrs rc@sbeZdZejddZddZddZddZd d Z d d Z d dZ ddZ ddZ ddZdS)TestContextDecoratorcCstj}t}||j|dSr)rror8rrrrrsz'TestContextDecorator.test_instance_docscCsTt}|(}|||||jWdn1s80Y||jddS)NNNN)rrr(rr8rX)r contextresultrrrtest_contextdecorators  *z*TestContextDecorator.test_contextdecoratorc Cst}|td<|tdWdn1s60YWdn1sT0Y||j||jdtt}d|_|tdWdn1s0Y||j||jdtdS)Nr?rT)rassertRaisesRegex NameErrorassertIsNotNonerXrr)r rrrr$test_contextdecorator_with_exceptionsD & z9TestContextDecorator.test_contextdecorator_with_exceptioncs0tfdd}|jddS)NcsjjdSrr\rXr(rrrr rrtests z1TestContextDecorator.test_decorator..testr)rr8rXr rrrrtest_decorators z#TestContextDecorator.test_decoratorcsltfdd}td|Wdn1s@0YjjdtdS)Ncs$jjtddS)Nr?)r\rXr(rrrrrrrs  z@TestContextDecorator.test_decorator_with_exception..testr?r)rrrrrXrrrrrtest_decorator_with_exceptions$ z2TestContextDecorator.test_decorator_with_exceptioncstGfdddt}|}|dd||jd||jd||jd|}|ddd||jd||jd||jd|}|jddd||jd||jddS) NcseZdZdddZdS)z9TestContextDecorator.test_decorating_method..TestNcSs||_||_||_dSr)rrr)r rrrrrrmethodsz@TestContextDecorator.test_decorating_method..Test.method)N)rrrrrrrrTestsrr.rrrr~)robjectrr8rrr)r rrrrrtest_decorating_methods   z+TestContextDecorator.test_decorating_methodc CsdGdddt}|t6|Wdn1s80YWdn1sV0YdS)Nc@seZdZddZddZdS)z7TestContextDecorator.test_typo_enter..mycontextcSsdSrrr rrr __unter__szATestContextDecorator.test_typo_enter..mycontext.__unter__cWsdSrrrrrrrsz@TestContextDecorator.test_typo_enter..mycontext.__exit__N)rrrrrrrrrrsrContextDecoratorrAttributeErrorr rrrrtest_typo_enters z$TestContextDecorator.test_typo_enterc CsdGdddt}|t6|Wdn1s80YWdn1sV0YdS)Nc@seZdZddZddZdS)z6TestContextDecorator.test_typo_exit..mycontextcSsdSrrr rrrrsz@TestContextDecorator.test_typo_exit..mycontext.__enter__cWsdSrrrrrr__uxit__sz?TestContextDecorator.test_typo_exit..mycontext.__uxit__N)rrrrrrrrrrsrrrrrrtest_typo_exits z#TestContextDecorator.test_typo_exitcsRGdddt}Gddd|t}|fdd}|jddS)Nc@s$eZdZdZdZddZddZdS)zHTestContextDecorator.test_contextdecorator_as_mixin..somecontextFNcSs d|_|Srrr rrrrszRTestContextDecorator.test_contextdecorator_as_mixin..somecontext.__enter__cWs ||_dSrrWrrrrr szQTestContextDecorator.test_contextdecorator_as_mixin..somecontext.__exit__)rrrrrXrrrrrr somecontextsrc@s eZdZdS)zFTestContextDecorator.test_contextdecorator_as_mixin..mycontextNrrrrrr srcsjjdSrrrrrrrs zATestContextDecorator.test_contextdecorator_as_mixin..testr)rrr8rX)r rrrrrrtest_contextdecorator_as_mixins z3TestContextDecorator.test_contextdecorator_as_mixincsbtfdd}g|dfdd}|dgdg|dgd dS) Nc3s|dVddS)Nr0r1)rr3rrr5s zETestContextDecorator.test_contextmanager_as_decorator..woohoor.csdg|dSr)r8r2)r:rFrrr!szCTestContextDecorator.test_contextmanager_as_decorator..test something)r.rr0something else)r.rr0rx)r r5rrrFr test_contextmanager_as_decoratorsz5TestContextDecorator.test_contextmanager_as_decoratorN)rrrrrrrrrrrrrrrrrrrrs     rc@seZdZdZejddZddZddZdd Z d d Z d d Z ddZ ddZ ddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)ZdS)*TestBaseExitStackNcCs"|jj}|}||j|dSr) exit_stackror8rrrrr1sz$TestBaseExitStack.test_instance_docscCs,|Wdn1s0YdSr)rr rrrtest_no_resources8s z#TestBaseExitStack.test_no_resourcesc s8difdifdifdtddfdtddfdtddfdtdddfg}gfd 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 qWdn1s80Y| |g|}| t |jdd Wdn1s0Y| t |jjd d Wdn1s0Y| t |j|dd Wdn1s0YWdn1s0Y| gdS)Nr)r.)r.rr.)Zexampler)r callbackcs||fdSrr1)r rsrrr_exitGsz.TestBaseExitStack.test_callback.._exit)argr)rr)dictrreversedrr_exit_callbacks __wrapped__ZassertNotEqualrr\ror8rr)r Zexpectedrstackr rsrwrapperrrr test_callback<sD        6   , . NzTestBaseExitStack.test_callbackcs@tfdd}dd}fdd}Gdddt}}|||jd d |||}|||jd d j||||jd d |||}|||jd d j||||jd d ||||jd d |d d Wdn1s20YdS) Ncs|dSr)rr!rXexc_tbZ exc_raisedr rr _expect_excgsz0TestBaseExitStack.test_push.._expect_exccWsdSrr exc_detailsrrr _suppress_excisz2TestBaseExitStack.test_push.._suppress_exccs"|||dSr)r\rr rr _expect_okks  z/TestBaseExitStack.test_push.._expect_okc@s$eZdZddZddZddZdS)z+TestBaseExitStack.test_push..ExitCMcSs ||_dSr check_exc)r rrrr__init__psz4TestBaseExitStack.test_push..ExitCM.__init__cSs|ddS)NzShould not be called!)rNr rrrrrsz5TestBaseExitStack.test_push..ExitCM.__enter__cWs|j|dSrrr rrrrrtsz4TestBaseExitStack.test_push..ExitCM.__exit__NrrrrrrrrrrExitCMosrr.r)r<rrpushrr__self__)r rrrrrcmrrr test_pushes*        zTestBaseExitStack.test_pushcsGfdddt}g|}|X}|jfdd}||||||jddj|dWdn1s0Y| gddS) Ncs$eZdZfddZfddZdS)z4TestBaseExitStack.test_enter_context..TestCMcsddSrr1r rrrrsz>TestBaseExitStack.test_enter_context..TestCM.__enter__csddSNrr1rrrrrsz=TestBaseExitStack.test_enter_context..TestCM.__exit__Nr$rrrrTestCMs r csddS)Nrr1rrrrrsz3TestBaseExitStack.test_enter_context.._exitrr.r)r.rrr) rrrr enter_contextrrr r2r8)r r r rrrrrtest_enter_contexts   (z$TestBaseExitStack.test_enter_contextcsng|>}|jfdd}|||dWdn1sP0Y|ddgdS)NcsddSrr1rrrrrsz+TestBaseExitStack.test_close.._exitrr.)rrrrr2r8)r rrrrr test_closes  (zTestBaseExitStack.test_closecsg|>}|jfdd}|||}dWdn1sP0Yd||gddS)NcsddSr r1rrrrrsz-TestBaseExitStack.test_pop_all.._exitr.r)r.rr)rrrpop_allr2rr8)r rr new_stackrrr test_pop_alls  ( zTestBaseExitStack.test_pop_allc Csl|tN|&}|ddddWdn1s@0YWdn1s^0YdS)NcWsdS)NFrrWrrrz3TestBaseExitStack.test_exit_raise..r.r)rr<rrr rrrrtest_exit_raises  z!TestBaseExitStack.test_exit_raisecCsB|&}|ddddWdn1s40YdS)NcWsdSrrrWrrrrrz6TestBaseExitStack.test_exit_suppress..r.rrrrrrrtest_exit_suppresss z$TestBaseExitStack.test_exit_suppressc Cs^Gddd}Gddd}Gddd}z|t|ttf|@|tddWdn1sp0YWdn1s0YWdn1s0YWdn1s0YWnTty*}z:||jt||jjt||jjjWYd}~nd}~00|d |jd}||t||jt dS) Nc@s$eZdZddZddZddZdS)zJTestBaseExitStack.test_exit_exception_chaining_reference..RaiseExccSs ||_dSrrWrrrrrszSTestBaseExitStack.test_exit_exception_chaining_reference..RaiseExc.__init__cSs|Srrr rrrrszTTestBaseExitStack.test_exit_exception_chaining_reference..RaiseExc.__enter__cWs |jdSrrWrrrrrszSTestBaseExitStack.test_exit_exception_chaining_reference..RaiseExc.__exit__NrrrrrRaiseExcsrc@s$eZdZddZddZddZdS)zUTestBaseExitStack.test_exit_exception_chaining_reference..RaiseExcWithContextcSs||_||_dSr)outerinner)r rrrrrrsz^TestBaseExitStack.test_exit_exception_chaining_reference..RaiseExcWithContext.__init__cSs|Srrr rrrrsz_TestBaseExitStack.test_exit_exception_chaining_reference..RaiseExcWithContext.__enter__cWs"z |jWn|jYn0dSr)rrrrrrrs z^TestBaseExitStack.test_exit_exception_chaining_reference..RaiseExcWithContext.__exit__NrrrrrRaiseExcWithContextsrc@seZdZddZddZdS)zMTestBaseExitStack.test_exit_exception_chaining_reference..SuppressExccSs|Srrr rrrrszWTestBaseExitStack.test_exit_exception_chaining_reference..SuppressExc.__enter__cWs|t|_dSr)rJ saved_detailsrrrrrs zVTestBaseExitStack.test_exit_exception_chaining_reference..SuppressExc.__exit__Nr$rrrr SuppressExcsrr.r0Expected IndexError, but no exception was raised) IndexErrorKeyErrorr ValueErrorrZ __context__r\rNrr<)r rrrrX inner_excrrr&test_exit_exception_chaining_references"    &   z8TestBaseExitStack.test_exit_exception_chaining_referencec s dd}dfdd}zn|R}||t||t||t||||tddWdn1sz0YWnRty}z:||jt||jjt| |jjjWYd}~nd}~00| dd}||t||jt dS)NcSs|dSrrrWrrr raise_excszATestBaseExitStack.test_exit_exception_chaining..raise_exccs|dSrrrrrr suppress_excszDTestBaseExitStack.test_exit_exception_chaining..suppress_excr.rr ) rrr!r"rrr#rZr$r\rNr<)r r'r)rrXr%rr(rtest_exit_exception_chainings&       *&  z.TestBaseExitStack.test_exit_exception_chainingc sGdddttfddtfdd}|fD]}|z0|tWdn1sl0YWn0y}z|jWYd}~nd}~00dWdq:1s0Yq:dS)Nc@s eZdZdS)zPTestBaseExitStack.test_exit_exception_explicit_none_context..MyExceptionNrrrrr MyExceptionsr+c 3s@z dVWn0ty:}z|Wd|_nd|_0Yn0dSr) BaseExceptionr$rW)r+rrmy_cms  zJTestBaseExitStack.test_exit_exception_explicit_none_context..my_cmc3s>"}||VWdn1s00YdSr)rr)r)r-r rrmy_cm_with_exit_stacks  zZTestBaseExitStack.test_exit_exception_explicit_none_context..my_cm_with_exit_stackr )rMr7rLr!r\r$rN)r r.r rXr)r+r-r r)test_exit_exception_explicit_none_context s   ("z;TestBaseExitStack.test_exit_exception_explicit_none_contextc Cs"dd}dd}zF|*}|dd||tWdn1sJ0YWn0ty}z||tWYd}~nd}~00|dzN|2}||t||||tWdn1s0YWn2ty}z||tWYd}~nd}~00|ddS) NcSs|dSrrrWrrrr'0szHTestBaseExitStack.test_exit_exception_non_suppressing..raise_exccWsdSrrrrrrr)3szKTestBaseExitStack.test_exit_exception_non_suppressing..suppress_exccSsdSrrrrrrr8rzGTestBaseExitStack.test_exit_exception_non_suppressing..r z.Expected KeyError, but no exception was raised)rrr!rMrZrNr"r)r r'r)rrXrrr#test_exit_exception_non_suppressing.s" ."    ."z5TestBaseExitStack.test_exit_exception_non_suppressingc Cstdd}td}td}td}td}zZ|>}||||||||||Wdn1sz0YWnrty}zZ|||||j|||jj|||jjj|||jjjjWYd}~n d}~00dS)NcsszdVW|n|0dSrrrWrrrgets_the_context_rightKszZTestBaseExitStack.test_exit_exception_with_correct_context..gets_the_context_rightr.rrr)r7rMrrrr$r\)r r1exc1exc2exc3exc4rrXrrr(test_exit_exception_with_correct_contextIs(  &  z:TestBaseExitStack.test_exit_exception_with_correct_contextc Cs dd}td}td}td}td}td}zL|0}|||||||||Wdn1sp0YWnty}zp|||||j|||jj|||jjj|||jjjj|||jjjjjWYd}~n d}~00dS)NcSsz |W|n|0dSrr)r%Z outer_excrrr raise_nestedkszQTestBaseExitStack.test_exit_exception_with_existing_context..raise_nestedr.rrrr)rMrrrr$r\) r r7r2r3r4r5Zexc5rrXrrr)test_exit_exception_with_existing_contexths, &   z;TestBaseExitStack.test_exit_exception_with_existing_contextc Cszdd}z>|"}||ddWdn1s:0YWn.tyt}z|dWYd}~n d}~00dS)NcWsdSrrrrrrr)szDTestBaseExitStack.test_body_exception_suppress..suppress_excr.rz%Expected no exception, got IndexError)rrr!rN)r r)rrXrrrtest_body_exception_suppresss  *z.TestBaseExitStack.test_body_exception_suppresscCsV|:}|dd|dd|ddWdn1sH0YdS)NcWsdSrrrWrrrrrzITestBaseExitStack.test_exit_exception_chaining_suppress..cWsddSrrrWrrrrrcWsidSrrrWrrrrrrrrrr%test_exit_exception_chaining_suppresss z7TestBaseExitStack.test_exit_exception_chaining_suppresscCsD|(}tdD]}|tqWdn1s60YdS)Ni')rrangerint)r rirrrtest_excessive_nestings  z(TestBaseExitStack.test_excessive_nestingcCsZGdddt}|}t|_|}|t|j|||||jdd|dS)Nc@s eZdZdS)z7TestBaseExitStack.test_instance_bypass..ExampleNrrrrrExamplerr?rr.) rrrrrrrrr)r r?r rrrrtest_instance_bypasss z&TestBaseExitStack.test_instance_bypassc sGdddtGdddt}tfdd}tdd}|X}|0}|||||d Wdn1s0YWdn1s0Y|j}||||j|| |jj| |jj | |j |jdS) Nc@s eZdZdS)zITestBaseExitStack.test_dont_reraise_RuntimeError..UniqueExceptionNrrrrrUniqueExceptionrrAc@s eZdZdS)zLTestBaseExitStack.test_dont_reraise_RuntimeError..UniqueRuntimeErrorNrrrrrUniqueRuntimeErrorrrBc 3s>z dVWn.ty8}zd|WYd}~n d}~00dS)Nr.z new exceptionrMrWrArrseconds z@TestBaseExitStack.test_dont_reraise_RuntimeError..secondc ss8z dVWn(ty2}z|WYd}~n d}~00dSrrCrWrrrfirsts z?TestBaseExitStack.test_dont_reraise_RuntimeError..firstzplease no infinite loop.) rMrCr7rrr exceptionrZr$r\r[r)r rBrErFZerr_ctxZes_ctxrXrrDrtest_dont_reraise_RuntimeErrors"     D z0TestBaseExitStack.test_dont_reraise_RuntimeError)rrrrrrrrrr rrrrrr&r*r/r0r6r8r9r:r>r@rHrrrrr.s, )"  0"  rc@seZdZeZdS) TestExitStackN)rrr ExitStackrrrrrrIsrIc@sJeZdZdZdZejddZddZddZ dd Z d d Z d d Z dS)TestRedirectStreamNcCs$|jj}|d}||j|dSr)redirect_streamror8rrrrrs z%TestRedirectStream.test_instance_docscCs.tt|j}|d|tt|j|dSr)getattrsys orig_streamrLr)r orig_stdoutrrrtest_no_redirect_in_inits  z+TestRedirectStream.test_no_redirect_in_initcCst}d}tt|j}||$t|tt|jdWdn1sL0Y|tt|j|| }| ||dS)Nztt"|tdddWdn1s00YdS)Nrr )rmr#r8powr rrrtest_no_exceptions zTestSuppress.test_no_exceptioncCs4tttdWdn1s&0YdS)Nr)rmrlenr rrrtest_exact_exception s z!TestSuppress.test_exact_exceptioncCs4ttddWdn1s&0YdS)Nr_2)rm LookupErrorr rrrtest_exception_hierarchy$s z%TestSuppress.test_exception_hierarchyc Cs^|t@ttddWdn1s20YWdn1sP0YdSr)rr<rmrr rrrtest_other_exception(s  z!TestSuppress.test_other_exceptionc Cs\|t>tddWdn1s00YWdn1sN0YdSr)rr<rmr rrr test_no_args-s zTestSuppress.test_no_argscCshtttddWdn1s(0YttttdWdn1sZ0YdS)Nr.rr)rmr<rrrr rrrtest_multiple_exception_args2s & z)TestSuppress.test_multiple_exception_argsc Cstt}|Wdn1s"0Y|tdWdn1sN0Y|H|tdWdn1s0Yd}ddWdn1s0Y||dS)NrTr.r)rmrMrrr()r Zignore_exceptionsZouter_continuedrrrre8s&&&z!TestSuppress.test_cm_is_reentrantN)rrrrrrrnrqrsrvrwrxryrerrrrrls rl__main__)rTrNrrZunittest contextlibrrr|ZTestCaserr,rrrrrrrrrIrKrfrirlrmainrrrrs8 +Y" 0!96