o
    g#                     @   sv   	 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	dZ
G dd dejZed	kr9e  dS dS )
    N)dedent)	ExitStack)mock)import_helpercodec                   @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )TestInteractiveConsolec                 C   s   t  | _|   d S )N)r   ZInteractiveConsoleconsolemock_sysself r   K/Users/admin/.pyenv/versions/3.10.0/lib/python3.10/test/test_code_module.pysetUp   s   
zTestInteractiveConsole.setUpc                 C   s   	 t  }| |j |tjddd| _|td| _|td| _tjdt	j
t	j
d}||| _t
jt
ju rC| jj| j_| j`| j`d S )Nz
code.inputT)Zcreatezcode.sys.stdoutzcode.sys.stderrzcode.sys)wrapsspec)r   Z
addCleanupcloseenter_contextr   Zpatchinfuncstdoutstderrr   syssysmod
excepthook__excepthook__ps1ps2)r   stackZprepatchr   r   r   r	      s   


zTestInteractiveConsole.mock_sysc                 C   sL   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
   r   r   r   test_ps1#      

zTestInteractiveConsole.test_ps1c                 C   sL   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
   r   r   r   test_ps2+   r#   zTestInteractiveConsole.test_ps2c                 C   sN   ddt dg| j_| j  t| jjD ]}dd|d v r" d S qt	d)Nz	'antioch' r   Zantioch   zno console stdout)
r   r   r   r   r    listr   method_callsjoinAssertionErrorr   callr   r   r   test_console_stderr3   s   
z*TestInteractiveConsole.test_console_stderrc                 C   sH   dt dg| j_| j  | jjD ]}dd|d v r d S qtd)NZ	undefinedr   	NameErrorr%   r&   zNo syntax error from console)	r   r   r   r   r    r   r(   r)   r*   r+   r   r   r   test_syntax_error<   s   
z(TestInteractiveConsole.test_syntax_errorc                 C   s:   dt dg| j_t }|| j_| j  | 	|j
 d S )Nzraise ValueError('')r   )r   r   r   r   ZMockr   r   r   r    Z
assertTrueZcalled)r   hookr   r   r   test_sysexcepthookE   s   
z)TestInteractiveConsole.test_sysexcepthookc                 C   s   t d| j_| jjdd | t| jjd | jjd }| |ddi g | j	  t d| j_| jjdd | t| jjd	 d S )
Nr   ZFoobanner   r   write)zFoo
r%      
r   r   r   r   r    r!   lenr   r(   Z
reset_mock)r   Zbanner_callr   r   r   test_bannerM   s   
z"TestInteractiveConsole.test_bannerc                 C   s   t d| j_| jjdd | t| jjd | jjd }d}| |d|fi g | j	  t d| j_| jjddd | t| jjd | j	  d	}t d| j_| jjd|d | t| jjd | jjd }|d
 }| |d|fi g d S )Nr   r%   r2   r6   r&   z"now exiting InteractiveConsole...
r5   )r3   Zexitmsgu	   bye! ζж
r7   )r   err_msgexpectedmessager   r   r   test_exit_msg[   s&   

z$TestInteractiveConsole.test_exit_msgc                 C   J   dt dg| j_| j  ddd | jjD }td}| 	|| d S )Nz(raise ValueError('') from AttributeErrorr   r%   c                 s       | ]
}d  |d V  qdS r%   r&   Nr)   .0r,   r   r   r   	<genexpr>{       z7TestInteractiveConsole.test_cause_tb.<locals>.<genexpr>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    r)   r   r(   r   ZassertInr   outputr<   r   r   r   test_cause_tbw   s   
	z$TestInteractiveConsole.test_cause_tbc                 C   r?   )Nztry: ham
except: eggs
r   r%   c                 s   r@   rA   rB   rC   r   r   r   rE      rF   z9TestInteractiveConsole.test_context_tb.<locals>.<genexpr>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
        rG   rH   r   r   r   test_context_tb   s   
z&TestInteractiveConsole.test_context_tbN)__name__
__module____qualname__r   r	   r"   r$   r-   r/   r1   r9   r>   rJ   rK   r   r   r   r   r      s    		r   __main__)r   Zunittesttextwrapr   
contextlibr   r   Ztest.supportr   import_moduler   ZTestCaser   rL   mainr   r   r   r   <module>   s    
 