Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_code_module.cpython-311.pyc
�

�Ke#���dZddlZddlZddlmZddlmZddlmZddlm	Z	e	j
d��ZGd�d	ej��Z
ed
krej��dSdS)zCTest InteractiveConsole and InteractiveInterpreter from code module�N)�dedent)�	ExitStack)�mock)�
import_helper�codec�P�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
dS)
�TestInteractiveConsolec�j�t���|_|���dS)N)r�InteractiveConsole�console�mock_sys��selfs �?/usr/local/apps/python3/lib/python3.11/test/test_code_module.py�setUpzTestInteractiveConsole.setUps&���.�.�0�0����
�
������c�d�t��}|�|j��|�t	jdd�����|_|�t	jd����|_|�t	jd����|_t	jdtj
tj
���}|�|��|_tjtj
ur|jj
|j_|j`|j`dS)	z.Mock system environment for InteractiveConsolez
code.inputT)�createzcode.sys.stdoutzcode.sys.stderrzcode.sys)�wraps�specN)r�
addCleanup�close�
enter_contextr�patch�infunc�stdout�stderrr�sys�sysmod�
excepthook�__excepthook__�ps1�ps2)r�stack�prepatchs   rr
zTestInteractiveConsole.mock_syss������������$�$�$��)�)�$�*�\�15�+7�+7�+7�8�8����)�)�$�*�5F�*G�*G�H�H����)�)�$�*�5F�*G�*G�H�H����:�j���t�x�H�H�H���)�)�(�3�3����>�S�/�/�/�%)�[�%?�D�K�"��K�O��K�O�O�Orc�4�td��|j_|j���|�|jjd��d|j_|j���|�|jjd��dS)N�Finishedz>>> z	custom1> )�EOFErrorr�side_effectr�interact�assertEqualrr"rs r�test_ps1zTestInteractiveConsole.test_ps1#���"*�:�"6�"6�����������������&�1�1�1�%�����������������+�6�6�6�6�6rc�4�td��|j_|j���|�|jjd��d|j_|j���|�|jjd��dS)Nr'z... z	custom2> )	r(rr)rr*r+rr#r"rs r�test_ps2zTestInteractiveConsole.test_ps2+r-rc��ddtd��g|j_|j���t|jj��D]"}dd�|d��vrdS�#td���)Nz	'antioch'�r'�antioch�zno console stdout)
r(rr)rr*�listr�method_calls�join�AssertionError�r�calls  r�test_console_stderrz*TestInteractiveConsole.test_console_stderr3s���#.��H�Z�4H�4H�"I��������������1�2�2�	6�	6�D��B�G�G�D��G�,�,�,�,����-�!�!4�5�5�5rc���dtd��g|j_|j���|jjD]"}dd�|d��vrdS�#td���)N�	undefinedr'�	NameErrorr1r3zNo syntax error from console)	r(rr)rr*rr5r6r7r8s  r�test_syntax_errorz(TestInteractiveConsole.test_syntax_error<s{��#.���0D�0D�"E������������K�,�	A�	A�D��b�g�g�d�1�g�.�.�.�.����/�!�!?�@�@�@rc���dtd��g|j_tj��}||j_|j���|�	|j
��dS)Nzraise ValueError('')r')r(rr)r�Mockrr rr*�
assertTrue�called)r�hooks  r�test_sysexcepthookz)TestInteractiveConsole.test_sysexcepthookEs_��#9�$,�Z�$8�$8�#:�����y�{�{��!%����������������$�$�$�$�$rc��td��|j_|j�d���|�t
|jj��d��|jjd}|�|ddig��|j�	��td��|j_|j�d���|�t
|jj��d	��dS)
Nr'�Foo��banner�r�write)zFoo
r1��
r(rr)rr*r+�lenrr5�
reset_mock)r�banner_calls  r�test_bannerz"TestInteractiveConsole.test_bannerMs���"*�:�"6�"6��������U��+�+�+�����T�[�5�6�6��:�:�:��k�.�q�1������w�
�B�&?�@�@�@�	
���� � � �"*�:�"6�"6��������R��(�(�(�����T�[�5�6�6��:�:�:�:�:rc�v�td��|j_|j�d���|�t
|jj��d��|jjd}d}|�|d|fig��|j�	��td��|j_|j�dd���|�t
|jj��d��|j�	��d	}td��|j_|j�d|���|�t
|jj��d��|jjd}|d
z}|�|d|fig��dS)Nr'r1rGrKr3z"now exiting InteractiveConsole...
rJ)rH�exitmsgu	bye! ζж�
rL)r�err_msg�expected�messages    r�
test_exit_msgz$TestInteractiveConsole.test_exit_msg[s���"*�:�"6�"6��������R��(�(�(�����T�[�5�6�6��:�:�:��+�*�1�-��8������7�X�K��"<�=�=�=�	
���� � � �"*�:�"6�"6��������R���4�4�4�����T�[�5�6�6��:�:�:�	
���� � � �K�	�#+�:�"6�"6��������R���9�9�9�����T�[�5�6�6��:�:�:��+�*�1�-���T�>������7�X�K��"<�=�=�=�=�=rc�
�dtd��g|j_|j���d�d�|jjD����}td��}|�	||��dS)Nz(raise ValueError('') from AttributeErrorr'r1c3�LK�|]}d�|d��V�� dS�r1r3N�r6��.0r9s  r�	<genexpr>z7TestInteractiveConsole.test_cause_tb.<locals>.<genexpr>{�2����O�O�d�����a��)�)�O�O�O�O�O�Orz�
        AttributeError

        The above exception was the direct cause of the following exception:

        Traceback (most recent call last):
          File "<console>", line 1, in <module>
        ValueError
        �
r(rr)rr*r6rr5r�assertIn�r�outputrUs   r�
test_cause_tbz$TestInteractiveConsole.test_cause_tbws���#M�$,�Z�$8�$8�#:��������������O�O�d�k�6N�O�O�O�O�O����
�
��	
�
�
�h��'�'�'�'�'rc�
�dtd��g|j_|j���d�d�|jjD����}td��}|�	||��dS)Nztry: ham
except: eggs
r'r1c3�LK�|]}d�|d��V�� dSrZr[r\s  rr^z9TestInteractiveConsole.test_context_tb.<locals>.<genexpr>�r_rah
        Traceback (most recent call last):
          File "<console>", line 1, in <module>
        NameError: name 'ham' is not defined

        During handling of the above exception, another exception occurred:

        Traceback (most recent call last):
          File "<console>", line 2, in <module>
        NameError: name 'eggs' is not defined
        r`rbs   r�test_context_tbz&TestInteractiveConsole.test_context_tb�s���#=�$,�Z�$8�$8�#:��������������O�O�d�k�6N�O�O�O�O�O���
�

�

��	
�
�
�h��'�'�'�'�'rN)�__name__�
__module__�__qualname__rr
r,r/r:r>rDrPrWrdrg�rrr	r	
s������������� 7�7�7�7�7�7�6�6�6�A�A�A�%�%�%�;�;�;�>�>�>�8(�(�(� (�(�(�(�(rr	�__main__)�__doc__r�unittest�textwrapr�
contextlibrr�test.supportr�
import_moduler�TestCaser	rh�mainrkrr�<module>rus���E�E�
�
�
�
����������� � � � � � �������&�&�&�&�&�&�#�}�"�6�*�*��J(�J(�J(�J(�J(�X�.�J(�J(�J(�Z�z����H�M�O�O�O�O�O��r