
    7bho                     N   	 d Z dZddl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)#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     8/opt/python-3.12.12/usr/lib/python3.12/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__8   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__J   sq     <<C33<<$+B   XH  ! 31gq!//23s   4	AAANr   r    r!   r   r   r   r)   r   r   r5   r5   6   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__[   s*    (x(! r   c                 :    d| _         t        j                  |       S r   )r   r5   r   r   s    r   r   zMockNested.__enter__a   s     %%r   c                 J    d| _         || _        t        j                  | g| S r   )r   r   r5   r   r   r?   s     r   r   zMockNested.__exit__e   s%    !t/h//r   NrH   r)   r   r   rJ   rJ   Z   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>.fooNotDeclaredm   s    s   )assertRaises	NameError)r   rU   s     r   testNameErrorzFailureTestCase.testNameErrorl   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__s       r   N)r   r    r!   r   r)   r   r   
LacksEnterr[   r       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>.fooLacksEnterv   s    ,C   the context managerobjectassertRaisesRegex	TypeError)r   ra   r^   s     @r   testEnterAttributeError1z(FailureTestCase.testEnterAttributeError1q   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rb   rc   rd   )r   ro   rm   s     @r   testEnterAttributeError2z(FailureTestCase.testEnterAttributeError2{   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rb   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   s'    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   k   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   s+    ,. 44T: Ts   )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   s6    *,005 - 	66s; -,	   7A c                     t               5 }| j                  |       d d d        | j                         y # 1 sw Y   xY wr%   r   r   s     r   *testInlineGeneratorBoundToExistingVariablezANonexceptionalTestCase.testInlineGeneratorBoundToExistingVariable  s4    *,005 -66s; -,r   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  s>    *,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  sV    ,.S005..t4  	66s;44T:	 Ts   #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s24F3226:226:44S944S9	 
 88@::3?..v6005  	44V<66s;  Vs$   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 544s   (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*  s>    )+ AY#..q1 44Q7 Y   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.testSingleArgBoundToSingleElementParenthesizedList2  s>    )+ AY3..q1 44Q7 Yr   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>.shouldThrowValueError;  s#    578JS# 988s   "+)rV   
ValueError)r   r   s     r   -testSingleArgBoundToMultipleElementTupleErrorzJNestedNonexceptionalTestCase.testSingleArgBoundToMultipleElementTupleError:  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@  sb    ;= !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.testMultipleArgUnboundI  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.testMultipleArgBoundX  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>.shouldThrowi  s@    t}222644T]]C'') s   AAA)r3   rV   r;   r   r   r   r   r   r   s   ` @r   testSingleResourcez&ExceptionalTestCase.testSingleResourceg  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>.shouldThrowt  s    t} Q s   !)r3   rV   ZeroDivisionErrorr   r   s   ` @r   testExceptionNormalizedz+ExceptionalTestCase.testExceptionNormalizedr  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  sw    48tx66v>66v>88B88B++-  V s#   BA.B:BB	BB )r3   rV   r;   r   r   rT   r   r   r   r   r   s   ` @@r   r   z.ExceptionalTestCase.testNestedSingleStatements|  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  su     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  s\    48226:44TXX>'')tx 	  V	 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  sy    48tx66v>66v>88B88B	 
 '') V 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      #K00    r  )r   rf   r  r   s     @r   testRaisedStopIteration1z,ExceptionalTestCase.testRaisedStopIteration1  s>    		 
		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  s8    	 		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  s=     
	 
		% }-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   r5  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   r9    r(  r   r   c                  B             5  t        d      # 1 sw Y   y xY wr  r4  r  s   r   r   zAExceptionalTestCase.testRaisedGeneratorExit2.<locals>.shouldThrow  r   r!  )re   rV   r5  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!   rF  )rE  s   r   BoolrC    s    1r   rG  exit_result)r   rE  rG  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%   rH  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>  s    Dr   Should NOT see thisfailr   s   r   
trueAsBoolz8ExceptionalTestCase.testErrorsInBool.<locals>.trueAsBool  $    L!		/0 "!!   &/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   rS  zKExceptionalTestCase.testErrorsInBool.<locals>.falseAsBool.<locals>.<lambda>  s    Er   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   rS  zJExceptionalTestCase.testErrorsInBool.<locals>.failAsBool.<locals>.<lambda>$  s    AqDr   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*  r0  r6  r=  ra  r)   r   r   r   r   f  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+  sU    qLG.02 1 	"%	 10 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.testWithContinue5  sb    qLG{.02 10 	"%	 10 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>.fooB  sA    G124rMG" 544 3 s   $-rg  )r   r   s     r   testWithReturnz*NonLocalFlowControlTestCase.testWithReturnA  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>.genM  s!     .0 100s   +		+(+rm  rt  )listr   )r   ru  xs      r   testWithYieldz)NonLocalFlowControlTestCase.testWithYieldL  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.testWithRaiseT  sn    		3qLG.02"" 10 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  p      r   r  rT   T)
r3   r   rv  keysr   r,   valuessortrT   hasattr)r   targetsr  r  blahs        r   testSingleComplexTargetz0AssignmentTargetTestCase.testSingleComplexTargetd  sV   i.*,
1T',,.1A37WQZ]44lC - +,W^^5E0Fq0I!0LT',,.1A37WQZ]44lC - +,
'DIIKTAq6* - 	s*,WT5148 -, -, -, -, -,s2   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   rK  r)   r   s    r   r   zHAssignmentTargetTestCase.testMultipleComplexTargets.<locals>.C.__enter__w  s    r   c                      y r%   r)   r   tvtbs       r   r   zGAssignmentTargetTestCase.testMultipleComplexTargets.<locals>.C.__exit__x  s    $r   Nr   r)   r   r   r  r  v  s    /.r   r  r   r~  r   r   r  )rK  r   r   rK  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.testMultipleComplexTargetsu  sz   	/ 	/ i.SAWQZ]GAJqM71:a=Wq)n5 SnT'..*+A.q148H3I!3LQ3OQUV]VdVdVfQghiQjklQmWq)n5 S8WQZWQZW!a&89 sS4TXtxTXXq)TXXq)TZZ+ S SSS Ss1   -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   rK     )r   ranger   rM  s       r   testWithExtendedTargetsz0AssignmentTargetTestCase.testWithExtendedTargets  sX    q!%!aQ"QA'Q" &%%s   =AA%N)r   r    r!   r  r  r  r)   r   r   r|  r|  b  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  sH    	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  sM    	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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   rN  rO  s      r   testNoExceptionszNestedWith.testNoExceptions  sm    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   rN  s     r   testExceptionInExprListz"NestedWith.testExceptionInExprList  s^    	DOO$5 %6 	'& %6$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D$4$4$6		56 %7
 II12'& %7$6 		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_executedrN  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'8BQ#Q#R$R$	 ( %$'' %$s#   BAB5BB	BBc                      fd} fd} fd}|df|df|dffD ]  \  }} j                  |      5   |       }t        j                  |j                        d   }d}|j                  }	 j                  |j                  |	j                  d	z           j                  |j                  |	j                  d	z           j                  |j                  |j                  |z
  |j                  |z
   |       d d d         y # 1 sw Y   xY w)
Nc                     	 j                         5  j                         5 } j                         5 }	 d d d        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w# t        $ r}|cY d }~S d }~ww xY wr%   )r  r  	Exception)r   drG   r   s      r   init_raisesz5NestedWith.testExceptionLocation.<locals>.init_raises  s[    ZZ\4??#4DJJLA =I#4\\LL#4#4\\ sf   A4 A(AAAA(A4 AAA%	!A((A1-A4 1A4 4	B	=B>B	B	c                      	 j                         5  j                         5 } 	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w# t        $ r}|cY d }~S d }~ww xY wr%   )r  r  r  r  rG   r   s     r   enter_raisesz6NestedWith.testExceptionLocation.<locals>.enter_raises  sL    %%' *6'''' L   A A7AA A 	AAA A 	A$AA$A$c                      	 j                         5  j                         5 } 	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w# t        $ r}|cY d }~S d }~ww xY wr%   )r  r  r  r  s     r   exit_raisesz5NestedWith.testExceptionLocation.<locals>.exit_raises  sJ    __&

 )5&&&& r  zself.InitRaises()zself.EnterRaises()zself.ExitRaises()r      r   )subTestr   
extract_tbrE   __code__r   linenoco_firstlineno
end_linenolinecolno	end_colno)
r   r  r  r  r'   expectedexcfindentcos
   `         r   testExceptionLocationz NestedWith.testExceptionLocation  s    			 !,-@A ,.BC +-@A ND( d#f(():):;A>]]  2+<+<q+@A  r/@/@1/DE  &(81;;;O!P!)+ $#	  $#s   CDD
	N)r   r    r!   re   r  r  r  r  r  r  r  r  r  r  r)   r   r   r  r    sP     &1V 1,f ,<V <''	'1%(+r   r  __main__)
__author__	__email__r>   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     sD   = 
#	 
    L LC1 C$6   !V !H0 0"T5h'' T5l,06 ,0^1<X..0L 1<h?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2t+"" t+n zHMMO r   