
    4hh$                         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   " S S\R                  5      r " S	 S
\R                  5      rg)    N)patch)dedent)force_not_colorized)InteractiveColoredConsole)_more_linesc                       \ rS rSrS rS r\S 5       rS rS r	S r
\S 5       r\S	 5       rS
 rS rS rS rS rSrg)TestSimpleInteract   c           	         0 n[        S5      n[        USS9n[        R                  " 5       n[        R
                  " [        S5       n[        R
                  " [        SUR                  S9 n[        R                  " U5         UR                  USSS9nS S S 5        S S S 5        S S S 5        U R                  W5        WR                  5         g ! , (       d  f       N@= f! , (       d  f       NI= f! , (       d  f       NR= f)	Nz        class A:
            def foo(self):


                pass

        class B:
            def bar(self):
                pass

        a = 1
        a
        <stdin>filenameshowsyntaxerror	runsource)wrapssingler   _symbol)r   r   ioStringIOr   objectr   
contextlibredirect_stdoutpushassertFalseassert_not_called)self	namespacecodeconsolefr   r   mores           G/opt/python-3.13.8/usr/lib/python3.13/test/test_pyrepl/test_interact.pytest_multiple_statements+TestSimpleInteract.test_multiple_statements   s    	   ,I	JKKMLL24EF/LL2KwGXGXY]f&&q)<<y(<KD * Z G
 	))+	 *) ZY GFs<   %C2-C!CC!C2
CC!!
C/	+C22
D c                 @   0 n[        S5      n[        USS9n[        R                  " 5       n[        R
                  " U5         UR                  USSS9nS S S 5        U R                  W5        U R                  UR                  5       S5        g ! , (       d  f       N@= f)Nz8        b = 1
        b
        a = 1
        a
        r   r   r   r   z1
)
r   r   r   r   r   r   r   r   assertEqualgetvaluer   r   r   r    r!   r"   s         r#   test_multiple_statements_output2TestSimpleInteract.test_multiple_statements_output)   s    	   ,I	JKKM''*<<y(<KD +u- +*s   B
Bc                 Z   [        5       n[        S5      n[        R                  " 5       n[        R
                  " U5         UR                  U5        S S S 5        U R                  SUR                  5       5        U R                  SUR                  5       5        g ! , (       d  f       NO= f)NzQ        raise Exception('foobar')
        print('spam', 'eggs', sep='&')
        zException: foobarz	spam&eggs)
r   r   r   r   r   redirect_stderrr   assertInr(   assertNotIn)r   r    r   r!   s       r#   #test_multiple_statements_fail_early6TestSimpleInteract.test_multiple_statements_fail_early8   s{    +-   KKM''*d# +)1::<8ajjl3 +*s   B
B*c                 .   0 nSn[        USS9n[        R                  " 5       n[        R                  " U5         UR                  USSS9nS S S 5        U R                  W5        U R                  UR                  5       S5        g ! , (       d  f       N@= f)N r   r   r   r   )	r   r   r   r   r   r   r   r'   r(   r)   s         r#   
test_emptyTestSimpleInteract.test_emptyE   sw    	+I	JKKM''*<<y(<KD +r* +*s   B
Bc                     [        5       nSn[        R                  " US5       nUR                  U5        UR	                  5         S S S 5        g ! , (       d  f       g = f)Nprint('Hello, world!')runcode)r   r   r   r   assert_called_once)r   r    sourcemock_runcodes       r#   %test_runsource_compiles_and_runs_code8TestSimpleInteract.test_runsource_compiles_and_runs_codeO   sE    +-)\\'9-f%++- .--s   "A
Ac                     [        5       nSn[        R                  " 5       n[        R                  " U5         UR                  U5      nS S S 5        U R                  W5        g ! , (       d  f       N = f)Nr7   )r   r   r   r   r   r   r   r   r    r:   r!   results        r#   7test_runsource_returns_false_for_successful_compilationJTestSimpleInteract.test_runsource_returns_false_for_successful_compilationV   sT    +-)KKM''*&&v.F +  +*s   A$$
A2c                 *   [        5       nSn[        R                  " 5       n[        R                  " U5         UR                  U5      nS S S 5        U R                  W5        U R                  SUR                  5       5        g ! , (       d  f       N@= f)Nprint('Hello, world!'SyntaxError	r   r   r   r   r-   r   r   r.   r(   r?   s        r#   3test_runsource_returns_false_for_failed_compilationFTestSimpleInteract.test_runsource_returns_false_for_failed_compilation^   sh    +-(KKM''*&&v.F + mQZZ\2 +*s   B
Bc                 ,   [        5       nSn[        R                  " 5       n[        R                  " U5         UR                  U5      nS S S 5        U R                  W5        SnU R                  XSR                  5       5        g ! , (       d  f       NA= f)Nzdef f(x, x): ...z_
    def f(x, x): ...
             ^
SyntaxError: duplicate argument 'x' in function definitionrF   )r   r    r:   r!   r@   rs         r#   )test_runsource_show_syntax_error_location<TestSimpleInteract.test_runsource_show_syntax_error_locationh   so    +-#KKM''*&&v.F + > 	a& +*s   B
Bc                 z   [        5       nSn[        R                  " US5       nUR                  U5        UR	                  5         S S S 5        [        S5      n[        R                  " US5       nUR                  U5        UR	                  5         S S S 5        g ! , (       d  f       N[= f! , (       d  f       g = f)NrD   r   zN        match 1:
            case {0: _, 0j: _}:
                pass
        )r   r   r   r   r9   r   )r   r    r:   mock_showsyntaxerrors       r#   8test_runsource_shows_syntax_error_for_failed_compilationKTestSimpleInteract.test_runsource_shows_syntax_error_for_failed_compilationv   s    +-(\\'#459Mf% 335 6   
 \\'#459Mf% 335 65 65 65s   "B0"B,
B),
B:c                    [        5       nSn[        R                  " 5       n[        R                  " U5         [        R
                  " U5         UR                  U5      nS S S 5        S S S 5        U R                  W5        U R                  SUR                  5       5        g ! , (       d  f       NH= f! , (       d  f       NQ= f)Nz 
z,source code string cannot contain null bytes)
r   r   r   r   r   r-   r   r   r.   r(   r?   s        r#   "test_runsource_survives_null_bytes5TestSimpleInteract.test_runsource_survives_null_bytes   s    +-KKM''*J,F,Fq,I&&v.F -J* DajjlS -J,I**s#   B4B#!B4#
B1	-B44
Cc                 <   [        5       n[        S5      n[        R                  " 5       n[        R
                  " U5         UR                  U5      nS S S 5        U R                  W5        U R                  UR                  5       S5        g ! , (       d  f       N@= f)Nz:        x: int = 1
        print(__annotations__)
        z{'x': <class 'int'>}

r   r   r   r   r   r   r   r   r'   r(   r?   s        r#   test_no_active_future(TestSimpleInteract.test_no_active_future   sw    +-   KKM''*&&v.F + '?@ +*   B
Bc                 <   [        5       n[        S5      n[        R                  " 5       n[        R
                  " U5         UR                  U5      nS S S 5        U R                  W5        U R                  UR                  5       S5        g ! , (       d  f       N@= f)Nzo        from __future__ import annotations
        def g(x: int): ...
        print(g.__annotations__)
        z{'x': 'int'}
rU   r?   s        r#   test_future_annotations*TestSimpleInteract.test_future_annotations   sw    +-  
 KKM''*&&v.F + '78 +*rX   c                 H   [        5       n[        R                  " 5       n[        R                  " U5         UR                  S5      nUR                  S5      nS S S 5        U R                  W5        U R                  UR                  5       S5        g ! , (       d  f       N@= f)Nz&from __future__ import barry_as_FLUFL
zprint("black" <> 'blue')
zTrue
)	r   r   r   r   r   r   r   r'   r(   )r   r    r!   r@   s       r#   test_future_barry_as_flufl-TestSimpleInteract.test_future_barry_as_flufl   sy    +-KKM''*&&'PQF&&'GHF + 	 x0	 +*s   #B
B! N)__name__
__module____qualname____firstlineno__r$   r*   r   r0   r4   r<   rA   rG   rK   rO   rR   rV   rZ   r]   __static_attributes__r_       r#   r	   r	      sr    ,8. 
4 
4+.! 3 3 ' '6T
A91re   r	   c                   V    \ 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)TestMoreLines   c                 T    0 nSn[        USS9nU R                  [        X25      5        g )Nzif foor   r   r   r   r   r   r   r   r    s       r#   test_invalid_syntax_single_line-TestMoreLines.test_invalid_syntax_single_line   s+    	+I	JW34re   c                 T    0 nSn[        USS9nU R                  [        X25      5        g )Nr3   r   r   rj   rk   s       r#   test_empty_lineTestMoreLines.test_empty_line   s+    	+I	JW34re   c                 T    0 nSn[        USS9nU R                  [        X25      5        g )Nzfoo = 1r   r   rj   rk   s       r#   test_valid_single_statement)TestMoreLines.test_valid_single_statement   s+    	+I	JW34re   c                 f    0 n[        S5      n[        USS9nU R                  [        X25      5        g )NzF        foo = [
            1,
            2,
            3,
        ]r   r   r   r   r   r   rk   s       r#    test_multiline_single_assignment.TestMoreLines.test_multiline_single_assignment   s7    	   ,I	JW34re   c                 f    0 n[        S5      n[        USS9nU R                  [        X25      5        g )Nz?        def foo():
            '''docs'''

            return 1r   r   r   r   
assertTruer   rk   s       r#   test_multiline_single_block)TestMoreLines.test_multiline_single_block   s5    	  
 ,I	JG23re   c                 T    0 nSn[        USS9nU R                  [        X25      5        g )Nzfoo = 1;bar = 2r   r   rj   rk   s       r#   $test_multiple_statements_single_line2TestMoreLines.test_multiple_statements_single_line   s+    	 +I	JW34re   c                 f    0 n[        S5      n[        USS9nU R                  [        X25      5        g )Nz$        import time

        foo = 1r   r   ry   rk   s       r#   r$   &TestMoreLines.test_multiple_statements   s5    	   ,I	JG23re   c                 f    0 n[        S5      n[        USS9nU R                  [        X25      5        g )Nz|        from dataclasses import dataclass

        @dataclass
        class Point:
            x: float
            y: floatr   r   ry   rk   s       r#   test_multiple_blocks"TestMoreLines.test_multiple_blocks   s5    	   ,I	JG23re   c                 f    0 n[        S5      n[        USS9nU R                  [        X25      5        g )Nz        from dataclasses import dataclass

        @dataclass
        class Point:
            x: float
            y: float
        r   r   ru   rk   s       r#   "test_multiple_blocks_empty_newline0TestMoreLines.test_multiple_blocks_empty_newline   s7    	   ,I	JW34re   c                 T    0 nSn[        USS9nU R                  [        X25      5        g )NzYfrom dataclasses import dataclass

@dataclass
class Point:
    x: float
    y: float
    r   r   rj   rk   s       r#   %test_multiple_blocks_indented_newline3TestMoreLines.test_multiple_blocks_indented_newline  s2    	 	 ,I	JW34re   c                 T    0 nSn[        USS9nU R                  [        X25      5        g )Nzif foo:r   r   )r   rz   r   rk   s       r#   test_incomplete_statement'TestMoreLines.test_incomplete_statement  s)    	+I	JG23re   r_   N)r`   ra   rb   rc   rl   ro   rr   rv   r{   r~   r$   r   r   r   r   rd   r_   re   r#   rg   rg      s9    555	5454
4554re   rg   )r   r   unittestunittest.mockr   textwrapr   test.supportr   _pyrepl.consoler   _pyrepl.simple_interactr   TestCaser	   rg   r_   re   r#   <module>r      sF     	    , 5 /b1** b1Jb4H%% b4re   