B
    u9a{              	   @   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.7/test_print.py<lambda>       r   c             C   s   t | d|iS )Nr   )r   )r   r   r   r   r	   r	   r
   r      r   c             C   s   t | d|iS )Nr   )r   )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
   r      r   c             C   s   t | d|iS )Nr   )r   )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
   r      r   c             C   s   t | ||dS )N)r   r   )r   )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	   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 )N)x)selfr   r	   r	   r
   __init__$   s    zClassWith__str__.__init__c             C   s   | j S )N)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               @   s0   e Zd ZdZeeefddZdd Zdd ZdS )		TestPrintz-Test correct operation of the print function.c          	   C   sP   t |tk	|tk	|tk	f }t }||||| W d Q R X | | | d S )N)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 )N)r   r    )r   r   r   )r   r   r   r   )r   r   r   r   o)r   r	   r
   r   @   s    zTestPrint.test_print.<locals>.x
r	   za
)azNone
)Nz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   r   z1*a*1.3+)r"   r!   g?+za

b
)za
r'   z + + 
) r$   r)   za
 b
z*
zabc 1
abcr"      )r   )r   r   assertRaises	TypeErrorr   AttributeError)r   r   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flushed)r   r	   r	   r
   r   j   s    z5TestPrint.test_print_flush.<locals>.filelike.__init__c             S   s   |  j |7  _ d S )N)r0   )r   strr	   r	   r
   writen   s    z2TestPrint.test_print_flush.<locals>.filelike.writec             S   s   |  j d7  _ d S )Nr"   )r1   )r   r	   r	   r
   flushq   s    z2TestPrint.test_print_flush.<locals>.filelike.flushN)r   r   r   r   r3   r4   r	   r	   r	   r
   filelikei   s   r5   r"   r   T)r   r   r4   r#   r+   F)r   r4   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 )Nr	   )r   r2   r	   r	   r
   r3   }   s    z1TestPrint.test_print_flush.<locals>.noflush.writec             S   s   t d S )N)RuntimeError)r   r	   r	   r
   r4      s    z1TestPrint.test_print_flush.<locals>.noflush.flushN)r   r   r   r3   r4   r	   r	   r	   r
   noflush|   s   r7   )r   r   r0   r1   r,   r6   )r   r5   fr7   r	   r	   r
   test_print_flushg   s    zTestPrint.test_print_flushN)r   r   r   __doc__r   r   r/   r9   r	   r	   r	   r
   r   +   s   (r   c               @   sH   e Zd 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 )TestPy2MigrationHintzwTest that correct hint is produced analogous to Python3 syntax,
    if print statement is executed as in Python 2.
    c          	   C   s8   d}|  t}t| W d Q R X | dt|j d S )Nzprint "Hello World"zprint("Hello World"))r,   SyntaxErrorexecassertInr2   	exception)r   python2_print_strcontextr	   r	   r
   test_normal_string   s    z'TestPy2MigrationHint.test_normal_stringc          	   C   s8   d}|  t}t| W d Q R X | dt|j d S )Nzprint "Hello World",zprint("Hello World", end=" "))r,   r<   r=   r>   r2   r?   )r   r@   rA   r	   r	   r
   test_string_with_soft_space   s    z0TestPy2MigrationHint.test_string_with_soft_spacec          	   C   s8   d}|  t}t| W d Q R X | dt|j d S )Nzprint  "Hello World", zprint("Hello World", end=" "))r,   r<   r=   r>   r2   r?   )r   r@   rA   r	   r	   r
   %test_string_with_excessive_whitespace   s    z:TestPy2MigrationHint.test_string_with_excessive_whitespacec          	   C   s8   d}|  t}t| W d Q R X | dt|j d S )Nz.if 1:
            print "Hello World"
        zprint("Hello World"))r,   r<   r=   r>   r2   r?   )r   r@   rA   r	   r	   r
   #test_string_with_leading_whitespace   s    z8TestPy2MigrationHint.test_string_with_leading_whitespacec          	   C   s8   d}|  t}t| W d Q R X | dt|j d S )Nzprint p;zprint(p))r,   r<   r=   r>   r2   r?   )r   r@   rA   r	   r	   r
   test_string_with_semicolon   s    z/TestPy2MigrationHint.test_string_with_semicolonc          	   C   s8   d}|  t}t| W d Q R X | dt|j d S )Nzfor i in s: print izprint(i))r,   r<   r=   r>   r2   r?   )r   r@   rA   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 Q R X | dt|j |  t}td?  W d Q R X | dt|j |  t}ttj?  W d Q R X | 	dt|j |  t}ttj>  W d Q R X | 	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 )NrI   r	   )r   Zlhsr	   r	   r
   __rrshift__   s    zhTestPy2MigrationHint.test_stream_redirection_hint_for_py2_migration.<locals>.OverrideRRShift.__rrshift__N)r   r   r   rJ   r	   r	   r	   r
   OverrideRRShift   s   rK   )r,   r-   r   sysstderrr>   r2   r?   maxZassertNotInr   )r   rA   rK   r	   r	   r
   .test_stream_redirection_hint_for_py2_migration   s     zCTestPy2MigrationHint.test_stream_redirection_hint_for_py2_migrationN)r   r   r   r:   rB   rC   rD   rE   rF   rG   rO   r	   r	   r	   r
   r;      s   r;   __main__)ZunittestrL   ior   Ztestr   objectr   r   r   ZTestCaser   r;   r   mainr	   r	   r	   r
   <module>   s"   	ZU