
    /hh5                     "   S SK r S SKrS SKrS SKJr  S SKJr  S SKJr  S SKJ	r	  S SKJ
r
  \
R                  " S5      r " S S	5      r\	 " S
 S\R                  \5      5       r " S S\R                  \5      r\S:X  a  \R$                  " 5         gg)    N)dedent)	ExitStack)mock)force_not_colorized_test_class)import_helpercodec                       \ rS rSrS rSrg)MockSys   c                    [        5       nU R                  UR                  5        UR                  [        R
                  " SSS95      U l        UR                  [        R
                  " S5      5      U l        UR                  [        R
                  " S5      5      U l        [        R
                  " S[        R                  [        R                  S9nUR                  U5      U l        [        R                  [        R                  L a%  U R                  R                  U R                  l        U R                  ?U R                  ?g )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)selfstackprepatchs      >/opt/python-3.13.8/usr/lib/python3.13/test/test_code_module.pymock_sysMockSys.mock_sys   s     $))$**\15+7 8))$**5F*GH))$**5F*GH::jtxxH))(3>>S///%)[[%?%?DKK"KKOKKO    )r   r   r   r   N)__name__
__module____qualname____firstlineno__r!   __static_attributes__ r#   r    r
   r
      s    r#   r
   c                   ~    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rSrg)TestInteractiveConsole!   Nc                 V    [         R                  5       U l        U R                  5         g Nr   InteractiveConsoleconsoler!   r   s    r    setUpTestInteractiveConsole.setUp%   s    ..0r#   c                 Z   [        S5      U R                  l        U R                  R	                  5         U R                  U R                  R                  S5        SU R                  l        U R                  R	                  5         U R                  U R                  R                  S5        g )NFinishedz>>> z	custom1> )EOFErrorr   side_effectr1   interactassertEqualr   r   r2   s    r    test_ps1TestInteractiveConsole.test_ps1)   n    "*:"6&1%+6r#   c                 Z   [        S5      U R                  l        U R                  R	                  5         U R                  U R                  R                  S5        SU R                  l        U R                  R	                  5         U R                  U R                  R                  S5        g )Nr6   z... z	custom2> )r7   r   r8   r1   r9   r:   r   r   r2   s    r    test_ps2TestInteractiveConsole.test_ps21   r=   r#   c                    SS[        S5      /U R                  l        U R                  R	                  5         [        U R                  R                  5       H  nSSR                  US   5      ;   d  M    g    [        S5      e)Nz	'antioch' r6   antioch   zno console stdout)
r7   r   r8   r1   r9   listr   method_callsjoinAssertionError)r   calls     r    test_console_stderr*TestInteractiveConsole.test_console_stderr9   si    #.HZ4H"I112DBGGDG,, 3 !!455r#   c                 :   SSS[        S5      /U R                  l        U R                  R	                  5         SR                  S U R                  R                   5       5      nXR                  S5      S  nUS UR                  S5       nU R                  UR                  5       SS  / S	Q5        U R                  U R                  R                  [        5        U R                  [        U R                  R                   5      [        5        U R#                  U R                  R$                  5        U R#                  U R                  R                   R&                  5        U R                  U R                  R(                  U R                  R                   5        g )
Ndef f():	    x = ?rB   r6   c              3   J   #    U  H  nS R                  US   5      v   M     g7frB   rD   NrG   .0rI   s     r    	<genexpr>;TestInteractiveConsole.test_syntax_error.<locals>.<genexpr>H   "     O6Nda))6N   !#(InteractiveConsole)
now exitingrD   )z  File "<console>", line 2rN   z	        ^zSyntaxError: invalid syntax)r7   r   r8   r1   r9   rG   r   rF   indexr:   
splitlinesassertIsr   	last_typeSyntaxErrortype
last_valueassertIsNonelast_traceback__traceback__last_excr   outputs     r    test_syntax_error(TestInteractiveConsole.test_syntax_errorB   s0   #-#.#%$,Z$8#: 	Odkk6N6NOO%;<=>6o67**,QR0 3+ 	,
 	dkk++[9d4;;112K@$++445$++00>>?dkk**DKK,B,BCr#   c                 6   S[        S5      /U R                  l        U R                  R	                  5         SR                  S U R                  R                   5       5      nXR                  S5      S  nUS UR                  S5       nU R                  UR                  5       SS  / SQ5        U R                  U R                  R                  [        5        U R                  [        U R                  R                   5      [        5        U R#                  U R                  R$                  5        U R#                  U R                  R                   R&                  5        U R                  U R                  R(                  U R                  R                   5        g )	N  1r6   rB   c              3   J   #    U  H  nS R                  US   5      v   M     g7frP   rQ   rR   s     r    rT   @TestInteractiveConsole.test_indentation_error.<locals>.<genexpr>Y   rV   rW   rX   rY   rD   )z  File "<console>", line 1z    1z#IndentationError: unexpected indent)r7   r   r8   r1   r9   rG   r   rF   rZ   r:   r[   r\   r   r]   IndentationErrorr_   r`   ra   rb   rc   rd   re   s     r    test_indentation_error-TestInteractiveConsole.test_indentation_errorV   s'   #((:*>"?Odkk6N6NOO%;<=>6o67**,QR0 33 	4 	dkk++-=>d4;;1124DE$++445$++00>>?dkk**DKK,B,BCr#   c                 2   S[        S5      /U R                  l        U R                  R	                  5         SR                  S U R                  R                   5       5      nXR                  S5      S  nXR                  S5      S-   S  nU R                  UR                  S5      U5        U R                  U R                  R                  [        5        U R                  [        U R                  R                   5      [        5        U R#                  U R                  R$                  5        U R#                  U R                  R                   R&                  5        U R                  U R                  R(                  U R                  R                   5        g )	Nu   ''r6   rB   c              3   J   #    U  H  nS R                  US   5      v   M     g7frP   rQ   rR   s     r    rT   <TestInteractiveConsole.test_unicode_error.<locals>.<genexpr>i   rV   rW   rX   
rD   zUnicodeEncodeError: )r7   r   r8   r1   r9   rG   r   rF   rZ   
assertTrue
startswithr\   r   r]   UnicodeEncodeErrorr_   r`   ra   rb   rc   rd   re   s     r    test_unicode_error)TestInteractiveConsole.test_unicode_errorf   s   #-x
/C"DOdkk6N6NOO%;<=>T*Q./0))*@A6Jdkk++-?@d4;;1124FG$++445$++00>>?dkk**DKK,B,BCr#   c                    SSSS[        S5      /U R                  l        [        R                  " 5       nXR
                  l        U R                  R                  5         UR                  5         UR                  U R
                  R                  U R
                  R                  U R
                  R                  5        U R                  U R
                  R                  [        5        U R                  [!        U R
                  R                  5      [        5        U R                  U R
                  R                  U R
                  R                  R"                  5        U R                  U R
                  R$                  U R
                  R                  5        U R'                  [(        R*                  " U R
                  R$                  5      / SQ5        g )NrM   z    raise ValueError('BOOM!')rB   zf()r6   )z#Traceback (most recent call last):
z(  File "<console>", line 1, in <module>
z!  File "<console>", line 2, in f
zValueError: BOOM!
)r7   r   r8   r   Mockr   r   r1   r9   assert_calledassert_called_withr]   r`   rb   r\   
ValueErrorr_   rc   rd   r:   	tracebackformat_exceptionr   hooks     r    test_sysexcepthook)TestInteractiveConsole.test_sysexcepthooks   s7   #-#B#%#($,Z$8	#:
 yy{!% 5 5 $ 6 6 $ : :	< 	dkk++Z8d4;;112J?dkk00$++2H2H2V2VWdkk**DKK,B,BC33DKK4H4HI L# 	$r#   c                    SSS[        S5      /U R                  l        [        R                  " 5       nXR
                  l        U R                  R                  5         UR                  5         UR                  U R
                  R                  U R
                  R                  U R
                  R                  5        U R                  U R
                  R                  [        5        U R                  [!        U R
                  R                  5      [        5        U R#                  U R
                  R                  5        U R#                  U R
                  R                  R$                  5        U R                  U R
                  R&                  U R
                  R                  5        U R)                  [*        R,                  " U R
                  R&                  5      / SQ5        g )NrM   rN   rB   r6   )z  File "<console>", line 2
z
    x = ?
z
        ^
zSyntaxError: invalid syntax
)r7   r   r8   r   rz   r   r   r1   r9   r{   r|   r]   r`   rb   r\   r^   r_   ra   rc   rd   r:   r~   r   r   s     r    test_sysexcepthook_syntax_error6TestInteractiveConsole.test_sysexcepthook_syntax_error   sB   #-#.#%$,Z$8#: yy{!% 5 5 $ 6 6 $ : :	< 	dkk++[9d4;;112K@$++445$++00>>?dkk**DKK,B,BC33DKK4H4HI L- 	.r#   c                    S[        S5      /U R                  l        [        R                  " 5       nXR
                  l        U R                  R                  5         UR                  5         UR                  U R
                  R                  U R
                  R                  U R
                  R                  5        U R                  U R
                  R                  [        5        U R                  [!        U R
                  R                  5      [        5        U R#                  U R
                  R                  5        U R#                  U R
                  R                  R$                  5        U R                  U R
                  R&                  U R
                  R                  5        U R)                  [*        R,                  " U R
                  R&                  5      / SQ5        g )Nrj   r6   )z  File "<console>", line 1
z    1
z$IndentationError: unexpected indent
)r7   r   r8   r   rz   r   r   r1   r9   r{   r|   r]   r`   rb   r\   rm   r_   ra   rc   rd   r:   r~   r   r   s     r    $test_sysexcepthook_indentation_error;TestInteractiveConsole.test_sysexcepthook_indentation_error   s9   #((:*>"?yy{!% 5 5 $ 6 6 $ : :	< 	dkk++-=>d4;;1124DE$++445$++00>>?dkk**DKK,B,BC33DKK4H4HI L5 	6r#   c                    SSS[        S5      /U R                  l        SU R                  l        U R
                  R                  5         U R                  SS0 /U R                  R                  S   5        S	R                  S
 U R                  R                   5       5      nU R                  SU5        U R                  UR                  S5      S5        U R                  SU5        U R                  SU5        g )N1/0a = 123print(a)r6   rD   write123r   rB   c              3   T   #    U  H  oS    S:X  d  M  UR                   S    v   M      g7fr   r   NargsrR   s     r    rT   WTestInteractiveConsole.test_sysexcepthook_crashing_doesnt_close_repl.<locals>.<genexpr>   '     `1IRSWX_M_		!1I   ((Error in sys.excepthook:z'int' object is not callableOriginal exception was:division by zeror7   r   r8   r   r   r1   r9   r:   r   rF   rG   r   assertIncount)r   errors     r    -test_sysexcepthook_crashing_doesnt_close_replDTestInteractiveConsole.test_sysexcepthook_crashing_doesnt_close_repl   s    #()Z*AU"V!"'9b14;;3K3KA3NO`1I1I``0%8%CDaH/7(%0r#   c                   ^ SSS[        S5      /U R                  l        SmU4S jnXR                  l        U R
                  R                  5         U R                  SS0 /U R                  R                  S	   5        S
R                  S U R                  R                   5       5      nU R                  SU5        U R                  UR                  S5      S5        U R                  SU5        U R                  SU5        g )Nr   r   r   r6   znot so fastc                     > [        T5      er.   )BaseException)r   kwargsss     r    
raise_baseSTestInteractiveConsole.test_sysexcepthook_raising_BaseException.<locals>.raise_base   s    ""r#   r   r   r   rB   c              3   T   #    U  H  oS    S:X  d  M  UR                   S    v   M      g7fr   r   rR   s     r    rT   RTestInteractiveConsole.test_sysexcepthook_raising_BaseException.<locals>.<genexpr>   r   r   r   rD   r   r   r   )r   r   r   r   s      @r    (test_sysexcepthook_raising_BaseException?TestInteractiveConsole.test_sysexcepthook_raising_BaseException   s    #()Z*AU"V	#!+'9b14;;3K3KA3NO`1I1I``0%8]3Q7/7(%0r#   c                     S/U R                   l        S nXR                  l        U R	                  [
        5         U R                  R                  5         S S S 5        g ! , (       d  f       g = f)Nr   c                      [         er.   )
SystemExit)r   r   s     r    r   ]TestInteractiveConsole.test_sysexcepthook_raising_SystemExit_gets_through.<locals>.raise_base   s    r#   )r   r8   r   r   assertRaisesr   r1   r9   )r   r   s     r    2test_sysexcepthook_raising_SystemExit_gets_throughITestInteractiveConsole.test_sysexcepthook_raising_SystemExit_gets_through   sI    #('	!+z*LL!!# +**s   A
A-c                    [        S5      U R                  l        U R                  R	                  SS9  U R                  [        U R                  R                  5      S5        U R                  R                  S   nU R                  USS0 /5        U R                  R                  5         [        S5      U R                  l        U R                  R	                  SS9  U R                  [        U R                  R                  5      S	5        g )
Nr6   Foobanner   r   r   )zFoo
rB      
r7   r   r8   r1   r9   r:   lenr   rF   
reset_mock)r   banner_calls     r    test_banner"TestInteractiveConsole.test_banner   s    "*:"6U+T[[556:kk..q1w
B&?@ 	 "*:"6R(T[[556:r#   c                    [        S5      U R                  l        U R                  R	                  SS9  U R                  [        U R                  R                  5      S5        U R                  R                  S   nSnU R                  USU40 /5        U R                  R                  5         [        S5      U R                  l        U R                  R	                  SSS9  U R                  [        U R                  R                  5      S5        U R                  R                  5         S	n[        S5      U R                  l        U R                  R	                  SUS9  U R                  [        U R                  R                  5      S5        U R                  R                  S   nUS
-   nU R                  USU40 /5        g )Nr6   rB   r   r   rD   "now exiting InteractiveConsole...
r   )r   exitmsgu	   bye! ζжrs   r   )r   err_msgexpectedmessages       r    test_exit_msg$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                     S[        S5      /U R                  l        U R                  R	                  5         SR                  S U R                  R                   5       5      n[        S5      nU R                  X!5        U R                  U R                  R                  [        5        U R                  [        U R                  R                  5      [        5        U R                  U R                  R                   U R                  R                  R"                  5        U R%                  U R                  R                   5        U R                  U R                  R&                  U R                  R                  5        g )Nz(raise ValueError('') from AttributeErrorr6   rB   c              3   J   #    U  H  nS R                  US   5      v   M     g7frP   rQ   rR   s     r    rT   7TestInteractiveConsole.test_cause_tb.<locals>.<genexpr>  rV   rW   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
        )r7   r   r8   r1   r9   rG   r   rF   r   r   r\   r   r]   r}   r_   r`   rb   rc   assertIsNotNonerd   r   rf   r   s      r    test_cause_tb$TestInteractiveConsole.test_cause_tb   s    #M$,Z$8#:Odkk6N6NOO   	h'dkk++Z8d4;;112J?dkk00$++2H2H2V2VWT[[778dkk**DKK,B,BCr#   c                     S[        S5      /U R                  l        U R                  R	                  5         SR                  S U R                  R                   5       5      n[        S5      nU R                  X!5        U R                  U R                  R                  [        5        U R                  [        U R                  R                  5      [        5        U R                  U R                  R                   U R                  R                  R"                  5        U R%                  U R                  R                   5        U R                  U R                  R&                  U R                  R                  5        g )Nztry: ham
except: eggs
r6   rB   c              3   J   #    U  H  nS R                  US   5      v   M     g7frP   rQ   rR   s     r    rT   9TestInteractiveConsole.test_context_tb.<locals>.<genexpr>  rV   rW   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
        )r7   r   r8   r1   r9   rG   r   rF   r   r   r\   r   r]   	NameErrorr_   r`   rb   rc   r   rd   r   s      r    test_context_tb&TestInteractiveConsole.test_context_tb  s    #=$,Z$8#:Odkk6N6NOO 
 
 	h'dkk++Y7d4;;112I>dkk00$++2H2H2V2VWT[[778dkk**DKK,B,BCr#   r1   )r$   r%   r&   r'   maxDiffr3   r;   r?   rJ   rg   rn   rw   r   r   r   r   r   r   r   r   r   r   r(   r)   r#   r    r+   r+   !   sa    G776D(D D$...6&	11$;>8D*Dr#   r+   c                   t    \ rS rSrS r\R                  " \R                  R                  S5      S 5       r
Srg)TestInteractiveConsoleLocalExiti,  c                 T    [         R                  SS9U l        U R                  5         g )NT)
local_exitr/   r2   s    r    r3   %TestInteractiveConsoleLocalExit.setUp.  s     ..$.?r#   z1exit() isn't defined unless there's a site modulec                    S/U R                   l        U R                  R                  SS9  U R	                  [        U R                  R                  5      S5        U R                  R                  S   nSnU R	                  USU40 /5        g )Nzexit()rB   r   r   rD   r   r   )r   r8   r1   r9   r:   r   r   rF   )r   r   r   s      r    	test_exit)TestInteractiveConsoleLocalExit.test_exit2  sx     $,*R(T[[556:++**1-87XK"<=r#   r   N)r$   r%   r&   r'   r3   unittestskipIfr   flagsno_siter   r(   r)   r#   r    r   r   ,  s2     __SYY&&([\> ]>r#   r   __main__)r   r~   r   textwrapr   
contextlibr   r   test.supportr   r   import_moduler   r
   TestCaser+   r   r$   mainr)   r#   r    <module>r      s    
       7 &""6* &  GDX.. GD  GDT>h&7&7 >" zMMO r#   