
    ;e#                         	 d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlmZ  ej	        d          Z
 G d dej                  Zed	k    r ej                     dS dS )
    N)dedent)	ExitStack)mock)import_helpercodec                   P    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S )TestInteractiveConsolec                 j    t                                           | _        |                                  d S )N)r   InteractiveConsoleconsolemock_sysselfs    ,/usr/lib/python3.11/test/test_code_module.pysetUpzTestInteractiveConsole.setUp   s&    ..00    c                 f   	 t                      }|                     |j                   |                    t	          j        dd                    | _        |                    t	          j        d                    | _        |                    t	          j        d                    | _        t	          j        dt          j
        t          j
                  }|                    |          | _        t          j        t          j        u r| j        j        | j        _        | j        `| j        `d S )Nz
code.inputT)createzcode.sys.stdoutzcode.sys.stderrzcode.sys)wrapsspec)r   
addCleanupcloseenter_contextr   patchinfuncstdoutstderrr   syssysmod
excepthook__excepthook__ps1ps2)r   stackprepatchs      r   r   zTestInteractiveConsole.mock_sys   s    8$$$))$*\15+7 +7 +7 8 8))$*5F*G*GHH))$*5F*G*GHH:jtxHHH))(33>S///%)[%?DK"KOKOOOr   c                 4   t          d          | j        _        | j                                         |                     | j        j        d           d| j        _        | j                                         |                     | j        j        d           d S )NFinishedz>>> z	custom1> )EOFErrorr   side_effectr   interactassertEqualr   r"   r   s    r   test_ps1zTestInteractiveConsole.test_ps1#       "*:"6"6&111%+66666r   c                 4   t          d          | j        _        | j                                         |                     | j        j        d           d| j        _        | j                                         |                     | j        j        d           d S )Nr'   z... z	custom2> )	r(   r   r)   r   r*   r+   r   r#   r"   r   s    r   test_ps2zTestInteractiveConsole.test_ps2+   r-   r   c                    ddt          d          g| j        _        | j                                         t          | j        j                  D ]"}dd                    |d                   v r d S #t          d          )Nz	'antioch' r'   antioch   zno console stdout)
r(   r   r)   r   r*   listr   method_callsjoinAssertionErrorr   calls     r   test_console_stderrz*TestInteractiveConsole.test_console_stderr3   s    #.HZ4H4H"I122 	6 	6DBGGDG,,,, - !!4555r   c                     dt          d          g| j        _        | j                                         | j        j        D ]"}dd                    |d                   v r d S #t          d          )N	undefinedr'   	NameErrorr1   r3   zNo syntax error from console)	r(   r   r)   r   r*   r   r5   r6   r7   r8   s     r   test_syntax_errorz(TestInteractiveConsole.test_syntax_error<   s{    #.0D0D"EK, 	A 	ADbggd1g.... / !!?@@@r   c                     dt          d          g| j        _        t          j                    }|| j        _        | j                                         | 	                    |j
                   d S )Nzraise ValueError('')r'   )r(   r   r)   r   Mockr   r    r   r*   
assertTruecalled)r   hooks     r   test_sysexcepthookz)TestInteractiveConsole.test_sysexcepthookE   s_    #9$,Z$8$8#:y{{!%$$$$$r   c                    t          d          | j        _        | j                            d           |                     t          | j        j                  d           | j        j        d         }|                     |ddi g           | j        	                                 t          d          | j        _        | j                            d           |                     t          | j        j                  d	           d S )
Nr'   Foobanner   r   write)zFoo
r1      
r(   r   r)   r   r*   r+   lenr   r5   
reset_mock)r   banner_calls     r   test_bannerz"TestInteractiveConsole.test_bannerM   s    "*:"6"6U+++T[566:::k.q1w
B&?@@@ 	   "*:"6"6R(((T[566:::::r   c                 v   t          d          | j        _        | j                            d           |                     t          | j        j                  d           | j        j        d         }d}|                     |d|fi g           | j        	                                 t          d          | j        _        | j                            dd           |                     t          | j        j                  d           | j        	                                 d	}t          d          | j        _        | j                            d|           |                     t          | j        j                  d           | j        j        d         }|d
z   }|                     |d|fi g           d S )Nr'   r1   rG   rK   r3   z"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7XK"<=== 	   "*:"6"6R444T[566::: 	   K 	 #+:"6"6R999T[566:::+*1-T>7XK"<=====r   c                 
   dt          d          g| j        _        | j                                         d                    d | j        j        D                       }t          d          }| 	                    ||           d S )Nz(raise ValueError('') from AttributeErrorr'   r1   c              3   L   K   | ]}d                      |d                   V   dS r1   r3   Nr6   .0r9   s     r   	<genexpr>z7TestInteractiveConsole.test_cause_tb.<locals>.<genexpr>{   2      OOda))OOOOOOr   z
        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(   r   r)   r   r*   r6   r   r5   r   assertInr   outputrU   s      r   test_cause_tbz$TestInteractiveConsole.test_cause_tbw   s    #M$,Z$8$8#:OOdk6NOOOOO    	h'''''r   c                 
   dt          d          g| j        _        | j                                         d                    d | j        j        D                       }t          d          }| 	                    ||           d S )Nztry: ham
except: eggs
r'   r1   c              3   L   K   | ]}d                      |d                   V   dS rZ   r[   r\   s     r   r^   z9TestInteractiveConsole.test_context_tb.<locals>.<genexpr>   r_   r   ah  
        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`   rb   s      r   test_context_tbz&TestInteractiveConsole.test_context_tb   s    #=$,Z$8$8#:OOdk6NOOOOO 
 
 
 	h'''''r   N)__name__
__module____qualname__r   r   r,   r/   r:   r>   rD   rP   rW   rd   rg    r   r   r	   r	      s             7 7 77 7 76 6 6A A A% % %; ; ;> > >8( ( ( ( ( ( ( (r   r	   __main__)r   unittesttextwrapr   
contextlibr   r   test.supportr   import_moduler   TestCaser	   rh   mainrk   r   r   <module>rt      s    E 



                          & & & & & & #}"6**J( J( J( J( J(X. J( J( J(Z zHMOOOOO r   