o
    HXh                  	   @   s   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	d d
d dd dd dZG dd dZ	G dd de j
ZG dd de j
ZedkrUe   dS dS )    N)StringIO)supportc                 C   s   t |  S Nprintargssependfile r   9/opt/python-3.10.19/usr/lib/python3.10/test/test_print.py<lambda>   s    r   c                 C   s   t | d|iS )Nr   r   r   r   r   r   r          c                 C   s   t | d|iS )Nr
   r   r   r   r   r   r      r   c                 C   s   t | ||dS )N)r
   r   r   r   r   r   r   r          c                 C   s   t | d|iS )Nr	   r   r   r   r   r   r      r   c                 C   s   t | ||dS )N)r	   r   r   r   r   r   r   r      r   c                 C   s   t | ||dS )Nr	   r
   r   r   r   r   r   r      r   c                 C   s   t | |||dS )Nr	   r
   r   r   r   r   r   r   r      s    ))FFF)FFT)FTF)FTT)TFF)TFT)TTF)TTTc                   @      e Zd Zdd Zdd ZdS )ClassWith__str__c                 C   s
   || _ d S r   xselfr   r   r   r   __init__$   s   
zClassWith__str__.__init__c                 C   s   | j S r   r   r   r   r   r   __str__'   s   zClassWith__str__.__str__N)__name__
__module____qualname__r   r   r   r   r   r   r   #       r   c                   @   s.   e Zd Z	 eeefddZdd Zdd ZdS )	TestPrintc                 C   sd   t |tu|tu|tuf }t }||||| W d    n1 s#w   Y  | | | d S r   )dispatch
NotDefinedr   Zcaptured_stdoutassertEqualgetvalue)r   expectedr   r	   r
   r   fntr   r   r   check.   s   
zTestPrint.checkc                    s<  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 d |d dd d |d dd d d |d!tdf |d"td#d$f  jttdd%d  jttdd%d  jttddd& d S )'Nc                    s@    j | |||d t } j d||||d  | |  d S )Nr    r   )r(   r   r#   r$   )r%   r   r	   r
   or   r   r   r   @   s   zTestPrint.test_print.<locals>.x
r   a
)azNone
r   z1 2
)      z1   2
)r.    r/   z1*2
*)r	   z1 s)r.   sr)   )r
   za
b
)r-   bz1.01)g      ?r.   r   z1*a*1.3+)r.   r-   g?+za

b
)r,   r3   z + + 
) r0   r5   za
 b
z*
zabc 1
abcr.      )r   )r"   r   assertRaises	TypeErrorr   AttributeErrorr   r   r   r   
test_print?   s,   





zTestPrint.test_printc                 C   s   G dd d}| }t d|ddd t d|ddd t d|d	d
 | |jd | |jd G dd d}| jtt d| dd
 d S )Nc                   @   s$   e Zd Zdd Zdd Zdd ZdS )z,TestPrint.test_print_flush.<locals>.filelikec                 S   s   d| _ d| _d S )Nr)   r   )writtenflushedr   r   r   r   r   j   s   
z5TestPrint.test_print_flush.<locals>.filelike.__init__c                 S   s   |  j |7  _ d S r   )r<   r   strr   r   r   writen      z2TestPrint.test_print_flush.<locals>.filelike.writec                 S   s   |  j d7  _ d S )Nr.   )r=   r   r   r   r   flushq   rA   z2TestPrint.test_print_flush.<locals>.filelike.flushN)r   r   r   r   r@   rB   r   r   r   r   filelikei   s    rC   r.   r)   T)r   r
   rB   r/   r7   F)r   rB   z123
c                   @   r   )z+TestPrint.test_print_flush.<locals>.noflushc                 S   s   d S r   r   r>   r   r   r   r@   }      z1TestPrint.test_print_flush.<locals>.noflush.writec                 S   s   t r   )RuntimeErrorr   r   r   r   rB      rD   z1TestPrint.test_print_flush.<locals>.noflush.flushN)r   r   r   r@   rB   r   r   r   r   noflush|   r   rF   )r   r#   r<   r=   r8   rE   )r   rC   frF   r   r   r   test_print_flushg   s   zTestPrint.test_print_flushN)r   r   r   r"   r(   r;   rH   r   r   r   r   r    +   s    
(r    c                   @   sF   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S )TestPy2MigrationHintc                 C   L   d}|  t}t| W d    n1 sw   Y  | dt|j d S )Nzprint "Hello World"?Missing parentheses in call to 'print'. Did you mean print(...)r8   SyntaxErrorexecassertInr?   	exceptionr   Zpython2_print_strcontextr   r   r   test_normal_string      
z'TestPy2MigrationHint.test_normal_stringc                 C   rJ   )Nzprint "Hello World",rK   rL   rQ   r   r   r   test_string_with_soft_space   rT   z0TestPy2MigrationHint.test_string_with_soft_spacec                 C   rJ   )Nzprint  "Hello World", rK   rL   rQ   r   r   r   %test_string_with_excessive_whitespace   rT   z:TestPy2MigrationHint.test_string_with_excessive_whitespacec                 C   rJ   )Nz.if 1:
            print "Hello World"
        rK   rL   rQ   r   r   r   #test_string_with_leading_whitespace   s   
z8TestPy2MigrationHint.test_string_with_leading_whitespacec                 C   rJ   )Nzprint p;rK   rL   rQ   r   r   r   test_string_with_semicolon   rT   z/TestPy2MigrationHint.test_string_with_semicolonc                 C   rJ   )Nzfor i in s: print irK   rL   rQ   r   r   r    test_string_in_loop_on_same_line   rT   z5TestPy2MigrationHint.test_string_in_loop_on_same_linec                 C   s>  |  t}ttj? df W d    n1 sw   Y  | dt|j |  t}td?  W d    n1 s9w   Y  | dt|j |  t}ttj?  W d    n1 s\w   Y  | 	dt|j |  t}ttj>  W d    n1 sw   Y  | 	dt|j G dd d}| 
t| ? d d S )Nmessagez6Did you mean "print(<message>, file=<output_stream>)"?*   zDid you mean zDid you meanc                   @   s   e Zd Zdd ZdS )z\TestPy2MigrationHint.test_stream_redirection_hint_for_py2_migration.<locals>.OverrideRRShiftc                 S   s   dS )Nr[   r   )r   Zlhsr   r   r   __rrshift__   rD   zhTestPy2MigrationHint.test_stream_redirection_hint_for_py2_migration.<locals>.OverrideRRShift.__rrshift__N)r   r   r   r\   r   r   r   r   OverrideRRShift   s    r]   )r8   r9   r   sysstderrrO   r?   rP   maxZassertNotInr#   )r   rR   r]   r   r   r   .test_stream_redirection_hint_for_py2_migration   s,   
zCTestPy2MigrationHint.test_stream_redirection_hint_for_py2_migrationN)
r   r   r   rS   rU   rV   rW   rX   rY   ra   r   r   r   r   rI      s    rI   __main__)Zunittestr^   ior   testr   objectr"   r!   r   ZTestCaser    rI   r   mainr   r   r   r   <module>   s(    	Z[