B
    u9a_  ã               @   s˜   d dl Z d dlZd dlZd dlZd dlZd dlmZmZmZm	Z	 ej
dkrTe d¡‚ed Zdejejf ZG dd„ dejƒZd	d
„ Zedkr”eƒ  dS )é    N)ÚTESTFNÚrun_unittestÚunlinkÚreap_childrenÚposixz pipes module only works on posixÚ2ztr %s %sc               @   s„   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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 ) ÚSimplePipeTestsc             C   s   xt tfD ]}t|ƒ q
W d S )N)r   ÚTESTFN2r   )ÚselfÚf© r   ú /usr/lib/python3.7/test_pipes.pyÚtearDown   s    zSimplePipeTests.tearDownc          	   C   st   t  d¡d kr|  d¡ t ¡ }| ttj¡ | t	d¡}| 
d¡ | ¡  tt	ƒ}|  | ¡ d¡ W d Q R X d S )NÚtrztr is not availableÚwzhello world #1zHELLO WORLD #1)ÚshutilÚwhichÚskipTestÚpipesÚTemplateÚappendÚ	s_commandÚSTDIN_STDOUTÚopenr   ÚwriteÚcloseÚassertEqualÚread)r
   Útr   r   r   r   ÚtestSimplePipe1   s    


zSimplePipeTests.testSimplePipe1c          	   C   s†   t  d¡d kr|  d¡ ttdƒ}| d¡ W d Q R X t ¡ }| t	d tj
¡ | tt¡ ttƒ}|  | ¡ d¡ W d Q R X d S )Nr   ztr is not availabler   zhello world #2z < $IN > $OUTzHELLO WORLD #2)r   r   r   r   r   r   r   r   r   r   ÚFILEIN_FILEOUTÚcopyr	   r   r   )r
   r   r   r   r   r   ÚtestSimplePipe2    s    

zSimplePipeTests.testSimplePipe2c          	   C   s‚   t  d¡d kr|  d¡ ttdƒ}| d¡ W d Q R X t ¡ }| t	d tj
¡ | td¡}z|  | ¡ d¡ W d | ¡  X d S )Nr   ztr is not availabler   zhello world #2z < $INÚrzHELLO WORLD #2)r   r   r   r   r   r   r   r   r   r   ÚFILEIN_STDOUTr   r   r   )r
   r   r   r   r   r   ÚtestSimplePipe3+   s    
zSimplePipeTests.testSimplePipe3c          	   C   s€   d}t tdƒ}| |¡ W d Q R X t tdƒ}| d¡ W d Q R X t ¡ }| tt¡ t tƒ}|  | ¡ |¡ W d Q R X d S )Nzempty pipeline test COPYr   Ú )	r   r   r   r	   r   r   r!   r   r   )r
   Údr   r   r   r   r   ÚtestEmptyPipeline18   s    
z"SimplePipeTests.testEmptyPipeline1c          	   C   s\   d}t tdƒ}| |¡ W d Q R X t ¡ }|  td¡}z|  | ¡ |¡ W d | ¡  X d S )Nzempty pipeline test READr   r#   )r   r   r   r   r   r   r   r   )r
   r'   r   r   r   r   r   ÚtestEmptyPipeline2D   s    z"SimplePipeTests.testEmptyPipeline2c          	   C   sV   d}t  ¡ }| td¡}| |¡ W d Q R X ttƒ}|  | ¡ |¡ W d Q R X d S )Nzempty pipeline test WRITEr   )r   r   r   r   r   r   r   )r
   r'   r   r   r   r   r   ÚtestEmptyPipeline3P   s    
z"SimplePipeTests.testEmptyPipeline3c             C   s:   t  ¡ }|  t|ƒd¡ | dt j¡ |  t|ƒd¡ d S )Nz<Template instance, steps=[]>z
tr a-z A-Zz1<Template instance, steps=[('tr a-z A-Z', '--')]>)r   r   r   Úreprr   r   )r
   r   r   r   r   ÚtestReprY   s
    
zSimplePipeTests.testReprc             C   s<   t  ¡ }| d¡ |  |jd¡ | d¡ |  |jd¡ d S )NFT)r   r   Údebugr   Ú	debugging)r
   r   r   r   r   ÚtestSetDebug`   s
    

zSimplePipeTests.testSetDebugc             C   s,   t  ¡ }| dt j¡ |  t|jdd¡ d S )NÚboguscmdÚ	bogusfiler#   )r   r   r   ÚSINKÚassertRaisesÚ
ValueErrorr   )r
   r   r   r   r   ÚtestReadOpenSinkg   s    z SimplePipeTests.testReadOpenSinkc             C   s,   t  ¡ }| dt j¡ |  t|jdd¡ d S )Nr0   r1   r   )r   r   ÚprependÚSOURCEr3   r4   r   )r
   r   r   r   r   ÚtestWriteOpenSourcen   s    z#SimplePipeTests.testWriteOpenSourcec             C   sà   t  ¡ }|  t|jdt j¡ |  t|jdd¡ |  t|jdt j¡ t  ¡ }| dt j¡ |  t|jdt j¡ t  ¡ }|  t|jdt j	¡ t  ¡ }|  t|jdt j
¡ t  ¡ }|  t|jdt j	¡ t  ¡ }|  t|jdt j¡ d S )Né   r0   Úxxzboguscmd $OUTzboguscmd $IN)r   r   r3   Ú	TypeErrorr   r   r4   r7   r2   r    r$   ÚSTDIN_FILEOUT)r
   r   r   r   r   ÚtestBadAppendOptionsu   s&    z$SimplePipeTests.testBadAppendOptionsc             C   sà   t  ¡ }|  t|jdt j¡ |  t|jdd¡ |  t|jdt j¡ t  ¡ }| dt j¡ |  t|jdt j¡ t  ¡ }|  t|jdt j	¡ t  ¡ }|  t|jdt j
¡ t  ¡ }|  t|jdt j	¡ t  ¡ }|  t|jdt j¡ d S )Nr9   z
tr a-z A-Zr:   r0   zboguscmd $OUTzboguscmd $IN)r   r   r3   r;   r6   r   r4   r2   r7   r    r$   r<   )r
   r   r   r   r   ÚtestBadPrependOptions—   s&    z%SimplePipeTests.testBadPrependOptionsc             C   s   t  ¡ }|  t|jdd¡ d S )Nr1   Úx)r   r   r3   r4   r   )r
   r   r   r   r   ÚtestBadOpenMode¸   s    zSimplePipeTests.testBadOpenModec             C   sn   t  ¡ }| dt j¡ | ¡ }|  t|ƒt|ƒ¡ |  |j|j¡ |  t|jƒt|jƒ¡ |  |j	|j	¡ d S )Nz
tr a-z A-Z)
r   r   r   r   ZcloneZassertNotEqualÚidr   Zstepsr.   )r
   r   Úur   r   r   Ú	testClone¼   s    zSimplePipeTests.testCloneN)Ú__name__Ú
__module__Ú__qualname__r   r   r"   r%   r(   r)   r*   r,   r/   r5   r8   r=   r>   r@   rC   r   r   r   r   r      s   	"!r   c               C   s   t tƒ tƒ  d S )N)r   r   r   r   r   r   r   Ú	test_mainÆ   s    rG   Ú__main__)r   ÚosÚstringZunittestr   Ztest.supportr   r   r   r   ÚnameZSkipTestr	   Zascii_lowercaseZascii_uppercaser   ZTestCaser   rG   rD   r   r   r   r   Ú<module>   s   

 7