
    dafh                     H   d Z dZdZddlZddlZddlmZ ddlmZm	Z	m
Z
  G d de      Zd	 Z G d
 de      Zed        Z G d de      Z G d de      Z G d dej$                        Z G d de      Z G d dej$                  e      Z G d dej$                  e      Z G d deej$                        Z G d dej$                        Z G d dej$                        Z G d d ej$                        Z G d! d"ej$                        Zed#k(  r ej:                          yy)$z7Unit tests for the with statement specified in PEP 343.z
Mike Blandzmbland at acm dot org    N)deque)_GeneratorContextManagercontextmanagernullcontextc                   *     e Zd Z fdZd Zd Z xZS )MockContextManagerc                 H    t        |   |  d| _        d| _        d | _        y NF)super__init__enter_calledexit_called	exit_args)selfargs	__class__s     )/root/Python-3.12.4/Lib/test/test_with.pyr   zMockContextManager.__init__   s'    $!     c                 :    d| _         t        j                  |       S NT)r   r   	__enter__r   s    r   r   zMockContextManager.__enter__   s     '11$77r   c                 T    d| _         |||f| _        t        j                  | |||      S r   )r   r   r   __exit__r   typevalue	tracebacks       r   r   zMockContextManager.__exit__   s6    y1'00t16	C 	Cr   )__name__
__module____qualname__r   r   r   __classcell__)r   s   @r   r   r      s    8Cr   r   c                       fd}|S )Nc                      t        | |      S N)r   )r   kwdsfuncs     r   helperz#mock_contextmanager.<locals>.helper    s    !$d33r    )r'   r(   s   ` r   mock_contextmanagerr*      s    4Mr   c                       e Zd Zd Zy)MockResourcec                      d| _         d| _        y r
   )yieldedstoppedr   s    r   r   zMockResource.__init__&   s    r   Nr   r    r!   r   r)   r   r   r,   r,   %   s    r   r,   c               #   ^   K   t               } 	 d| _        |  d| _        y # d| _        w xY wwr   )r,   r.   r/   )mocks    r   mock_contextmanager_generatorr3   +   s,     >D
ts   -! -	*-c                       e Zd Zd Zd Zd Zy)Nestedc                      || _         d | _        y r%   )managersenteredr   r7   s     r   r   zNested.__init__7   s     r   c                 D   | j                   t        d      t               | _         g }	 | j                  D ]<  }|j	                  |j                                | j                   j                  |       > 	 |S #   | j                  t        j                          s Y |S xY w)NzContext is not reentrant)
r8   RuntimeErrorr   r7   appendr   
appendleftr   sysexc_info)r   varsmgrs      r   r   zNested.__enter__;   s    <<#9::w	}} -CMMO,'',- 	 4==#,,.1 2s   AA8 8$Bc                     |}| j                   D ]  }	  |j                  | rd} d | _         ||ur|y # t        $ r"}t        |      ||j                  f}Y d }~Kd }~ww xY wN)NNN)r8   r   BaseExceptionr   __traceback__)r   r?   exrA   es        r   r   zNested.__exit__I   sv     << 	3C33<<$+B	3 XH  ! 31gq!//23s   4	AAANr   r    r!   r   r   r   r)   r   r   r5   r5   5   s    r   r5   c                       e Zd Zd Zd Zd Zy)
MockNestedc                 Z    t        j                  | g|  d| _        d| _        d | _        y r
   )r5   r   r   r   r   r9   s     r   r   zMockNested.__init__Z   s*    (x(! r   c                 :    d| _         t        j                  |       S r   )r   r5   r   r   s    r   r   zMockNested.__enter__`   s     %%r   c                 J    d| _         || _        t        j                  | g| S r   )r   r   r5   r   r   r?   s     r   r   zMockNested.__exit__d   s%    !t/h//r   NrH   r)   r   r   rJ   rJ   Y   s    &0r   rJ   c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)FailureTestCasec                 6    d }| j                  t        |       y )Nc                  :    t         5  d d d        y # 1 sw Y   y xY wr%   foor)   r   r   fooNotDeclaredz5FailureTestCase.testNameError.<locals>.fooNotDeclaredl   s    NNNs   )assertRaises	NameError)r   rU   s     r   testNameErrorzFailureTestCase.testNameErrork   s    	)^4r   c                 \     G d dt               fd}| j                  t        d|       y )Nc                       e Zd Zd Zy)<FailureTestCase.testEnterAttributeError1.<locals>.LacksEnterc                      y r%   r)   r   s       r   r   zEFailureTestCase.testEnterAttributeError1.<locals>.LacksEnter.__exit__r       r   N)r   r    r!   r   r)   r   r   
LacksEnterr[   q       r   r^   c                  B            } | 5  d d d        y # 1 sw Y   y xY wr%   r)   )rT   r^   s    r   fooLacksEnterz?FailureTestCase.testEnterAttributeError1.<locals>.fooLacksEnteru   s    ,CNNN   the context managerobjectassertRaisesRegex	TypeError)r   ra   r^   s     @r   testEnterAttributeError1z(FailureTestCase.testEnterAttributeError1p   s)    	 		 	y*?Or   c                 \     G d dt               fd}| j                  t        d|       y )Nc                       e Zd Zy)CFailureTestCase.testEnterAttributeError2.<locals>.LacksEnterAndExitNr   r    r!   r)   r   r   LacksEnterAndExitrk   {   s    r   rm   c                  B            } | 5  d d d        y # 1 sw Y   y xY wr%   r)   )rT   rm   s    r   fooLacksEnterAndExitzFFailureTestCase.testEnterAttributeError2.<locals>.fooLacksEnterAndExit~   s    #%CNNNrb   rc   rd   )r   ro   rm   s     @r   testEnterAttributeError2z(FailureTestCase.testEnterAttributeError2z   s*    	 		 	y*?AUVr   c                 \     G d dt               fd}| j                  t        d|       y )Nc                       e Zd Zd Zy)9FailureTestCase.testExitAttributeError.<locals>.LacksExitc                      y r%   r)   r   s    r   r   zCFailureTestCase.testExitAttributeError.<locals>.LacksExit.__enter__   r]   r   N)r   r    r!   r   r)   r   r   	LacksExitrs      r_   r   ru   c                  B            } | 5  d d d        y # 1 sw Y   y xY wr%   r)   )rT   ru   s    r   fooLacksExitz<FailureTestCase.testExitAttributeError.<locals>.fooLacksExit   s    +CNNNrb   zthe context manager.*__exit__rd   )r   rw   ru   s     @r   testExitAttributeErrorz&FailureTestCase.testExitAttributeError   s)    	 		 	y*I<Xr   c                 8    d }| j                  t        ||       y )Nc                     t        | dd       y )N single)compile)ss    r   shouldRaiseSyntaxErrorzGFailureTestCase.assertRaisesSyntaxError.<locals>.shouldRaiseSyntaxError   s    Ar8$r   )rV   SyntaxError)r   codestrr   s      r   assertRaisesSyntaxErrorz'FailureTestCase.assertRaisesSyntaxError   s    	%+'=wGr   c                 H    | j                  d       | j                  d       y )Nzwith mock as None:
  passzwith mock as (None):
  passr   r   s    r   testAssignmentToNoneErrorz)FailureTestCase.testAssignmentToNoneError   s$    $$%AB$$	r   c                 H    | j                  d       | j                  d       y )Nzwith mock as None,:
  passzwith mock as (None,):
  passr   r   s    r   ,testAssignmentToTupleOnlyContainingNoneErrorz<FailureTestCase.testAssignmentToTupleOnlyContainingNoneError   s$    $$%BC$$	r   c                 &    | j                  d       y )Nz%with mock as (foo, None, bar):
  passr   r   s    r   (testAssignmentToTupleContainingNoneErrorz8FailureTestCase.testAssignmentToTupleContainingNoneError   s    $$	r   c                       G d dt                fd} j                  t        |        j                   j                  d        y )Nc                       e Zd Zd Zd Zy)4FailureTestCase.testEnterThrows.<locals>.EnterThrowsc                     t        d      )NzEnter threwr;   r   s    r   r   z>FailureTestCase.testEnterThrows.<locals>.EnterThrows.__enter__   s    "=11r   c                      y r%   r)   r   r   s     r   r   z=FailureTestCase.testEnterThrows.<locals>.EnterThrows.__exit__   r]   r   Nr   r    r!   r   r   r)   r   r   EnterThrowsr      s    2r   r   c                  \            } d _         | 5 _         	 d d d        y # 1 sw Y   y xY wr%   rS   )ctr   r   s    r   shouldThrowz4FailureTestCase.testEnterThrows.<locals>.shouldThrow   s0    BDH tx  s   "+)re   rV   r;   assertEqualrT   )r   r   r   s   ` @r   testEnterThrowszFailureTestCase.testEnterThrows   s:    	& 		
 	,44(r   c                 Z     G d dt               fd}| j                  t        |       y )Nc                       e Zd Zd Zd Zy)2FailureTestCase.testExitThrows.<locals>.ExitThrowsc                      y r%   r)   r   s    r   r   z<FailureTestCase.testExitThrows.<locals>.ExitThrows.__enter__   s    r   c                     t        d      )N*   r   r   s     r   r   z;FailureTestCase.testExitThrows.<locals>.ExitThrows.__exit__   s    "2&&r   Nr   r)   r   r   
ExitThrowsr      s    'r   r   c                  @             5  	 d d d        y # 1 sw Y   y xY wr%   r)   )r   s   r   r   z3FailureTestCase.testExitThrows.<locals>.shouldThrow   s        s   )re   rV   r;   )r   r   r   s     @r   testExitThrowszFailureTestCase.testExitThrows   s&    	' 	'
	 	,4r   N)r   r    r!   rX   rh   rp   rx   r   r   r   r   r   r   r)   r   r   rP   rP   j   s8    5
PWYH

)	5r   rP   c                   F    e Zd Zd Zd Zd Zd Zd Zd Zd Z		 dd	Z
d
 Zy)ContextmanagerAssertionMixinc                 $    t        d      | _        y )Nztest exception)r;   TEST_EXCEPTIONr   s    r   setUpz"ContextmanagerAssertionMixin.setUp   s    *+;<r   c                     | j                  |j                         | j                  |j                         | j	                  |j
                  d        y r%   )
assertTruer   assertFalser   r   r   r   mock_managers     r   assertInWithManagerInvariantsz:ContextmanagerAssertionMixin.assertInWithManagerInvariants   s>    112112//6r   c                     | j                  |j                         | j                  |j                         | j                  |j                  |       y r%   )r   r   r   r   r   )r   r   r   s      r    assertAfterWithManagerInvariantsz=ContextmanagerAssertionMixin.assertAfterWithManagerInvariants   s<    112001//;r   c                 (    | j                  |d       y rC   )r   r   s     r   'assertAfterWithManagerInvariantsNoErrorzDContextmanagerAssertionMixin.assertAfterWithManagerInvariantsNoError   s    --l	 r   c                 p    | j                  |j                         | j                  |j                         y r%   )r   r.   r   r/   r   mock_generators     r   assertInWithGeneratorInvariantsz<ContextmanagerAssertionMixin.assertInWithGeneratorInvariants   s(    ..///0r   c                 p    | j                  |j                         | j                  |j                         y r%   r   r.   r/   r   s     r   )assertAfterWithGeneratorInvariantsNoErrorzFContextmanagerAssertionMixin.assertAfterWithGeneratorInvariantsNoError   &    ../../r   c                     | j                   r%   )r   r   s    r   raiseTestExceptionz/ContextmanagerAssertionMixin.raiseTestException   s    !!!r   Nc                    | j                  |j                         | j                  |j                         |>| j                  |j                  d   | j
                         t        | j
                        }| j                  |j                  d   |       | j                  |j                  d   |       | j                  |j                  d   d        y )N   r      )	r   r   r   r   r   r   r   assertIsInstanceassertIsNot)r   r   exc_types      r   )assertAfterWithManagerInvariantsWithErrorzFContextmanagerAssertionMixin.assertAfterWithManagerInvariantsWithError   s    112001\33A68K8KLD//0H//2H=l44Q7B//2D9r   c                 p    | j                  |j                         | j                  |j                         y r%   r   r   s     r   +assertAfterWithGeneratorInvariantsWithErrorzHContextmanagerAssertionMixin.assertAfterWithGeneratorInvariantsWithError   r   r   r%   )r   r    r!   r   r   r   r   r   r   r   r   r   r)   r   r   r   r      s5    =7
<
 10" <@
:0r   r   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	NonexceptionalTestCasec                 D    t               5  	 d d d        y # 1 sw Y   y xY wr%   r3   r   s    r   testInlineGeneratorSyntaxz0NonexceptionalTestCase.testInlineGeneratorSyntax   s     *, 		 	 	s   c                 j    t               }|5  	 d d d        | j                  |       y # 1 sw Y   xY wr%   )r3   r   )r   r2   s     r   testUnboundGeneratorz+NonexceptionalTestCase.testUnboundGenerator   s3    ,. 		44T:	 	s   )2c                     t               5 }| j                  |       d d d        | j                         y # 1 sw Y   xY wr%   r3   r   r   r   rT   s     r   testInlineGeneratorBoundSyntaxz5NonexceptionalTestCase.testInlineGeneratorBoundSyntax   s=    *, 	6005	6 	66s;	6 	6s	   7A c                     d }t               5 }| j                  |       d d d        | j                  |       y # 1 sw Y   xY wr%   r   r   s     r   *testInlineGeneratorBoundToExistingVariablezANonexceptionalTestCase.testInlineGeneratorBoundToExistingVariable   s@    *, 	6005	666s;	6 	6s	   9Ac                     t               5 | _        | j                  | j                         d d d        | j                  | j                         y # 1 sw Y   %xY wr%   )r3   rT   r   r   r   s    r   (testInlineGeneratorBoundToDottedVariablez?NonexceptionalTestCase.testInlineGeneratorBoundToDottedVariable  sE    *, 	;00:	;66txx@	; 	;s   !AAc                     t               }|5 }| j                  |       | j                  |       d d d        | j                         | j	                  |       y # 1 sw Y   ,xY wr%   )r3   r   r   r   r   )r   r2   rT   s      r   testBoundGeneratorz)NonexceptionalTestCase.testBoundGenerator  s^    ,. 	5S005..t4	5 	66s;44T:		5 	5s   #AA$c                    t               }|5 }t               }|5 }| j                  |       | j                  |       | j                  |       | j                  |       d d d        | j                  |       | j	                         | j                  |       | j                  |       d d d        | j                  |       | j	                         y # 1 sw Y   xxY w# 1 sw Y   8xY wr%   )r3   r   r   r   r   )r   mock_arT   mock_bbars        r   testNestedSingleStatementsz1NonexceptionalTestCase.testNestedSingleStatements  s    .0 
	6s24F :3226:226:44S944S9	:
 88@::3?..v6005
	6 	44V<66s;: :
	6 
	6s$   C"ACAC"C	C""C+N)
r   r    r!   r   r   r   r   r   r   r   r)   r   r   r   r      s&    ;<<A
;<r   r   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	NestedNonexceptionalTestCasec                 V    t        t                     5  	 d d d        y # 1 sw Y   y xY wr%   r5   r3   r   s    r   "testSingleArgInlineGeneratorSyntaxz?NestedNonexceptionalTestCase.testSingleArgInlineGeneratorSyntax#  s&    134 		 	 	s   (c                     t               }t        |      5 }| j                  |       d d d        | j                  |       y # 1 sw Y   xY wr%   r3   r5   r   r   r   mrT   s      r   testSingleArgBoundToNonTuplez9NestedNonexceptionalTestCase.testSingleArgBoundToNonTuple'  sF    )+ AY 	2#..q1	244Q7	2 	2   AAc                     t               }t        |      5 }| j                  |       d d d        | j                  |       y # 1 sw Y   xY wr%   r   r   s      r   2testSingleArgBoundToSingleElementParenthesizedListzONestedNonexceptionalTestCase.testSingleArgBoundToSingleElementParenthesizedList/  sF    )+ AY 	23..q1	244Q7	2 	2r   c                 6    d }| j                  t        |       y )Nc                  \    t        t                     5 \  } }	 d d d        y # 1 sw Y   y xY wr%   r   )rT   r   s     r   shouldThrowValueErrorziNestedNonexceptionalTestCase.testSingleArgBoundToMultipleElementTupleError.<locals>.shouldThrowValueError8  s,    578 JS#  s   "+)rV   
ValueError)r   r   s     r   -testSingleArgBoundToMultipleElementTupleErrorzJNestedNonexceptionalTestCase.testSingleArgBoundToMultipleElementTupleError7  s    	 	*&;<r   c                     t               }t        |      }|5  | j                  |       | j                  |       d d d        | j                  |       | j                  |       y # 1 sw Y   ,xY wr%   r3   rJ   r   r   )r   r*   mock_nesteds      r   testSingleArgUnboundz1NestedNonexceptionalTestCase.testSingleArgUnbound=  sj    ;= !45 	<../BC..{;	< 	445HI44[A		< 	<s   #A&&A/c                    t               }t               }t               }t        |||      }|5  | j                  |       | j                  |       | j                  |       | j                  |       d d d        | j                  |       | j                  |       | j                  |       | j                  |       y # 1 sw Y   NxY wr%   r   )r   r   nor   s        r   testMultipleArgUnboundz3NestedNonexceptionalTestCase.testMultipleArgUnboundF  s    )+)+)+ Aq) 	<..q1..q1..q1..{;		<
 	44Q744Q744Q744[A	< 	<s   AC  C	c                    t        t               t               t                     }|5 \  }}}| j                  |       | j                  |       | j                  |       | j                  |       d d d        | j	                         | j	                         | j	                         | j                  |       y # 1 sw Y   NxY wr%   )rJ   r3   r   r   r   r   )r   r   r   r   r   s        r   testMultipleArgBoundz1NestedNonexceptionalTestCase.testMultipleArgBoundU  s     !>!@)+-J-LN 	<IQ1003003003..{;		<
 	66q966q966q944[A	< 	<s   A	B>>CN)
r   r    r!   r   r   r   r   r   r   r   r)   r   r   r   r   !  s(    88=BBBr   r   c                   T    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)ExceptionalTestCasec                      t                fd} j                  t        |        j                          j	                   j
                         y )Nc                       5 _         j                          j                  j                          j                          d d d        y # 1 sw Y   y xY wr%   )resourcer   r   r   cmr   s   r   r   z;ExceptionalTestCase.testSingleResource.<locals>.shouldThrowf  sK     *t}222644T]]C'')* * *s   AAA)r3   rV   r;   r   r   r   r   r   r   s   ` @r   testSingleResourcez&ExceptionalTestCase.testSingleResourced  sB    *,	*
 	,466r:88Gr   c                      t                fd} j                  t        |        j                  t               y )Nc                  H     5 _         ddz   d d d        y # 1 sw Y   y xY wNr   r   )r   r   s   r   r   z@ExceptionalTestCase.testExceptionNormalized.<locals>.shouldThrowq  s(     t} Q  s   !)r3   rV   ZeroDivisionErrorr   r   s   ` @r   testExceptionNormalizedz+ExceptionalTestCase.testExceptionNormalizedo  s4    *,	
 	+[966r;LMr   c                     t               t                fd} j                  t        |        j                          j                          j	                   j
                          j	                   j                         y )Nc                  F    5 _         5 _        j                          j                         j                  j                          j                  j                         j	                          d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wr%   rT   r   r   r   r   r   r   r   s   r   r   zCExceptionalTestCase.testNestedSingleStatements.<locals>.shouldThrow|  s     .48 .tx66v>66v>88B88B++-.. .. .. .s#   BA.B:BB	BB )r3   rV   r;   r   r   rT   r   r   r   r   r   s   ` @@r   r   z.ExceptionalTestCase.testNestedSingleStatementsy  sj    .0.0	. 	,466v>66v>88B88Br   c                 Z    t               t               t               fd} j                  t        |        j	                          j	                          j	                          j                   j                          j                   j                         y )Nc                  @   5 \  _         _        j                          j                         j                         j                  j                          j                  j                         j	                          d d d        y # 1 sw Y   y xY wr%   )
resource_a
resource_br   r   r   )cm_acm_br   r   s   r   r   zOExceptionalTestCase.testMultipleResourcesInSingleStatement.<locals>.shouldThrow  s     * B$/2248224822;?44T__E44T__E'')* * *s   BBB)r3   rJ   rV   r;   r   r   r
  r  )r   r   r  r  r   s   ` @@@r   &testMultipleResourcesInSingleStatementz:ExceptionalTestCase.testMultipleResourcesInSingleStatement  s    ,.,. t,	* 	,466t<66t<66{C88I88Ir   c                     t               t               d  _         fd} j                  t        |        j	                          j                   j                          j                   j                  d         j                  j                          j                  j                          j                  j                  d        y )Nc                       5 _         j                          j                  j                          j                          5 _        	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wr%   )rT   r   r   r   r   r  s   r   r   zPExceptionalTestCase.testNestedExceptionBeforeInnerStatement.<locals>.shouldThrow  so     48226:44TXX>'') tx	  	 s$   AA,A A, A)	%A,,A5)r3   r   rV   r;   r   r   rT   r   r   r   r   r   r  s   ` @@r   'testNestedExceptionBeforeInnerStatementz;ExceptionalTestCase.testNestedExceptionBeforeInnerStatement  s    .0.0	 	,466v>88B 	4(,,-++,))40r   c                     t               t                fd} j                  t        |        j                          j	                          j                   j                          j                   j                         y )Nc                  F    5 _         5 _        j                          j                         j                  j                          j                  j                         d d d        j	                          d d d        y # 1 sw Y   "xY w# 1 sw Y   y xY wr%   r  r  s   r   r   zOExceptionalTestCase.testNestedExceptionAfterInnerStatement.<locals>.shouldThrow  s     *48 Ctx66v>66v>88B88B	C
 '')* *C C* *s#   BAB*BB	BB )	r3   rV   r;   r   r   r   rT   r   r   r  s   ` @@r   &testNestedExceptionAfterInnerStatementz:ExceptionalTestCase.testNestedExceptionAfterInnerStatement  sj    .0.0	* 	,466v>44V<88B66txx@r   c                     t         d        fd}| j                  t        d      5   |        d d d        y # 1 sw Y   y xY w)Nc               3      K   d  y wr%   r)   r)   r   r   r   z8ExceptionalTestCase.testRaisedStopIteration1.<locals>.cm  	        c                  B             5  t        d      # 1 sw Y   y xY wN	from withStopIterationr   s   r   r   zAExceptionalTestCase.testRaisedStopIteration1.<locals>.shouldThrow  #     1#K001 1   r  )r   rf   r  r   s     @r   testRaisedStopIteration1z,ExceptionalTestCase.testRaisedStopIteration1  sF    		 
		1 ##M;? 	M	 	 	s	   :Ac                      G d dt               fd}| j                  t        d      5   |        d d d        y # 1 sw Y   y xY w)Nc                       e Zd Zd Zd Zy)8ExceptionalTestCase.testRaisedStopIteration2.<locals>.cmc                      y r%   r)   r   s    r   r   zBExceptionalTestCase.testRaisedStopIteration2.<locals>.cm.__enter__  r]   r   c                      y r%   r)   r   s       r   r   zAExceptionalTestCase.testRaisedStopIteration2.<locals>.cm.__exit__  r]   r   Nr   r)   r   r   r   r$        r   r   c                  B             5  t        d      # 1 sw Y   y xY wr  r  r  s   r   r   zAExceptionalTestCase.testRaisedStopIteration2.<locals>.shouldThrow  r  r   r  )re   rf   r  r   s     @r   testRaisedStopIteration2z,ExceptionalTestCase.testRaisedStopIteration2  s@    	 		1 ##M;? 	M	 	 	s	   =Ac                     t         d        fd}| j                  t              5   |        d d d        y # 1 sw Y   y xY w)Nc               3      K   d  y wr%   r)   r)   r   r   r   z8ExceptionalTestCase.testRaisedStopIteration3.<locals>.cm  r  r  c                  T             5  t        t        g             # 1 sw Y   y xY wr%   )nextiterr  s   r   r   zAExceptionalTestCase.testRaisedStopIteration3.<locals>.shouldThrow  s&     %48n$% %s   ')r   rV   r  r   s     @r   testRaisedStopIteration3z,ExceptionalTestCase.testRaisedStopIteration3  sF     
	 
		% }- 	M	 	 	s	   9Ac                 T    t         d        fd}| j                  t        |       y )Nc               3      K   d  y wr%   r)   r)   r   r   r   z8ExceptionalTestCase.testRaisedGeneratorExit1.<locals>.cm  r  r  c                  B             5  t        d      # 1 sw Y   y xY wr  GeneratorExitr  s   r   r   zAExceptionalTestCase.testRaisedGeneratorExit1.<locals>.shouldThrow  r  r   )r   rV   r4  r   s     @r   testRaisedGeneratorExit1z,ExceptionalTestCase.testRaisedGeneratorExit1  s,    		 
		1 	-5r   c                 Z     G d dt               fd}| j                  t        |       y )Nc                       e Zd Zd Zd Zy)8ExceptionalTestCase.testRaisedGeneratorExit2.<locals>.cmc                      y r%   r)   r   s    r   r   zBExceptionalTestCase.testRaisedGeneratorExit2.<locals>.cm.__enter__  r]   r   c                      y r%   r)   r   s       r   r   zAExceptionalTestCase.testRaisedGeneratorExit2.<locals>.cm.__exit__  r]   r   Nr   r)   r   r   r   r8    r'  r   r   c                  B             5  t        d      # 1 sw Y   y xY wr  r3  r  s   r   r   zAExceptionalTestCase.testRaisedGeneratorExit2.<locals>.shouldThrow  r  r   )re   rV   r4  r   s     @r   testRaisedGeneratorExit2z,ExceptionalTestCase.testRaisedGeneratorExit2  s&    	& 		1 	-5r   c                       G d dt                fd} |         fd} j                  t        |        fd} j                  t        |       y )Nc                       e Zd Zd Zd Zd Zy)0ExceptionalTestCase.testErrorsInBool.<locals>.cmc                 6     G fdd      } |       | _         y )Nc                       e Zd Z fdZy)GExceptionalTestCase.testErrorsInBool.<locals>.cm.__init__.<locals>.Boolc                             S r%   r)   )r   bool_conversions    r   __bool__zPExceptionalTestCase.testErrorsInBool.<locals>.cm.__init__.<locals>.Bool.__bool__  s    .00r   N)r   r    r!   rE  )rD  s   r   BoolrB    s    1r   rF  exit_result)r   rD  rF  s    ` r   r   z9ExceptionalTestCase.testErrorsInBool.<locals>.cm.__init__  s    1 1 $(6 r   c                      y)N   r)   r   s    r   r   z:ExceptionalTestCase.testErrorsInBool.<locals>.cm.__enter__  s    r   c                     | j                   S r%   rG  r   abcs       r   r   z9ExceptionalTestCase.testErrorsInBool.<locals>.cm.__exit__  s    '''r   NrH   r)   r   r   r   r?    s    *
(r   r   c                  d      d       5  j                  d       d d d        y # 1 sw Y   y xY w)Nc                       yr   r)   r)   r   r   <lambda>zJExceptionalTestCase.testErrorsInBool.<locals>.trueAsBool.<locals>.<lambda>      r   Should NOT see thisfailr   s   r   
trueAsBoolz8ExceptionalTestCase.testErrorsInBool.<locals>.trueAsBool  -    L! 1		/01 1 1   &/c                  d      d       5  j                  d       d d d        y # 1 sw Y   y xY w)Nc                       yr
   r)   r)   r   r   rR  zKExceptionalTestCase.testErrorsInBool.<locals>.falseAsBool.<locals>.<lambda>  rS  r   zShould raiserU  r   s   r   falseAsBoolz9ExceptionalTestCase.testErrorsInBool.<locals>.falseAsBool  s,    M" *		.)* * *rY  c                  d      d       5  j                  d       d d d        y # 1 sw Y   y xY w)Nc                      ddz  S r   r)   r)   r   r   rR  zJExceptionalTestCase.testErrorsInBool.<locals>.failAsBool.<locals>.<lambda>!  s
    AqD r   rT  rU  r   s   r   
failAsBoolz8ExceptionalTestCase.testErrorsInBool.<locals>.failAsBool   rX  rY  )re   rV   AssertionErrorr  )r   rW  r\  r_  r   s   `   @r   testErrorsInBoolz$ExceptionalTestCase.testErrorsInBool  sJ    		( 		(	1 		* 	.+6	1 	+Z8r   N)r   r    r!   r   r  r   r  r  r  r!  r)  r/  r5  r<  ra  r)   r   r   r   r   c  sC    	HNC"J&1*A"
669r   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)NonLocalFlowControlTestCasec                     d}	 |dz  }t               5  |dz  }	 d d d        | j                  |d       y # 1 sw Y   nxY w|dz  }C)Nr   r   
   d      r3   r   r   counters     r   testWithBreakz)NonLocalFlowControlTestCase.testWithBreak(  s\    qLG.0 2 	"%	  sNG s   5>c                     d}	 |dz  }|dkD  rnt               5  |dz  }	 d d d        &| j                  |d       y # 1 sw Y   nxY w|dz  }J)Nr   r   r   re  rf     rh  ri  s     r   testWithContinuez,NonLocalFlowControlTestCase.testWithContinue2  sk    qLG{.0 2  	"%	  sNG s	   <Ac                 8    d }| j                   |       d       y )Nc                  l    d} 	 | dz  } t               5  | dz  } | cd d d        S # 1 sw Y   nxY w| dz  } 2)Nr   r   re  rf  r   )rj  s    r   rT   z7NonLocalFlowControlTestCase.testWithReturn.<locals>.foo?  sJ    G124 #rMG"# # # 3 s   $-rg  )r   r   s     r   testWithReturnz*NonLocalFlowControlTestCase.testWithReturn>  s    	 	#r   c                 R    d }t         |             }| j                  |ddg       y )Nc               3   Z   K   t               5  d d d d d        y # 1 sw Y   y xY ww)Nrm     r   r)   r   r   genz6NonLocalFlowControlTestCase.testWithYield.<locals>.genJ  s*     .0   s   +		+(+rm  rt  )listr   )r   ru  xs      r   testWithYieldz)NonLocalFlowControlTestCase.testWithYieldI  s(    	 KRH%r   c                     d}	 |dz  }t               5  |dz  }t        # 1 sw Y   nxY w|dz  }| j                  d       y # t        $ r | j                  |d       Y y w xY w)Nr   r   re  rf  zDidn't raise RuntimeErrorrg  )r3   r;   rV  r   ri  s     r   testWithRaisez)NonLocalFlowControlTestCase.testWithRaiseQ  su    		3qLG.0 #2""# # sNG II12  	*Wb)	*s   A (A A A N)r   r    r!   rk  rn  rq  rx  rz  r)   r   r   rc  rc  &  s    &
&	$&3r   rc  c                       e Zd Zd Zd Zd Zy)AssignmentTargetTestCasec                 t   dg di}t               5 |d   d<   | j                  t        |j                               dg       | j                  |d   d   j                  t
               d d d        t               5 t        |j                               d   d<   | j                  t        |j                               dg       | j                  |d   d   j                  t
               d d d        t               5 |d<   t        |j                               }|j                          | j                  |ddg       d d d         G d d      } |       }t               5 |_        | j                  t        |d      d       d d d        y # 1 sw Y   #xY w# 1 sw Y   xY w# 1 sw Y   hxY w# 1 sw Y   y xY w)	Nr   r   r   r   r   r   c                       e Zd Zy);AssignmentTargetTestCase.testSingleComplexTarget.<locals>.CNrl   r)   r   r   Cr  m      r   r  rT   T)
r3   r   rv  keysr   r,   valuessortrT   hasattr)r   targetsr  r  blahs        r   testSingleComplexTargetz0AssignmentTargetTestCase.testSingleComplexTargeta  s|   i.*, 	D
1T',,.1A37WQZ]44lC	D +, 	DW^^5E0Fq0I!0LT',,.1A37WQZ]44lC	D +, 	+
'DIIKTAq6*	+ 	s*, 	9WT5148	9 	9	D 	D	D 	D	+ 	+	9 	9s2   AF	:A.F:AF""F.	FF"F+.F7c                 v    G d d      }dg di} |       5 \  |d   d<   |d   d<   |d   d<   | j                  |dg di       d d d         |       5 \  t        |j                               d   d<   t        |j                               d   d<   t        |j                               d   d<   | j                  |dg di       d d d         |       5 \  |d<   |d<   |d	<   | j                  |ddd	d       d d d         G d
 d      } |       } |       5 \  |_        |_        |_        | j                  |j                  d       | j                  |j                  d       | j                  |j
                  d	       d d d        y # 1 sw Y   GxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nc                       e Zd Zd Zd Zy)>AssignmentTargetTestCase.testMultipleComplexTargets.<locals>.Cc                      y)Nr   r   rJ  r)   r   s    r   r   zHAssignmentTargetTestCase.testMultipleComplexTargets.<locals>.C.__enter__t  s    r   c                      y r%   r)   r   tvtbs       r   r   zGAssignmentTargetTestCase.testMultipleComplexTargets.<locals>.C.__exit__u  s    $r   Nr   r)   r   r   r  r  s  s    /.r   r  r   r~  r   r   r  )rJ  r   r   rJ  c                       e Zd Zy)>AssignmentTargetTestCase.testMultipleComplexTargets.<locals>.BNrl   r)   r   r   Br  }  r  r   r  )r   rv  r  onetwothree)r   r  r  r  r  s        r   testMultipleComplexTargetsz3AssignmentTargetTestCase.testMultipleComplexTargetsr  s   	/ 	/ i.S 	6AWQZ]GAJqM71:a=Wq)n5	6S 	6nT'..*+A.q148H3I!3LQ3OQUV]VdVdVfQghiQjklQmWq)n5	6S 	:8WQZWQZW!a&89	:sS 	,4TXtxTXXq)TXXq)TZZ+	, 	,	6 	6	6 	6	: 	:	, 	,s1   -F
A2F$F#A(F/
FF #F,/F8c                     t        t        dd            5 ^}}}| j                  |d       | j                  |ddg       | j                  |d       d d d        y # 1 sw Y   y xY w)Nr      r   rJ     )r   ranger   rL  s       r   testWithExtendedTargetsz0AssignmentTargetTestCase.testWithExtendedTargets  sa    q!% 	#!aQ"QA'Q"	# 	# 	#s   =AA%N)r   r    r!   r  r  r  r)   r   r   r|  r|  _  s    9",$#r   r|  c                       e Zd Zd Zd Zy)ExitSwallowsExceptionTestCasec                      G d d      }	  |       5  ddz   d d d        y # 1 sw Y   y xY w# t         $ r | j                  d       Y y w xY w)Nc                       e Zd Zd Zd Zy)SExitSwallowsExceptionTestCase.testExitTrueSwallowsException.<locals>.AfricanSwallowc                      y r%   r)   r   s    r   r   z]ExitSwallowsExceptionTestCase.testExitTrueSwallowsException.<locals>.AfricanSwallow.__enter__      r   c                      yr   r)   r  s       r   r   z\ExitSwallowsExceptionTestCase.testExitTrueSwallowsException.<locals>.AfricanSwallow.__exit__  s    r   Nr   r)   r   r   AfricanSwallowr    s    %5r   r  r   r   z,ZeroDivisionError should have been swallowed)r  rV  )r   r  s     r   testExitTrueSwallowsExceptionz;ExitSwallowsExceptionTestCase.testExitTrueSwallowsException  sQ    	6 	6	F! !    	FIIDE	Fs#   . ". +. . A
Ac                      G d d      }	  |       5  ddz   d d d        | j                  d       y # 1 sw Y   xY w# t        $ r Y y w xY w)Nc                       e Zd Zd Zd Zy)ZExitSwallowsExceptionTestCase.testExitFalseDoesntSwallowException.<locals>.EuropeanSwallowc                      y r%   r)   r   s    r   r   zdExitSwallowsExceptionTestCase.testExitFalseDoesntSwallowException.<locals>.EuropeanSwallow.__enter__  r  r   c                      yr
   r)   r  s       r   r   zcExitSwallowsExceptionTestCase.testExitFalseDoesntSwallowException.<locals>.EuropeanSwallow.__exit__  s    r   Nr   r)   r   r   EuropeanSwallowr    s    %6r   r  r   r   z)ZeroDivisionError should have been raised)rV  r  )r   r  s     r   #testExitFalseDoesntSwallowExceptionzAExitSwallowsExceptionTestCase.testExitFalseDoesntSwallowException  sT    	7 	7	C " !
 IIAB   		s   ? 3? <? 	A
AN)r   r    r!   r  r  r)   r   r   r  r    s    F
Cr   r  c                       e Zd Z G d de      Z G d de      Z G d de      Z G d de      Zd	 Zd
 Z	d Z
d Zd Zy)
NestedWithc                        e Zd ZddZd Zd Zy)NestedWith.DummyNc                 D    || }|| _         || _        d| _        d| _        y r
   )r   gobbler   r   )r   r   r  s      r   r   zNestedWith.Dummy.__init__  s*    }DJ DK %D$Dr   c                 (    d| _         | j                  S r   )r   r   r   s    r   r   zNestedWith.Dummy.__enter__  s     $D::r   c                 :    d| _         || _        | j                  ryy r   )r   r?   r  rN   s     r   r   zNestedWith.Dummy.__exit__  s     #D$DM{{ r   r
   rH   r)   r   r   Dummyr    s    	%		r   r  c                       e Zd Zd Zy)NestedWith.InitRaisesc                     t               r%   r   r   s    r   r   zNestedWith.InitRaises.__init__  s	    ,.0r   Nr0   r)   r   r   
InitRaisesr    s    0r   r  c                       e Zd Zd Zd Zy)NestedWith.EnterRaisesc                     t               r%   r   r   s    r   r   z NestedWith.EnterRaises.__enter__  s	    <>1r   c                      y r%   r)   rN   s     r   r   zNestedWith.EnterRaises.__exit__  s    tr   Nr   r)   r   r   EnterRaisesr    s    1+r   r  c                       e Zd Zd Zd Zy)NestedWith.ExitRaisesc                      y r%   r)   r   s    r   r   zNestedWith.ExitRaises.__enter__  s    Tr   c                     t               r%   r   rN   s     r   r   zNestedWith.ExitRaises.__exit__  s	    \^';r   Nr   r)   r   r   
ExitRaisesr    s    !;r   r  c                 p   | j                         5 }| j                         5 }| j                  |j                         | j                  |j                         d d d        d d d        | j                  j                         | j                  j                         y # 1 sw Y   HxY w# 1 sw Y   LxY wr%   )r  r   r   r   )r   rM  rN  s      r   testNoExceptionszNestedWith.testNoExceptions  s    ZZ\ 	,Q

 	,OOANN+OOANN+	, 	, 	&&		, 	, 	, 	,s"   B,7B B, B)	%B,,B5c                    	 | j                         5 }| j                         5  	 d d d        d d d        | j                  j                         | j                  |j                         y # 1 sw Y   HxY w# 1 sw Y   LxY w#  Y SxY wr%   )r  r  r   r   r   r   rM  s     r   testExceptionInExprListz"NestedWith.testExceptionInExprList  ss    	 DOO$5   	'&   	s7   B A8A,A8B ,A5	1A88B=B Bc                 h   	 | j                         5 }| j                         5  | j                  d       d d d        d d d        | j                  d       | j	                  j
                         | j	                  |j                         y # 1 sw Y   YxY w# 1 sw Y   ]xY w# t        $ r Y Zw xY w)Nzbody of bad with executedzRuntimeError not reraised)r  r  rV  r;   r   r   r   r  s     r   testExceptionInEnterzNestedWith.testExceptionInEnter  s    	3 7D$4$4$6 7		567 7
 II12'&7 7 7 7 		s=   B% BBBB% B	BB"B% %	B10B1c                 p   d}| j                  d      5 }| j                         5  d}d d d        d d d        | j                  j                         | j                  |j                         | j                  |       | j                  |j                  d   d        y # 1 sw Y   xxY w# 1 sw Y   |xY w)NFT)r  r   )r  r  r   r   r   assertNotEqualr?   )r   body_executedrM  s      r   testExceptionInExitzNestedWith.testExceptionInExit  s    ZZtZ$ 	!4??+< 	! M	! 	!'&&AJJqM40	! 	! 	! 	!s!   B,B B, B)	%B,,B5c                 <   | j                  d      5 \  }}| j                  d      5 \  }}| j                  d|       | j                  d|       | j                  d|       | j                  d|       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)N)r   r   )r   )re     r   r   re  r  )r  r   )r   a1a2b1b2s        r   testEnterReturnsTuplez NestedWith.testEnterReturnsTuple  s    ZZeZ$ 	%RZZhZ'	%+3BQ#Q#R$R$	% 	% 	% 	% 	% 	%s#   BAB5BB	BBN)r   r    r!   re   r  r  r  r  r  r  r  r  r  r)   r   r   r  r    sK     &1V 1,f ,<V <''	'1%r   r  __main__)__doc__
__author__	__email__r>   unittestcollectionsr   
contextlibr   r   r   r   r*   re   r,   r3   r5   rJ   TestCaserP   r   r   r   r   rc  r|  r  r  r   mainr)   r   r   <module>r     sA   = 
#	 
   L LC1 C$6   !V !H0 0"Q5h'' Q5f,06 ,0^2<X..0L 2<j?B8#4#4 ?BD@968I8I @9F63("3"3 63r)#x00 )#XCH$5$5 C2J%"" J%X zHMMO r   