HEX
Server: Apache
System: Linux bd12.noc223.com 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User: handcraf (1693)
PHP: 8.1.28
Disabled: NONE
Upload Files
File: //proc/self/root/opt/alt/python312/lib64/python3.12/test/__pycache__/test_with.cpython-312.pyc
�

�h�eh��H�dZdZdZddlZddlZddlmZddlmZm	Z	m
Z
Gd�de�Zd	�ZGd
�de
�Zed��ZGd
�de
�ZGd�de�ZGd�dej$�ZGd�de
�ZGd�dej$e�ZGd�dej$e�ZGd�deej$�ZGd�dej$�ZGd�dej$�ZGd�d ej$�ZGd!�d"ej$�Zed#k(rej:�yy)$z7Unit tests for the with statement specified in PEP 343.z
Mike Blandzmbland at acm dot org�N)�deque)�_GeneratorContextManager�contextmanager�nullcontextc�*��eZdZ�fd�Zd�Zd�Z�xZS)�MockContextManagerc�H��t�|�|�d|_d|_d|_y�NF)�super�__init__�enter_called�exit_called�	exit_args)�self�args�	__class__s  ��5/opt/alt/python312/lib64/python3.12/test/test_with.pyrzMockContextManager.__init__s'���
���$��!��� ������c�:�d|_tj|�S�NT)r
r�	__enter__�rs rrzMockContextManager.__enter__s�� ���'�1�1�$�7�7rc�T�d|_|||f|_tj||||�Sr)rrr�__exit__�r�type�value�	tracebacks    rrzMockContextManager.__exit__s6�������y�1���'�0�0��t�16�	�C�	Cr)�__name__�
__module__�__qualname__rrr�
__classcell__)rs@rrr
s����8�Crrc����fd�}|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��Mrc��eZdZd�Zy)�MockResourcec� �d|_d|_yr
)�yielded�stoppedrs rrzMockResource.__init__&s�������rN�rr r!rr)rrr,r,%s��rr,c#�^K�t�}	d|_|��d|_y#d|_wxYw�wr)r,r.r/)�mocks r�mock_contextmanager_generatorr3+s,�����>�D������
�����t���s�-�!�-�	*�-c��eZdZd�Zd�Zd�Zy)�Nestedc� �||_d|_yr%)�managers�entered�rr7s  rrzNested.__init__7s�� ��
���rc�D�|j�td��t�|_g}	|jD]<}|j	|j��|jj
|��>	|S#|jtj��s�Y|SxYw)NzContext is not reentrant)
r8�RuntimeErrorrr7�appendr�
appendleftr�sys�exc_info)r�vars�mgrs   rrzNested.__enter__;s����<�<�#��9�:�:��w�����	��}�}�
-�����C�M�M�O�,����'�'��,�
-����	� �4�=�=�#�,�,�.�1��2���s�AA8�8$Bc���|}|jD]}	|j|�rd}�d|_||ur|�y#t$r"}t|�||jf}Yd}~�Kd}~wwxYw�N)NNN)r8r�
BaseExceptionr�
__traceback__)rr?�exrA�es     rrzNested.__exit__Isv�����<�<�	3�C�
3��3�<�<��$�+�B��	3����
�X���H���!�
3��1�g�q�!�/�/�2���
3�s�4�	A�A�AN�rr r!rrrr)rrr5r55s����
rr5c��eZdZd�Zd�Zd�Zy)�
MockNestedc�Z�tj|g|���d|_d|_d|_yr
)r5rr
rrr9s  rrzMockNested.__init__Zs*������(�x�(�!��� �����rc�:�d|_tj|�Sr)r
r5rrs rrzMockNested.__enter__`s�� �������%�%rc�J�d|_||_tj|g|���Sr)rrr5r�rr?s  rrzMockNested.__exit__ds%�����!������t�/�h�/�/rNrHr)rrrJrJYs���&�0rrJc�H�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�FailureTestCasec�6�d�}|jt|�y)Nc�:�t5ddd�y#1swYyxYwr%��foor)rr�fooNotDeclaredz5FailureTestCase.testNameError.<locals>.fooNotDeclaredls���N�N�N�s��)�assertRaises�	NameError)rrUs  r�
testNameErrorzFailureTestCase.testNameErrorks��	����)�^�4rc�\��Gd�dt���fd�}|jtd|�y)Nc��eZdZd�Zy)�<FailureTestCase.testEnterAttributeError1.<locals>.LacksEnterc��yr%r)rs    rrzEFailureTestCase.testEnterAttributeError1.<locals>.LacksEnter.__exit__r���rN)rr r!rr)rr�
LacksEnterr[q���
rr^c�B����}|5ddd�y#1swYyxYwr%r))rTr^s �r�
fooLacksEnterz?FailureTestCase.testEnterAttributeError1.<locals>.fooLacksEnterus����,�C��N�N�N�����the context manager��object�assertRaisesRegex�	TypeError)rrar^s  @r�testEnterAttributeError1z(FailureTestCase.testEnterAttributeError1ps)���	��	�	�	
���y�*?��Orc�\��Gd�dt���fd�}|jtd|�y)Nc��eZdZy)�CFailureTestCase.testEnterAttributeError2.<locals>.LacksEnterAndExitN�rr r!r)rr�LacksEnterAndExitrk{s��rrmc�B����}|5ddd�y#1swYyxYwr%r))rTrms �r�fooLacksEnterAndExitzFFailureTestCase.testEnterAttributeError2.<locals>.fooLacksEnterAndExit~s���#�%�C��N�N�N�rbrcrd)rrorms  @r�testEnterAttributeError2z(FailureTestCase.testEnterAttributeError2zs*���	��	�	�	
���y�*?�AU�Vrc�\��Gd�dt���fd�}|jtd|�y)Nc��eZdZd�Zy)�9FailureTestCase.testExitAttributeError.<locals>.LacksExitc��yr%r)rs rrzCFailureTestCase.testExitAttributeError.<locals>.LacksExit.__enter__�r]rN)rr r!rr)rr�	LacksExitrs�r_rruc�B����}|5ddd�y#1swYyxYwr%r))rTrus �r�fooLacksExitz<FailureTestCase.testExitAttributeError.<locals>.fooLacksExit�s����+�C��N�N�N�rbzthe context manager.*__exit__rd)rrwrus  @r�testExitAttributeErrorz&FailureTestCase.testExitAttributeError�s)���	��	�	�	
���y�*I�<�Xrc�8�d�}|jt||�y)Nc��t|dd�y)N��single)�compile)�ss r�shouldRaiseSyntaxErrorzGFailureTestCase.assertRaisesSyntaxError.<locals>.shouldRaiseSyntaxError�s���A�r�8�$r)rV�SyntaxError)r�codestrrs   r�assertRaisesSyntaxErrorz'FailureTestCase.assertRaisesSyntaxError�s��	%����+�'=�w�Grc�H�|jd�|jd�y)Nzwith mock as None:
  passzwith mock as (None):
  pass�r�rs r�testAssignmentToNoneErrorz)FailureTestCase.testAssignmentToNoneError�s$���$�$�%A�B��$�$�
�	rc�H�|jd�|jd�y)Nzwith mock as None,:
  passzwith mock as (None,):
  passr�rs r�,testAssignmentToTupleOnlyContainingNoneErrorz<FailureTestCase.testAssignmentToTupleOnlyContainingNoneError�s$���$�$�%B�C��$�$�
�	rc�&�|jd�y)Nz%with mock as (foo, None, bar):
  passr�rs r�(testAssignmentToTupleContainingNoneErrorz8FailureTestCase.testAssignmentToTupleContainingNoneError�s���$�$�
�	rc����Gd�dt����fd�}�jt|��j�jd�y)Nc��eZdZd�Zd�Zy)�4FailureTestCase.testEnterThrows.<locals>.EnterThrowsc��td��)NzEnter threw�r;rs rrz>FailureTestCase.testEnterThrows.<locals>.EnterThrows.__enter__�s
��"�=�1�1rc��yr%r)�rrs  rrz=FailureTestCase.testEnterThrows.<locals>.EnterThrows.__exit__�r]rN�rr r!rrr)rr�EnterThrowsr��s��
2�
rr�c�\����}d�_|5�_	ddd�y#1swYyxYwr%rS)�ctr�rs ��r�shouldThrowz4FailureTestCase.testEnterThrows.<locals>.shouldThrow�s0�����B��D�H��
�t�x��
�
�
�s�"�+)rerVr;�assertEqualrT)rr�r�s` @r�testEnterThrowszFailureTestCase.testEnterThrows�s:���	�&�	�	�
	
���,��4�������4�(rc�Z��Gd�dt���fd�}|jt|�y)Nc��eZdZd�Zd�Zy)�2FailureTestCase.testExitThrows.<locals>.ExitThrowsc��yr%r)rs rrz<FailureTestCase.testExitThrows.<locals>.ExitThrows.__enter__�s��rc��td��)N�*r�r�s  rrz;FailureTestCase.testExitThrows.<locals>.ExitThrows.__exit__�s
��"�2�&�&rNr�r)rr�
ExitThrowsr��s��
�
'rr�c�@����5	ddd�y#1swYyxYwr%r))r�s�rr�z3FailureTestCase.testExitThrows.<locals>.shouldThrow�s �����
��
�
�
�s��)rerVr;)rr�r�s  @r�testExitThrowszFailureTestCase.testExitThrows�s&���	'��	'�
	�	
���,��4rN)
rr r!rXrhrprxr�r�r�r�r�r�r)rrrPrPjs8��5�
P�W�Y�H�
���

)�	5rrPc�F�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z		dd	�Z
d
�Zy)�ContextmanagerAssertionMixinc�$�td�|_y)Nztest exception)r;�TEST_EXCEPTIONrs r�setUpz"ContextmanagerAssertionMixin.setUp�s��*�+;�<��rc��|j|j�|j|j�|j	|j
d�yr%)�
assertTruer
�assertFalserr�r�r�mock_managers  r�assertInWithManagerInvariantsz:ContextmanagerAssertionMixin.assertInWithManagerInvariants�s>������1�1�2�����1�1�2�����/�/��6rc��|j|j�|j|j�|j|j|�yr%)r�r
rr�r)rr�rs   r� assertAfterWithManagerInvariantsz=ContextmanagerAssertionMixin.assertAfterWithManagerInvariants�s<������1�1�2�����0�0�1�����/�/��;rc�(�|j|d�yrC)r�r�s  r�'assertAfterWithManagerInvariantsNoErrorzDContextmanagerAssertionMixin.assertAfterWithManagerInvariantsNoError�s���-�-�l��	 rc�p�|j|j�|j|j�yr%)r�r.r�r/�r�mock_generators  r�assertInWithGeneratorInvariantsz<ContextmanagerAssertionMixin.assertInWithGeneratorInvariants�s(������.�.�/�����/�/�0rc�p�|j|j�|j|j�yr%�r�r.r/r�s  r�)assertAfterWithGeneratorInvariantsNoErrorzFContextmanagerAssertionMixin.assertAfterWithGeneratorInvariantsNoError��&������.�.�/�����.�.�/rc��|j�r%)r�rs r�raiseTestExceptionz/ContextmanagerAssertionMixin.raiseTestException�s���!�!�!rNc��|j|j�|j|j�|�>|j|jd|j
�t
|j
�}|j|jd|�|j|jd|�|j|jdd�y)N�r�)	r�r
rr�rr�r�assertIsInstance�assertIsNot)rr��exc_types   r�)assertAfterWithManagerInvariantsWithErrorzFContextmanagerAssertionMixin.assertAfterWithManagerInvariantsWithError�s�������1�1�2�����0�0�1������\�3�3�A�6��8K�8K�L��D�/�/�0�H�����/�/��2�H�=����l�4�4�Q�7��B�����/�/��2�D�9rc�p�|j|j�|j|j�yr%r�r�s  r�+assertAfterWithGeneratorInvariantsWithErrorzHContextmanagerAssertionMixin.assertAfterWithGeneratorInvariantsWithError�r�rr%)rr r!r�r�r�r�r�r�r�r�r�r)rrr�r��s5��=�7�
<�
 �1�0�"�<@�
:�0rr�c�6�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	y)	�NonexceptionalTestCasec�D�t�5	ddd�y#1swYyxYwr%�r3rs r�testInlineGeneratorSyntaxz0NonexceptionalTestCase.testInlineGeneratorSyntax�s ��
*�
,�	��	�	�	�s��c�j�t�}|5	ddd�|j|�y#1swY�xYwr%)r3r�)rr2s  r�testUnboundGeneratorz+NonexceptionalTestCase.testUnboundGenerator�s3��,�.��
�	��	��4�4�T�:�	�	�s�)�2c��t�5}|j|�ddd�|j�y#1swY�xYwr%�r3r�r��rrTs  r�testInlineGeneratorBoundSyntaxz5NonexceptionalTestCase.testInlineGeneratorBoundSyntax�s=��
*�
,�	6���0�0��5�	6�	
�6�6�s�;�	6�	6�s	�7�Ac��d}t�5}|j|�ddd�|j|�y#1swY�xYwr%r�r�s  r�*testInlineGeneratorBoundToExistingVariablezANonexceptionalTestCase.testInlineGeneratorBoundToExistingVariable�s@����
*�
,�	6���0�0��5�	6��6�6�s�;�	6�	6�s	�9�Ac��t�5|_|j|j�ddd�|j|j�y#1swY�%xYwr%)r3rTr�r�rs r�(testInlineGeneratorBoundToDottedVariablez?NonexceptionalTestCase.testInlineGeneratorBoundToDottedVariablesE��
*�
,�	;����0�0����:�	;��6�6�t�x�x�@�	;�	;�s�!A�Ac���t�}|5}|j|�|j|�ddd�|j�|j	|�y#1swY�,xYwr%)r3r�r�r�r�)rr2rTs   r�testBoundGeneratorz)NonexceptionalTestCase.testBoundGenerators^��,�.��
�	5�S��0�0��5��.�.�t�4�	5�	
�6�6�s�;��4�4�T�:�		5�	5�s�#A�A$c���t�}|5}t�}|5}|j|�|j|�|j|�|j|�ddd�|j|�|j	�|j|�|j|�ddd�|j|�|j	�y#1swY�xxYw#1swY�8xYwr%)r3r�r�r�r�)r�mock_arT�mock_b�bars     r�testNestedSingleStatementsz1NonexceptionalTestCase.testNestedSingleStatementss���.�0��
�
	6�s�2�4�F��
:�3��2�2�6�:��2�2�6�:��4�4�S�9��4�4�S�9�	
:�

�8�8��@��:�:�3�?��.�.�v�6��0�0��5�
	6�	
�4�4�V�<��6�6�s�;�
:�
:��
	6�
	6�s$�
C"�AC�AC"�C	�C"�"C+N)
rr r!r�r�r�r�r�r�r�r)rrr�r��s&���;�<�<�A�
;�<rr�c�6�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	y)	�NestedNonexceptionalTestCasec�V�tt��5	ddd�y#1swYyxYwr%�r5r3rs r�"testSingleArgInlineGeneratorSyntaxz?NestedNonexceptionalTestCase.testSingleArgInlineGeneratorSyntax#s&��
�1�3�
4�	��	�	�	�s��(c��t�}t|�5}|j|�ddd�|j|�y#1swY�xYwr%�r3r5r�r��r�mrTs   r�testSingleArgBoundToNonTuplez9NestedNonexceptionalTestCase.testSingleArgBoundToNonTuple'sF��)�+���A�Y�	2�#��.�.�q�1�	2��4�4�Q�7�	2�	2���A�Ac��t�}t|�5}|j|�ddd�|j|�y#1swY�xYwr%r�r�s   r�2testSingleArgBoundToSingleElementParenthesizedListzONestedNonexceptionalTestCase.testSingleArgBoundToSingleElementParenthesizedList/sF��)�+���A�Y�	2�3��.�.�q�1�	2��4�4�Q�7�	2�	2�r�c�6�d�}|jt|�y)Nc�\�tt��5\}}	ddd�y#1swYyxYwr%r�)rTr�s  r�shouldThrowValueErrorziNestedNonexceptionalTestCase.testSingleArgBoundToMultipleElementTupleError.<locals>.shouldThrowValueError8s,���5�7�8�
�J�S�#��
�
�
�s�"�+)rV�
ValueError)rr�s  r�-testSingleArgBoundToMultipleElementTupleErrorzJNestedNonexceptionalTestCase.testSingleArgBoundToMultipleElementTupleError7s��	�	
���*�&;�<rc���t�}t|�}|5|j|�|j|�ddd�|j|�|j|�y#1swY�,xYwr%�r3rJr�r�)rr*�mock_nesteds   r�testSingleArgUnboundz1NestedNonexceptionalTestCase.testSingleArgUnbound=sj��;�=�� �!4�5��
�	<��.�.�/B�C��.�.�{�;�	<�	
�4�4�5H�I��4�4�[�A�		<�	<�s�#A&�&A/c��t�}t�}t�}t|||�}|5|j|�|j|�|j|�|j|�ddd�|j|�|j|�|j|�|j|�y#1swY�NxYwr%r�)rr��n�or�s     r�testMultipleArgUnboundz3NestedNonexceptionalTestCase.testMultipleArgUnboundFs���)�+��)�+��)�+�� ��A�q�)��
�	<��.�.�q�1��.�.�q�1��.�.�q�1��.�.�{�;�		<�
	
�4�4�Q�7��4�4�Q�7��4�4�Q�7��4�4�[�A�	<�	<�s�AC�C	c��tt�t�t��}|5\}}}|j|�|j|�|j|�|j|�ddd�|j	�|j	�|j	�|j|�y#1swY�NxYwr%)rJr3r�r�r�r�)rr�r�r�r�s     r�testMultipleArgBoundz1NestedNonexceptionalTestCase.testMultipleArgBoundUs��� �!>�!@�)�+�-J�-L�N��
�	<�I�Q��1��0�0��3��0�0��3��0�0��3��.�.�{�;�		<�
	
�6�6�q�9��6�6�q�9��6�6�q�9��4�4�[�A�	<�	<�s�A	B>�>CN)
rr r!r�r�r�r�r�r�r�r)rrr�r�!s(���8�8�=�B�
B�Brr�c�T�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy
)�ExceptionalTestCasec����t����fd�}�jt|��j���j	�j
�y)Nc����5�_�j���j�j��j�ddd�y#1swYyxYwr%)�resourcer�r�r���cmrs��rr�z;ExceptionalTestCase.testSingleResource.<locals>.shouldThrowfsK����
*�t�}��2�2�2�6��4�4�T�]�]�C��'�'�)�
*�
*�
*�s�AA�A)r3rVr;r�r�r��rr�r�s` @r�testSingleResourcez&ExceptionalTestCase.testSingleResourcedsB���
*�
,��	*�
	
���,��4��6�6�r�:��8�8����Grc����t����fd�}�jt|��j�t�y)Nc�H���5�_ddzddd�y#1swYyxYw�Nr�r)r�r�s��rr�z@ExceptionalTestCase.testExceptionNormalized.<locals>.shouldThrowqs(����
�t�}��Q��
�
�
�s��!)r3rV�ZeroDivisionErrorr�r�s` @r�testExceptionNormalizedz+ExceptionalTestCase.testExceptionNormalizedos4���
*�
,��	�
	
���+�[�9��6�6�r�;L�Mrc�����t��t�����fd�}�jt|��j���j���j	�j
��j	�j�y)Nc�F���5�_�5�_�j���j���j�j��j�j��j	�ddd�ddd�y#1swY�xYw#1swYyxYwr%�rTr�r�r�r��r�r�rs���rr�zCExceptionalTestCase.testNestedSingleStatements.<locals>.shouldThrow|s�����
.�4�8��.�t�x��6�6�v�>��6�6�v�>��8�8����B��8�8����B��+�+�-�.�
.�
.�.�.��
.�
.�s#�B�A.B�:B�B	�B�B )r3rVr;r�r�rTr��rr�r�r�s` @@rr�z.ExceptionalTestCase.testNestedSingleStatementsysj���.�0��.�0��	.�	
���,��4��6�6�v�>��6�6�v�>��8�8����B��8�8����Brc�Z�����t��t��t��������fd�}�jt|��j	���j	���j	���j�j��j�j�y)Nc�@���5\�_�_�j���j���j���j�j��j�j��j	�ddd�y#1swYyxYwr%)�
resource_a�
resource_br�r�r�)�cm_a�cm_br�rs����rr�zOExceptionalTestCase.testMultipleResourcesInSingleStatement.<locals>.shouldThrow�s�����
*� B���$�/��2�2�4�8��2�2�4�8��2�2�;�?��4�4�T�_�_�E��4�4�T�_�_�E��'�'�)�

*�
*�
*�s�BB�B)r3rJrVr;r�r�r
r)rr�rr
r�s` @@@r�&testMultipleResourcesInSingleStatementz:ExceptionalTestCase.testMultipleResourcesInSingleStatement�s����,�.��,�.�� ��t�,��	*�	
���,��4��6�6�t�<��6�6�t�<��6�6�{�C��8�8����I��8�8����Irc�����t��t��d�_���fd�}�jt|��j	���j�j��j�jd��j�j��j�j��j�jd�y)Nc�����5�_�j���j�j��j��5�_	ddd�ddd�y#1swY�xYw#1swYyxYwr%)rTr�r�r�r�rs���rr�zPExceptionalTestCase.testNestedExceptionBeforeInnerStatement.<locals>.shouldThrow�so����
�4�8��2�2�6�:��4�4�T�X�X�>��'�'�)���t�x���	
�
����	
�
�s$�AA,�A �A,� A)	�%A,�,A5)r3r�rVr;r�r�rTr�r�r
rrrs` @@r�'testNestedExceptionBeforeInnerStatementz;ExceptionalTestCase.testNestedExceptionBeforeInnerStatement�s����.�0��.�0�����	�	
���,��4��6�6�v�>��8�8����B�	
������4�(�����,�,�-�����+�+�,�����)�)�4�0rc�����t��t�����fd�}�jt|��j���j	���j�j��j�j�y)Nc�F���5�_�5�_�j���j���j�j��j�j�ddd��j	�ddd�y#1swY�"xYw#1swYyxYwr%rrs���rr�zOExceptionalTestCase.testNestedExceptionAfterInnerStatement.<locals>.shouldThrow�s�����
*�4�8��C�t�x��6�6�v�>��6�6�v�>��8�8����B��8�8����B�	C�
�'�'�)�

*�
*�C�C��
*�
*�s#�B�AB�*B�B	�B�B )	r3rVr;r�r�r�rTr�r�rs` @@r�&testNestedExceptionAfterInnerStatementz:ExceptionalTestCase.testNestedExceptionAfterInnerStatement�sj���.�0��.�0��	*�	
���,��4��6�6�v�>��4�4�V�<��8�8����B��6�6�t�x�x�@rc���td����fd�}|jtd�5|�ddd�y#1swYyxYw)Nc3�K�d��y�wr%r)r)rrr�z8ExceptionalTestCase.testRaisedStopIteration1.<locals>.cm��	�������c�B����5td��#1swYyxYw�N�	from with��
StopIteration�r�s�rr�zAExceptionalTestCase.testRaisedStopIteration1.<locals>.shouldThrow��#�����
1�#�K�0�0�
1�
1����r)rrfrr�s  @r�testRaisedStopIteration1z,ExceptionalTestCase.testRaisedStopIteration1�sF���	�	�
�	�	1��
#�
#�M�;�
?�	��M�	�	�	�s	�:�Ac���Gd�dt���fd�}|jtd�5|�ddd�y#1swYyxYw)Nc��eZdZd�Zd�Zy)�8ExceptionalTestCase.testRaisedStopIteration2.<locals>.cmc��yr%r)rs rrzBExceptionalTestCase.testRaisedStopIteration2.<locals>.cm.__enter__�r]rc��yr%r)rs    rrzAExceptionalTestCase.testRaisedStopIteration2.<locals>.cm.__exit__�r]rNr�r)rrr�r$����
�
rr�c�B����5td��#1swYyxYwrrrs�rr�zAExceptionalTestCase.testRaisedStopIteration2.<locals>.shouldThrow�rr r)rerfrr�s  @r�testRaisedStopIteration2z,ExceptionalTestCase.testRaisedStopIteration2�s@���	��	�	1��
#�
#�M�;�
?�	��M�	�	�	�s	�=�Ac���td����fd�}|jt�5|�ddd�y#1swYyxYw)Nc3�K�d��y�wr%r)r)rrr�z8ExceptionalTestCase.testRaisedStopIteration3.<locals>.cm�rrc�T����5ttg���#1swYyxYwr%)�next�iterrs�rr�zAExceptionalTestCase.testRaisedStopIteration3.<locals>.shouldThrow�s&�����
%��4��8�n�$�
%�
%�s��')rrVrr�s  @r�testRaisedStopIteration3z,ExceptionalTestCase.testRaisedStopIteration3�sF���
�	�
�	�	%��
�
�}�
-�	��M�	�	�	�s	�9�Ac�T��td����fd�}|jt|�y)Nc3�K�d��y�wr%r)r)rrr�z8ExceptionalTestCase.testRaisedGeneratorExit1.<locals>.cm�rrc�B����5td��#1swYyxYwr��
GeneratorExitrs�rr�zAExceptionalTestCase.testRaisedGeneratorExit1.<locals>.shouldThrow�rr )rrVr4r�s  @r�testRaisedGeneratorExit1z,ExceptionalTestCase.testRaisedGeneratorExit1�s,���	�	�
�	�	1�	
���-��5rc�Z��Gd�dt���fd�}|jt|�y)Nc��eZdZd�Zd�Zy)�8ExceptionalTestCase.testRaisedGeneratorExit2.<locals>.cmc��yr%r)rs rrzBExceptionalTestCase.testRaisedGeneratorExit2.<locals>.cm.__enter__�r]rc��yr%r)rs    rrzAExceptionalTestCase.testRaisedGeneratorExit2.<locals>.cm.__exit__�r]rNr�r)rrr�r8�r'rr�c�B����5td��#1swYyxYwrr3rs�rr�zAExceptionalTestCase.testRaisedGeneratorExit2.<locals>.shouldThrowrr )rerVr4r�s  @r�testRaisedGeneratorExit2z,ExceptionalTestCase.testRaisedGeneratorExit2�s&���	�&�	�	1�	
���-��5rc����Gd�dt����fd�}|���fd�}�jt|���fd�}�jt|�y)Nc��eZdZd�Zd�Zd�Zy)�0ExceptionalTestCase.testErrorsInBool.<locals>.cmc�6��G�fd�d�}|�|_y)Nc���eZdZ�fd�Zy)�GExceptionalTestCase.testErrorsInBool.<locals>.cm.__init__.<locals>.Boolc�����Sr%r))r�bool_conversions �r�__bool__zPExceptionalTestCase.testErrorsInBool.<locals>.cm.__init__.<locals>.Bool.__bool__s���.�0�0rN)rr r!rE)rDs�r�BoolrB
s���1rrF��exit_result)rrDrFs ` rrz9ExceptionalTestCase.testErrorsInBool.<locals>.cm.__init__s���1�1�$(�6�� rc��y)N�r)rs rrz:ExceptionalTestCase.testErrorsInBool.<locals>.cm.__enter__s��rc��|jSr%rG�r�a�b�cs    rrz9ExceptionalTestCase.testErrorsInBool.<locals>.cm.__exit__s���'�'�'rNrHr)rrr�r?s��
*�

�
(rr�c�d���d��5�jd�ddd�y#1swYyxYw)Nc��yrr)r)rr�<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�jd�ddd�y#1swYyxYw)Nc��yr
r)r)rrrRzKExceptionalTestCase.testErrorsInBool.<locals>.falseAsBool.<locals>.<lambda>rSrzShould raiserUr�s��r�falseAsBoolz9ExceptionalTestCase.testErrorsInBool.<locals>.falseAsBools,����M�"�
*��	�	�.�)�
*�
*�
*�rYc�d���d��5�jd�ddd�y#1swYyxYw)Nc��ddzSrr)r)rrrRzJExceptionalTestCase.testErrorsInBool.<locals>.failAsBool.<locals>.<lambda>!s
��A�q�D�rrTrUr�s��r�
failAsBoolz8ExceptionalTestCase.testErrorsInBool.<locals>.failAsBool rXrY)rerV�AssertionErrorr)rrWr\r_r�s`   @r�testErrorsInBoolz$ExceptionalTestCase.testErrorsInBoolsJ���		(��		(�	1�	��	*�	
���.�+�6�	1�	
���+�Z�8rN)rr r!r�rr�rrrr!r)r/r5r<rar)rrr�r�csC��	H�N�C�"J�&1�*A�"�
��
6�6�9rr�c�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�NonLocalFlowControlTestCasec��d}	|dz
}t�5|dz
}	ddd�|j|d�y#1swYnxYw|dz
}�C)Nrr��
�d��r3r��r�counters  r�
testWithBreakz)NonLocalFlowControlTestCase.testWithBreak(s\������q�L�G�.�0�
��2�
���
�	
����"�%�	
�
��
�s�N�G�s�5�>c��d}	|dz
}|dkDrnt�5|dz
}	ddd��&|j|d�y#1swYnxYw|dz
}�J)Nrr�r�rerf�rhris  r�testWithContinuez,NonLocalFlowControlTestCase.testWithContinue2sk������q�L�G���{��.�0�
��2�
���
�
�	
����"�%�	
�
��
�s�N�G�s	�<�Ac�8�d�}|j|�d�y)Nc�l�d}	|dz
}t�5|dz
}|cddd�S#1swYnxYw|dz
}�2)Nrr�rerfr�)rjs rrTz7NonLocalFlowControlTestCase.testWithReturn.<locals>.foo?sJ���G���1���2�4�#��r�M�G�"�#�#�#���3���s�$�-rg)r�r�s  r�testWithReturnz*NonLocalFlowControlTestCase.testWithReturn>s��	�	
������#rc�R�d�}t|��}|j|ddg�y)Nc3�ZK�t�5d��d��ddd�y#1swYyxYw�w)Nrm�
r�r)rr�genz6NonLocalFlowControlTestCase.testWithYield.<locals>.genJs*����.�0�
�����
�
�
�s�+�	�	+�(�+rmrt)�listr�)rru�xs   r�
testWithYieldz)NonLocalFlowControlTestCase.testWithYieldIs(��	�
���K������R��H�%rc���d}	|dz
}t�5|dz
}t�#1swYnxYw|dz
}|jd�y#t$r|j|d�YywxYw)Nrr�rerfzDidn't raise RuntimeErrorrg)r3r;rVr�ris  r�
testWithRaisez)NonLocalFlowControlTestCase.testWithRaiseQsu����		3��q�L�G�.�0�
#��2�
��"�"�
#�
#��
�s�N�G�
�I�I�1�2���	*����W�b�)�	*�s�A��(�A�A �A N)rr r!rkrnrqrxrzr)rrrcrc&s��&�
&�	$�&�3rrcc��eZdZd�Zd�Zd�Zy)�AssignmentTargetTestCasec�t�dgd�i}t�5|dd<|jt|j��dg�|j|ddjt
�ddd�t�5t|j
��dd<|jt|j��dg�|j|ddjt
�ddd�t�5|d<t|j��}|j�|j|ddg�ddd�Gd�d�}|�}t�5|_|jt|d�d�ddd�y#1swY��#xYw#1swY��xYw#1swY�hxYw#1swYyxYw)	Nr��rr�r�rr�c��eZdZy)�;AssignmentTargetTestCase.testSingleComplexTarget.<locals>.CNrlr)rr�Cr�m��rr�rTT)
r3r�rv�keysrr,�values�sortrT�hasattr)r�targetsr�r��blahs     r�testSingleComplexTargetz0AssignmentTargetTestCase.testSingleComplexTargetas|���i�.��
*�
,�	D���
�1�
����T�'�,�,�.�1�A�3�7����W�Q�Z��]�4�4�l�C�	D�+�
,�	D��W�^�^�5E�0F�q�0I�!�0L����T�'�,�,�.�1�A�3�7����W�Q�Z��]�4�4�l�C�	D�+�
,�	+���
������'�D��I�I�K����T�A�q�6�*�	+�	�
��s��
*�
,�	9������W�T�5�1�4�8�	9�	9�	D�	D��	D�	D��	+�	+��	9�	9�s2�AF	�:A.F�:AF"�"F.�	F�F�"F+�.F7c�v�Gd�d�}dgd�i}|�5\|dd<|dd<|dd<|j|dgd�i�ddd�|�5\t|j��dd<t|j��dd<t|j��dd<|j|dgd�i�ddd�|�5\|d<|d<|d	<|j|ddd	d��ddd�Gd
�d�}|�}|�5\|_|_|_|j|jd�|j|jd�|j|j
d	�ddd�y#1swY��GxYw#1swY��xYw#1swY��xYw#1swYyxYw)Nc��eZdZd�Zd�Zy)�>AssignmentTargetTestCase.testMultipleComplexTargets.<locals>.Cc��y)N�r�r�rJr)rs rrzHAssignmentTargetTestCase.testMultipleComplexTargets.<locals>.C.__enter__ts��rc��yr%r)�r�t�v�tbs    rrzGAssignmentTargetTestCase.testMultipleComplexTargets.<locals>.C.__exit__urSrNr�r)rrr�r�ss��/�.rr�r�r~rr�r�)rJr�r�rJc��eZdZy)�>AssignmentTargetTestCase.testMultipleComplexTargets.<locals>.BNrlr)rr�Br�}r�rr�)r�rvr��one�two�three)rr�r�r�r�s     r�testMultipleComplexTargetsz3AssignmentTargetTestCase.testMultipleComplexTargetsrs���	/�	/��i�.��
�S�	6�A�W�Q�Z��]�G�A�J�q�M�7�1�:�a�=����W�q�)�n�5�	6�
�S�	6�n�T�'�.�.�*�+�A�.�q�1�4����8H�3I�!�3L�Q�3O�QU�V]�Vd�Vd�Vf�Qg�hi�Qj�kl�Qm����W�q�)�n�5�	6�
�S�	:�8�W�Q�Z����W�Q�Z����W�!��a�&8�9�	:��
��s��
�S�	,�4�T�X�t�x������T�X�X�q�)����T�X�X�q�)����T�Z�Z��+�	,�	,�	6�	6��	6�	6��	:�	:��	,�	,�s1�-F
�A2F�$F#�A(F/�
F�F �#F,�/F8c���ttdd��5�^}}}|j|d�|j|ddg�|j|d�ddd�y#1swYyxYw)Nr��r�rJ�)r�ranger�rLs    r�testWithExtendedTargetsz0AssignmentTargetTestCase.testWithExtendedTargets�sa��
��q�!��
%�	#��!�a�����Q��"����Q��A��'����Q��"�	#�	#�	#�s�=A�A%N)rr r!r�r�r�r)rrr|r|_s��9�",�$#rr|c��eZdZd�Zd�Zy)�ExitSwallowsExceptionTestCasec��Gd�d�}	|�5ddzddd�y#1swYyxYw#t$r|jd�YywxYw)Nc��eZdZd�Zd�Zy)�SExitSwallowsExceptionTestCase.testExitTrueSwallowsException.<locals>.AfricanSwallowc��yr%r)rs rrz]ExitSwallowsExceptionTestCase.testExitTrueSwallowsException.<locals>.AfricanSwallow.__enter__�rSrc��yrr)r�s    rrz\ExitSwallowsExceptionTestCase.testExitTrueSwallowsException.<locals>.AfricanSwallow.__exit__�s��rNr�r)rr�AfricanSwallowr��s��%�5rr�r�rz,ZeroDivisionError should have been swallowed)rrV)rr�s  r�testExitTrueSwallowsExceptionz;ExitSwallowsExceptionTestCase.testExitTrueSwallowsException�sQ��	6�	6�	F��!�
��!��
�
�
�� �	F��I�I�D�E�	F�s#�.�"�.�+�.�.�A�
Ac��Gd�d�}	|�5ddzddd�|jd�y#1swY�xYw#t$rYywxYw)Nc��eZdZd�Zd�Zy)�ZExitSwallowsExceptionTestCase.testExitFalseDoesntSwallowException.<locals>.EuropeanSwallowc��yr%r)rs rrzdExitSwallowsExceptionTestCase.testExitFalseDoesntSwallowException.<locals>.EuropeanSwallow.__enter__�rSrc��yr
r)r�s    rrzcExitSwallowsExceptionTestCase.testExitFalseDoesntSwallowException.<locals>.EuropeanSwallow.__exit__�s��rNr�r)rr�EuropeanSwallowr��s��%�6rr�r�rz)ZeroDivisionError should have been raised)rVr)rr�s  r�#testExitFalseDoesntSwallowExceptionzAExitSwallowsExceptionTestCase.testExitFalseDoesntSwallowException�sT��	7�	7�	C� �"�
��!��
�

�I�I�A�B�
�
�� �	��	�s�?�3�?�<�?�	A�
AN)rr r!r�r�r)rrr�r��s��F�
Crr�c��eZdZGd�de�ZGd�de�ZGd�de�ZGd�de�Zd	�Zd
�Z	d�Z
d�Zd
�Zy)�
NestedWithc� �eZdZdd�Zd�Zd�Zy)�NestedWith.DummyNc�D�|�|}||_||_d|_d|_yr
)r�gobbler
r)rrr�s   rrzNestedWith.Dummy.__init__�s*���}����D�J� �D�K� %�D��$�D�rc�(�d|_|jSr)r
rrs rrzNestedWith.Dummy.__enter__�s�� $�D���:�:�rc�:�d|_||_|jryyr)rr?r�rNs  rrzNestedWith.Dummy.__exit__�s ��#�D��$�D�M��{�{��rr
rHr)rr�Dummyr��s��	%�	�	rr�c��eZdZd�Zy)�NestedWith.InitRaisesc��t��r%r�rs rrzNestedWith.InitRaises.__init__�s	��,�.�0rNr0r)rr�
InitRaisesr��s��0rr�c��eZdZd�Zd�Zy)�NestedWith.EnterRaisesc��t��r%r�rs rrz NestedWith.EnterRaises.__enter__�s	��<�>�1rc��yr%r)rNs  rrzNestedWith.EnterRaises.__exit__�rSrNr�r)rr�EnterRaisesr��s��1�+rr�c��eZdZd�Zd�Zy)�NestedWith.ExitRaisesc��yr%r)rs rrzNestedWith.ExitRaises.__enter__�rSrc��t��r%r�rNs  rrzNestedWith.ExitRaises.__exit__�s	��\�^�';rNr�r)rr�
ExitRaisesr��s��!�;rr�c�p�|j�5}|j�5}|j|j�|j|j�ddd�ddd�|jj�|jj�y#1swY�HxYw#1swY�LxYwr%)r�r�r
r)rrMrNs   r�testNoExceptionszNestedWith.testNoExceptions�s���
�Z�Z�\�	,�Q��
�
��	,���O�O�A�N�N�+��O�O�A�N�N�+�	,�	,�	
����
�
�&�����
�
�&�		,�	,��	,�	,�s"�B,�7B �B,� B)	�%B,�,B5c��	|j�5}|j�5	ddd�ddd�|jj�|j|j�y#1swY�HxYw#1swY�LxYw#Y�SxYwr%)r�r�r�r
r�rrMs  r�testExceptionInExprListz"NestedWith.testExceptionInExprList�ss��	�����
��D�O�O�$5�
��
�
�	
������'�����
�
�&�
�
��
�
��	��s7�B�A8�A,�A8�B�,A5	�1A8�8B�=B�Bc�h�	|j�5}|j�5|jd�ddd�ddd�|jd�|j	j
�|j	|j�y#1swY�YxYw#1swY�]xYw#t$rY�ZwxYw)Nzbody of bad with executedzRuntimeError not reraised)r�r�rVr;r�r
rr�s  r�testExceptionInEnterzNestedWith.testExceptionInEnter�s���	3�����
7��D�$4�$4�$6�
7��	�	�5�6�
7�
7�

�I�I�1�2�������'�����
�
�&�
7�
7��
7�
7���	��	�s=�B%�B�B
�B�B%�
B	�B�B"�B%�%	B1�0B1c�p�d}|jd��5}|j�5d}ddd�ddd�|jj�|j|j�|j|�|j|jdd�y#1swY�xxYw#1swY�|xYw)NFT)r�r)r�r�r�r
r�assertNotEqualr?)r�
body_executedrMs   r�testExceptionInExitzNestedWith.testExceptionInExit�s����
�
�Z�Z�t�Z�
$�	!��4�?�?�+<�	!� �M�	!�	!�������'�����
�
�&����
�&����A�J�J�q�M�4�0�	!�	!��	!�	!�s!�B,�B �B,� B)	�%B,�,B5c�<�|jd��5\}}|jd��5\}}|jd|�|jd|�|jd|�|jd|�ddd�ddd�y#1swY�xYw#1swYyxYw)N)r�r�)r)re�r�r�rer�)r�r�)r�a1�a2�b1�b2s     r�testEnterReturnsTuplez NestedWith.testEnterReturnsTuple�s���
�Z�Z�e�Z�
$�	%���R�
�Z�Z�h�Z�
'�	%�+3�B�����Q��#����Q��#����R��$����R��$�	%�	%�	%�	%��	%�	%�s#�B�AB�5B�B	�B�BN)
rr r!rer�r�r�r�r�r�r�r�r�r)rrr�r��sK�����&1�V�1�,�f�,�<�V�<�'�'�	'�1�%rr��__main__)�__doc__�
__author__�	__email__r>�unittest�collectionsr�
contextlibrrrrr*rer,r3r5rJ�TestCaserPr�r�r�r�rcr|r�r�r�mainr)rr�<module>r�sA��=��
�#�	�
���L�L�C�1�C�$��6������!�V�!�H0��0�"Q5�h�'�'�Q5�f,0�6�,0�^2<�X�.�.�0L�2<�j?B�8�#4�#4� �?B�D@9�6��8I�8I�@9�F63�(�"3�"3�63�r)#�x�0�0�)#�XC�H�$5�$5�C�2J%��"�"�J%�X�z���H�M�M�O�r