U
    k&p[Ø  ã                   @   sd   d dl mZ d dlZd dlZd dlZd dlZd dlZdd„ ZG dd„ dejƒZ	G dd„ dejƒZ
dS )	é    )Úunicode_literalsNc                 C   s   d S ©N© )Úmsgr   r   ú5/usr/lib/python3/dist-packages/cliapp/runcmd_tests.pyÚdevnull   s    r   c                   @   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d „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'S )(ÚRuncmdTestsc                 C   s   |   t dg¡d¡ d S )NÚtrueó    ©ÚassertEqualÚcliappÚruncmd©Úselfr   r   r   Útest_runcmd_executes_true"   s    z%RuncmdTests.test_runcmd_executes_truec                 C   s   |   tjtjdg¡ d S )NÚfalse)ZassertRaisesr   ZAppExceptionr   r   r   r   r   Ú#test_runcmd_raises_error_on_failure%   s    z/RuncmdTests.test_runcmd_raises_error_on_failurec                 C   s   |   t dddg¡d¡ d S )NÚechos   hellos   worlds   hello world
r   r   r   r   r   Ú%test_runcmd_returns_stdout_of_command(   s    ÿz1RuncmdTests.test_runcmd_returns_stdout_of_commandc                 C   s<   t  ddg¡\}}}|  |d¡ |  |d¡ |  |d¡ d S )NÚlsÚnotexistr   r
   )r   Úruncmd_uncheckedÚassertNotEqualr   )r   Ú	exit_codeÚoutÚerrr   r   r   Ú%test_runcmd_returns_stderr_of_command,   s    z1RuncmdTests.test_runcmd_returns_stderr_of_commandc                 C   s   |   tjdgddd¡ d S ©NÚcats   hello, world©Z
feed_stdinr   r   r   r   r   Ú'test_runcmd_pipes_stdin_through_command2   s    ÿz3RuncmdTests.test_runcmd_pipes_stdin_through_commandc                 C   s    |   tjdgdgddd¡ d S r   r   r   r   r   r   Ú,test_runcmd_pipes_stdin_through_two_commands6   s    þz8RuncmdTests.test_runcmd_pipes_stdin_through_two_commandsc                 C   s$   dd }|   tjdg|d|¡ d S )Nó   xi   r   r    r   )r   Údatar   r   r   Ú9test_runcmd_pipes_stdin_through_command_with_lots_of_data;   s    zERuncmdTests.test_runcmd_pipes_stdin_through_command_with_lots_of_datac                 C   s   |   tjdgddd¡ d S )Nr   T)Zignore_failr
   r   r   r   r   r   Ú'test_runcmd_ignores_failures_on_request?   s    z3RuncmdTests.test_runcmd_ignores_failures_on_requestc                 C   s   |   tjdgddd¡ d S )NÚpwdú/)Úcwds   /
r   r   r   r   r   Útest_runcmd_obeys_cwdB   s    z!RuncmdTests.test_runcmd_obeys_cwdc                 C   s   |   t ddg¡d¡ d S )Nr   Úfoo)r   s   foo
r
   ©r   r   r   r   r   r   r   Ú/test_runcmd_unchecked_returns_values_on_successE   s    ÿz;RuncmdTests.test_runcmd_unchecked_returns_values_on_successc                 C   s   |   t dg¡d¡ d S )Nr   )é   r
   r
   r,   r   r   r   r   Ú/test_runcmd_unchecked_returns_values_on_failureI   s    ÿz;RuncmdTests.test_runcmd_unchecked_returns_values_on_failurec                 C   s    |   t ddgddg¡d¡ d S )Nr   r+   Úwcú-c©r   s   4
r
   r,   r   r   r   r   Ú*test_runcmd_unchecked_runs_simple_pipelineM   s    þz6RuncmdTests.test_runcmd_unchecked_runs_simple_pipelinec                 C   s$   |   t ddgdgddg¡d¡ d S )Nr   r+   r   r0   r1   r2   r,   r   r   r   r   Ú*test_runcmd_unchecked_runs_longer_pipelineR   s    þz6RuncmdTests.test_runcmd_unchecked_runs_longer_pipelinec                 C   sR   t  ¡ \}}t |d ¡ ¡ t |dtj¡ |  tj	dg|dd¡ t 
|¡ d S )NZfoobarr   r   )Ústdin)r   s   foobarr
   )ÚtempfileÚmkstempÚosÚwriteÚencodeÚlseekÚSEEK_SETr   r   r   Úclose)r   ÚfdÚ_r   r   r   Ú%test_runcmd_redirects_stdin_from_fileW   s    ÿz1RuncmdTests.test_runcmd_redirects_stdin_from_filec              	   C   sf   t  ¡ \}}tjddg|d\}}}t |¡ t|ƒ}| ¡ }W 5 Q R X |  |d¡ |  |d¡ d S )Nr   r+   )Ústdoutr   zfoo
)	r6   r7   r   r   r8   r=   ÚopenÚreadr   ©r   r>   Úfilenamer   r?   Úfr$   r   r   r   Ú$test_runcmd_redirects_stdout_to_file_   s     ÿ

z0RuncmdTests.test_runcmd_redirects_stdout_to_filec              	   C   sf   t  ¡ \}}tjddg|d\}}}t |¡ t|ƒ}| ¡ }W 5 Q R X |  |d¡ |  |d¡ d S )Nr   r   )Ústderrr   Ú )	r6   r7   r   r   r8   r=   rB   rC   r   rD   r   r   r   Ú$test_runcmd_redirects_stderr_to_filei   s     ÿ

z0RuncmdTests.test_runcmd_redirects_stderr_to_filec              	   C   sj   t  ¡ \}}tjddg|tjd\}}}t |¡ t|ƒ}| 	¡ }W 5 Q R X |  
|d¡ |  
|d¡ d S )NÚsleepÚ2)rA   rH   r   rI   )r6   r7   r   r   Ú
subprocessZSTDOUTr8   r=   rB   rC   r   rD   r   r   r   Ú@test_runcmd_unchecked_handles_stdout_err_redirected_to_same_files   s      ÿ

zLRuncmdTests.test_runcmd_unchecked_handles_stdout_err_redirected_to_same_filec                    sR   g ‰ ‡ fdd„}d}t jdd|g|d\}}}|  |d¡ |  ˆ | d¡g¡ d S )	Nc                    s   ˆ   | ¡ dS )Nó   foo©Úappend©Ús©Zmsgsr   r   Úlogger€   s    
zPRuncmdTests.test_runcmd_calls_stdout_callback_when_msg_on_stdout.<locals>.loggerz	hello foxr   z-n)Zstdout_callbackrO   zUTF-8)r   r   r   r:   )r   rU   Z
test_inputr?   r   r   rT   r   Ú4test_runcmd_calls_stdout_callback_when_msg_on_stdout}   s     ÿz@RuncmdTests.test_runcmd_calls_stdout_callback_when_msg_on_stdoutc                    sJ   g ‰ ‡ fdd„}t jddg|d\}}}|  |d¡ |  d ˆ ¡|¡ d S )Nc                    s   ˆ   | ¡ d S r   rP   rR   rT   r   r   rU   ‘   s    
zPRuncmdTests.test_runcmd_calls_stderr_callback_when_msg_on_stderr.<locals>.loggerr   Znosuchthing)Zstderr_callbackrI   r
   )r   r   r   r   Újoin)r   rU   r?   r   r   rT   r   Ú4test_runcmd_calls_stderr_callback_when_msg_on_stderrŽ   s     ÿ	z@RuncmdTests.test_runcmd_calls_stderr_callback_when_msg_on_stderrN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r!   r"   r%   r&   r*   r-   r/   r3   r4   r@   rG   rJ   rN   rV   rX   r   r   r   r   r       s&   


r   c                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚShellQuoteTestsc                 C   s   |   t d¡d¡ d S )NrI   ©r   r   Zshell_quoter   r   r   r   Ú*test_returns_empty_string_for_empty_string§   s    z:ShellQuoteTests.test_returns_empty_string_for_empty_stringc                 C   s   |   t d¡d¡ d S )NZabc123r]   r   r   r   r   Ú"test_returns_same_string_when_safeª   s    z2ShellQuoteTests.test_returns_same_string_when_safec                 C   s   |   t d¡d¡ d S )Nú z' 'r]   r   r   r   r   Útest_quotes_space­   s    z!ShellQuoteTests.test_quotes_spacec                 C   s   |   t d¡d¡ d S )Nú"z'"'r]   r   r   r   r   Útest_quotes_double_quote°   s    z(ShellQuoteTests.test_quotes_double_quotec                 C   s   |   t d¡d¡ d S )Nú'z"'"r]   r   r   r   r   Útest_quotes_single_quote³   s    z(ShellQuoteTests.test_quotes_single_quoteN)rY   rZ   r[   r^   r_   ra   rc   re   r   r   r   r   r\   ¥   s
   r\   )Z
__future__r   r8   rM   r6   Zunittestr   r   ZTestCaser   r\   r   r   r   r   Ú<module>   s    