a
    ze{                  	   @   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re   dS )    N)StringIO)supportc                 C   s   t |  S Nprintargssependfile r   %/usr/lib/python3.9/test/test_print.py<lambda>       r   c                 C   s   t | d|iS )Nr   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|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      r   ))FFF)FFT)FTF)FTT)TFF)TFT)TTF)TTTc                   @   s   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   #   s   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 sF0    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)   r0   z + + 
) r-   r2   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   )r9   r   strr   r   r   writen   s    z2TestPrint.test_print_flush.<locals>.filelike.writec                 S   s   |  j d7  _ d S )Nr+   )r:   r   r   r   r   flushq   s    z2TestPrint.test_print_flush.<locals>.filelike.flushN)r   r   r   r   r=   r>   r   r   r   r   filelikei   s   r?   r+   r&   T)r   r
   r>   r,   r4   F)r   r>   z123
c                   @   s   e Zd Zdd Zdd ZdS )z+TestPrint.test_print_flush.<locals>.noflushc                 S   s   d S r   r   r;   r   r   r   r=   }   s    z1TestPrint.test_print_flush.<locals>.noflush.writec                 S   s   t d S r   )RuntimeErrorr   r   r   r   r>      s    z1TestPrint.test_print_flush.<locals>.noflush.flushN)r   r   r   r=   r>   r   r   r   r   noflush|   s   rA   )r   r    r9   r:   r5   r@   )r   r?   frA   r   r   r   test_print_flushg   s    zTestPrint.test_print_flushN)r   r   r   r   r%   r8   rC   r   r   r   r   r   +   s   
(r   c                   @   sD   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   sL   d}|  t}t| W d    n1 s,0    Y  | dt|j d S )Nzprint "Hello World"print("Hello World")r5   SyntaxErrorexecassertInr<   	exceptionr   Zpython2_print_strcontextr   r   r   test_normal_string   s    &z'TestPy2MigrationHint.test_normal_stringc                 C   sL   d}|  t}t| W d    n1 s,0    Y  | dt|j d S )Nzprint "Hello World",print("Hello World", end=" ")rF   rK   r   r   r   test_string_with_soft_space   s    &z0TestPy2MigrationHint.test_string_with_soft_spacec                 C   sL   d}|  t}t| W d    n1 s,0    Y  | dt|j d S )Nzprint  "Hello World", rN   rF   rK   r   r   r   %test_string_with_excessive_whitespace   s    &z:TestPy2MigrationHint.test_string_with_excessive_whitespacec                 C   sL   d}|  t}t| W d    n1 s,0    Y  | dt|j d S )Nz.if 1:
            print "Hello World"
        rE   rF   rK   r   r   r   #test_string_with_leading_whitespace   s    &z8TestPy2MigrationHint.test_string_with_leading_whitespacec                 C   sL   d}|  t}t| W d    n1 s,0    Y  | dt|j d S )Nzprint p;zprint(p)rF   rK   r   r   r   test_string_with_semicolon   s    &z/TestPy2MigrationHint.test_string_with_semicolonc                 C   sL   d}|  t}t| W d    n1 s,0    Y  | dt|j d S )Nzfor i in s: print izprint(i)rF   rK   r   r   r    test_string_in_loop_on_same_line   s    &z5TestPy2MigrationHint.test_string_in_loop_on_same_linec                 C   s>  |  t}ttj? df W d    n1 s.0    Y  | dt|j |  t}td?  W d    n1 sr0    Y  | dt|j |  t}ttj?  W d    n1 s0    Y  | 	dt|j |  t}ttj>  W d    n1 s0    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 )NrU   r   )r   Zlhsr   r   r   __rrshift__   s    zhTestPy2MigrationHint.test_stream_redirection_hint_for_py2_migration.<locals>.OverrideRRShift.__rrshift__N)r   r   r   rV   r   r   r   r   OverrideRRShift   s   rW   )r5   r6   r   sysstderrrI   r<   rJ   maxZassertNotInr    )r   rL   rW   r   r   r   .test_stream_redirection_hint_for_py2_migration   s$    ,&((zCTestPy2MigrationHint.test_stream_redirection_hint_for_py2_migrationN)
r   r   r   rM   rO   rP   rQ   rR   rS   r[   r   r   r   r   rD      s   rD   __main__)ZunittestrX   ior   testr   objectr   r   r   ZTestCaser   rD   r   mainr   r   r   r   <module>   s$   	ZU