
    daf#                         d Z 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                          yy)zCTest InteractiveConsole and InteractiveInterpreter from code module    N)dedent)	ExitStack)mock)import_helpercodec                   N    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y)TestInteractiveConsolec                 V    t         j                         | _        | j                          y )N)r   InteractiveConsoleconsolemock_sysselfs    0/root/Python-3.12.4/Lib/test/test_code_module.pysetUpzTestInteractiveConsole.setUp   s    ..0    c                    t               }| j                  |j                         |j                  t	        j
                  dd            | _        |j                  t	        j
                  d            | _        |j                  t	        j
                  d            | _        t	        j
                  dt        j                  t        j                        }|j                  |      | _        t        j                  t        j                  u r%| j                  j                  | j                  _        | j                  `| j                  `y)	z.Mock system environment for InteractiveConsolez
code.inputT)createzcode.sys.stdoutzcode.sys.stderrzcode.sys)wrapsspecN)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     $))$**\15+7 8))$**5F*GH))$**5F*GH::jtxxH))(3>>S///%)[[%?%?DKK"KKOKKOr   c                 Z   t        d      | j                  _        | j                  j	                          | j                  | j                  j                  d       d| j                  _        | j                  j	                          | j                  | j                  j                  d       y )NFinishedz>>> z	custom1> )EOFErrorr   side_effectr   interactassertEqualr   r"   r   s    r   test_ps1zTestInteractiveConsole.test_ps1#   n    "*:"6&1%+6r   c                 Z   t        d      | j                  _        | j                  j	                          | j                  | j                  j                  d       d| j                  _        | j                  j	                          | j                  | j                  j                  d       y )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                  j	                          t        | j                  j                        D ]  }ddj                  |d         v s y  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   sn    #.HZ4H"I112 	6DBGGDG,,	6 !!455r   c                     dt        d      g| j                  _        | j                  j	                          | j
                  j                  D ]  }ddj                  |d         v s y  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<   si    #.0D"EKK,, 	ADbggd1g..	A !!?@@r   c                     dt        d      g| j                  _        t        j                         }|| j
                  _        | j                  j                          | j                  |j                         y )Nzraise ValueError('')r'   )r(   r   r)   r   Mockr   r    r   r*   
assertTruecalled)r   hooks     r   test_sysexcepthookz)TestInteractiveConsole.test_sysexcepthookE   sR    #9$,Z$8#:yy{!%$r   c                 (   t        d      | j                  _        | j                  j	                  d       | j                  t        | j                  j                        d       | j                  j                  d   }| j                  |ddi g       | j                  j                          t        d      | j                  _        | j                  j	                  d       | j                  t        | j                  j                        d	       y )
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U+T[[556:kk..q1w
B&?@ 	 "*:"6R(T[[556:r   c                    t        d      | j                  _        | j                  j	                  d       | j                  t        | j                  j                        d       | j                  j                  d   }d}| j                  |d|fi g       | j                  j                          t        d      | j                  _        | j                  j	                  dd       | j                  t        | j                  j                        d       | j                  j                          d	}t        d      | j                  _        | j                  j	                  d|       | j                  t        | j                  j                        d       | j                  j                  d   }|d
z   }| j                  |d|fi g       y )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[   sk   "*:"6R(T[[556:++**1-87XK"<= 	 "*:"6R4T[[556: 	 K 	 #+:"6R9T[[556:++**1-T>7XK"<=r   c                    dt        d      g| j                  _        | j                  j	                          dj                  d | j                  j                  D              }t        d      }| j                  ||       y )Nz(raise ValueError('') from AttributeErrorr'   r1   c              3   D   K   | ]  }d j                  |d           ywr1   r3   Nr6   .0r9   s     r   	<genexpr>z7TestInteractiveConsole.test_cause_tb.<locals>.<genexpr>{        Oda)O    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   sh    #M$,Z$8#:Odkk6N6NOO   	h'r   c                    dt        d      g| j                  _        | j                  j	                          dj                  d | j                  j                  D              }t        d      }| j                  ||       y )Nztry: ham
except: eggs
r'   r1   c              3   D   K   | ]  }d j                  |d           yw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
        ra   rc   s      r   test_context_tbz&TestInteractiveConsole.test_context_tb   sh    #=$,Z$8#:Odkk6N6NOO 
 
 	h'r   N)__name__
__module____qualname__r   r   r,   r/   r:   r>   rD   rP   rW   re   rh    r   r   r	   r	      s:     776A%;>8( (r   r	   __main__)__doc__r   unittesttextwrapr   
contextlibr   r   test.supportr   import_moduler   TestCaser	   ri   mainrl   r   r   <module>rv      s]    E 
      & #}""6*J(X.. J(Z zHMMO r   