
    <e              	           d dl Z d dlZd dlmZ d dlmZ  e            Zd d d d d d	 d
 d dZ G d d          Z	 G d de j
                  Z G d de j
                  Zedk    r e j                     dS dS )    N)StringIO)supportc                     t          |  S Nprintargssependfiles       &/usr/lib/python3.11/test/test_print.py<lambda>r      s
    UD\     c                     t          | d|iS )Nr   r   r	   s       r   r   r      s    Ut%<%<%< r   c                     t          | d|iS )Nr   r   r	   s       r   r   r          UT%:s%:%: r   c                     t          | ||dS )N)r   r   r   r	   s       r   r   r          Us%E%E%E r   c                     t          | d|iS )Nr   r   r	   s       r   r   r      r   r   c                     t          | ||dS )N)r   r   r   r	   s       r   r   r      r   r   c                     t          | ||dS )Nr   r   r   r	   s       r   r   r      s    Uds%C%C%C r   c                     t          | |||dS )Nr   r   r   r   r	   s       r   r   r      s    Us$%N%N%N r   ))FFF)FFT)FTF)FTT)TFF)TFT)TTF)TTTc                       e Zd Zd Zd ZdS )ClassWith__str__c                     || _         d S r   xselfr    s     r   __init__zClassWith__str__.__init__$   s    r   c                     | j         S r   r   r"   s    r   __str__zClassWith__str__.__str__'   s	    vr   N)__name__
__module____qualname__r#   r&    r   r   r   r   #   s2              r   r   c                   ,    e Zd ZdZeeefdZd Zd ZdS )	TestPrintz-Test correct operation of the print function.c                    t           |t          u|t          u|t          uf         }t          j                    5 } |||||           d d d            n# 1 swxY w Y   |                     |                                |           d S r   )dispatch
NotDefinedr   captured_stdoutassertEqualgetvalue)r"   expectedr
   r   r   r   fnts           r   checkzTestPrint.check.   s     s*,*,:-/ 0 $&& 	%!BtS#t$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	x00000s   AAAc                     t           t           f fd	} |dd            |dd            |dd            |dd	            |d
d            |dd	d            |ddd            |ddd            |dddd            |dddd            |ddd            |ddd            |dd            |ddd             |ddd             |ddd d             |d t          d          f            |d!t          d"          d#f                                t          t          dd$                                t          t          dd$                                t
          t          dd%           d S )&Nc                                          | |||           t                      }                     d||||                               |                                |            d S )Nr    r   )r6   r   r1   r2   )r3   r
   r   r   or"   s        r   r    zTestPrint.test_print.<locals>.x@   sl     JJx3CJ888 

AJJr4ScJ::: QZZ\\844444r   
r*   a
)azNone
r   z1 2
)      z1   2
)r>    r?   z1*2
*)r   z1 s)r>   sr9   )r   za
b
)r=   bz1.01)g      ?r>   r   z1*a*1.3+)r>   r=   g?+za

b
)r<   rC   z + + 
) r@   rE   za
 b
z*
zabc 1
abcr>      )r   )r/   r   assertRaises	TypeErrorr   AttributeErrorr!   s   ` r   
test_printzTestPrint.test_print?   s   ",* 	5 	5 	5 	5 	5 	5 	
$	%	(G	'6	)[!!!	'6s####	%r""""	(JD))))	&(++++	*m#6666	*l----	+(c2222	)\"""	)\t,,,,	)\t,,,,	)\t6666	%"3'')***	)&u--q1222 	)UBA666)UBA666.%"=====r   c                     G d d          } |            }t          d|dd           t          d|dd           t          d|d	
           |                     |j        d           |                     |j        d            G d d          }|                     t
          t           d |            d
           d S )Nc                        e Zd Zd Zd Zd ZdS ),TestPrint.test_print_flush.<locals>.filelikec                 "    d| _         d| _        d S )Nr9   r   )writtenflushedr%   s    r   r#   z5TestPrint.test_print_flush.<locals>.filelike.__init__j   s    ! r   c                 &    | xj         |z  c_         d S r   )rP   r"   strs     r   writez2TestPrint.test_print_flush.<locals>.filelike.writen   s    #r   c                 &    | xj         dz  c_         d S )Nr>   )rQ   r%   s    r   flushz2TestPrint.test_print_flush.<locals>.filelike.flushq   s    !r   N)r'   r(   r)   r#   rU   rW   r*   r   r   filelikerN   i   sA        ! ! !$ $ $" " " " "r   rX   r>   r9   T)r   r   rW   r?   rG   F)r   rW   z123
c                       e Zd Zd Zd ZdS )+TestPrint.test_print_flush.<locals>.noflushc                     d S r   r*   rS   s     r   rU   z1TestPrint.test_print_flush.<locals>.noflush.write}   s    r   c                     t           r   )RuntimeErrorr%   s    r   rW   z1TestPrint.test_print_flush.<locals>.noflush.flush   s    ""r   N)r'   r(   r)   rU   rW   r*   r   r   noflushrZ   |   s2          # # # # #r   r^   )r   r1   rP   rQ   rH   r]   )r"   rX   fr^   s       r   test_print_flushzTestPrint.test_print_flushg   s    		" 		" 		" 		" 		" 		" 		" 		" HJJaaRt,,,,aaRt,,,,aau%%%%G,,,A&&&	# 	# 	# 	# 	# 	# 	# 	# 	,qwwyyMMMMMr   N)r'   r(   r)   __doc__r/   r6   rK   r`   r*   r   r   r,   r,   +   s[        77 *:1 1 1 1"&> &> &>PN N N N Nr   r,   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
TestPy2MigrationHintzwTest that correct hint is produced analogous to Python3 syntax,
    if print statement is executed as in Python 2.
    c                     d}|                      t                    5 }t          |           d d d            n# 1 swxY w Y   |                     dt	          |j                             d S )Nzprint "Hello World"?Missing parentheses in call to 'print'. Did you mean print(...)rH   SyntaxErrorexecassertInrT   	exceptionr"   python2_print_strcontexts      r   test_normal_stringz'TestPy2MigrationHint.test_normal_string       1{++ 	$w"###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	WG%&&	( 	( 	( 	( 	(   9= =c                     d}|                      t                    5 }t          |           d d d            n# 1 swxY w Y   |                     dt	          |j                             d S )Nzprint "Hello World",re   rf   rk   s      r   test_string_with_soft_spacez0TestPy2MigrationHint.test_string_with_soft_space   s    2{++ 	$w"###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	WG%&&	( 	( 	( 	( 	(rp   c                     d}|                      t                    5 }t          |           d d d            n# 1 swxY w Y   |                     dt	          |j                             d S )Nzprint  "Hello World", re   rf   rk   s      r   %test_string_with_excessive_whitespacez:TestPy2MigrationHint.test_string_with_excessive_whitespace   s    4{++ 	$w"###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	WG%&&	( 	( 	( 	( 	(rp   c                     d}|                      t                    5 }t          |           d d d            n# 1 swxY w Y   |                     dt	          |j                             d S )Nz.if 1:
            print "Hello World"
        re   rf   rk   s      r   #test_string_with_leading_whitespacez8TestPy2MigrationHint.test_string_with_leading_whitespace   s     {++ 	$w"###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	WG%&&	( 	( 	( 	( 	(rp   c                     d}|                      t                    5 }t          |           d d d            n# 1 swxY w Y   |                     dt	          |j                             d S )Nzprint p;re   rf   rk   s      r   test_string_with_semicolonz/TestPy2MigrationHint.test_string_with_semicolon   s    &{++ 	$w"###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	WG%&&	( 	( 	( 	( 	(rp   c                     d}|                      t                    5 }t          |           d d d            n# 1 swxY w Y   |                     dt	          |j                             d S )Nzfor i in s: print ire   rf   rk   s      r    test_string_in_loop_on_same_linez5TestPy2MigrationHint.test_string_in_loop_on_same_line   ro   rp   c                    |                      t                    5 }t          t          j        z	  df d d d            n# 1 swxY w Y   |                     dt          |j                             |                      t                    5 }t          dz	   d d d            n# 1 swxY w Y   |                     dt          |j                             |                      t                    5 }t          t          j        z	   d d d            n# 1 swxY w Y   | 	                    dt          |j                             |                      t                    5 }t          t          j        z   d d d            n# 1 swxY w Y   | 	                    dt          |j                              G d d          }| 
                    t           |            z	  d           d S )Nmessagez6Did you mean "print(<message>, file=<output_stream>)"?*   zDid you mean zDid you meanc                       e Zd Zd ZdS )\TestPy2MigrationHint.test_stream_redirection_hint_for_py2_migration.<locals>.OverrideRRShiftc                     dS )Nr}   r*   )r"   lhss     r   __rrshift__zhTestPy2MigrationHint.test_stream_redirection_hint_for_py2_migration.<locals>.OverrideRRShift.__rrshift__   s    rr   N)r'   r(   r)   r   r*   r   r   OverrideRRShiftr      s#            r   r   )rH   rI   r   sysstderrri   rT   rj   maxassertNotInr1   )r"   rm   r   s      r   .test_stream_redirection_hint_for_py2_migrationzCTestPy2MigrationHint.test_stream_redirection_hint_for_py2_migration   s   y)) 	+WSZ**	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ *+.w/@+A+A	C 	C 	C
 y)) 	WRKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 *+.w/@+A+A	C 	C 	C y)) 	W3:	 	 	 	 	 	 	 	 	 	 	 	 	 	 	#g.?*@*@AAA y)) 	 WSZ	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 W->)?)?@@@	 	 	 	 	 	 	 	 	//"3"33R88888sE   >AAB""B&)B&/DDDE>>FFN)r'   r(   r)   ra   rn   rr   rt   rv   rx   rz   r   r*   r   r   rc   rc      s         ( ( (( ( (( ( (( ( (( ( (( ( (9 9 9 9 9r   rc   __main__)unittestr   ior   testr   objectr/   r.   r   TestCaser,   rc   r'   mainr*   r   r   <module>r      sF    



            VXX
 	21<<::EE::EECCNN! *       WN WN WN WN WN! WN WN WNtW9 W9 W9 W9 W98, W9 W9 W9v zHMOOOOO r   