B
    u9aé  ã               @   sh   d Z ddlZddlmZ ddlZddlZejZdekrBde d ZG dd„ dejƒZ	e
dkrde ¡  dS )	zQBasic tests for os.popen()

  Particularly useful for platforms that fake popen.
é    N)Úsupportú ú"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S )Ú	PopenTestc          	   C   sN   d}|t |f }t |¡}| ¡ }W d Q R X t|ƒdd … }|  ||¡ d S )Nz&%s -c "import sys; print(sys.argv)" %sé   )ÚpythonÚosÚpopenÚreadÚevalÚassertEqual)ÚselfZcmdlineZexpectedÚcmdÚpÚdataZgot© r   ú /usr/lib/python3.7/test_popen.pyÚ_do_test_commandline   s    zPopenTest._do_test_commandlinec             C   sN   |   ttj¡ |  dddg¡ |  ddddg¡ |  ddddg¡ t ¡  d S )	Nzfoo barZfooZbarz foo "spam and eggs" "silly walk"zspam and eggsz
silly walkzfoo "a \"quoted\" arg" barza "quoted" arg)ZassertRaisesÚ	TypeErrorr   r	   r   r   Zreap_children)r   r   r   r   Ú
test_popen   s    
zPopenTest.test_popenc             C   sR   |   t d¡ ¡ d ¡ tjdkr8|   t d¡ ¡ d¡ n|   t d¡ ¡ d¡ d S )Nzexit 0Úntzexit 42é*   i *  )r   r   r	   ÚcloseÚname)r   r   r   r   Útest_return_code-   s    
zPopenTest.test_return_codec          	   C   s*   t  d¡}|  | ¡ d¡ W d Q R X d S )Nz
echo hellozhello
)r   r	   r   r
   )r   Úfr   r   r   Útest_contextmanager4   s    zPopenTest.test_contextmanagerc          	   C   s,   t  d¡}|  t|ƒdg¡ W d Q R X d S )Nz
echo hellozhello
)r   r	   r   Úlist)r   r   r   r   r   Útest_iterating8   s    zPopenTest.test_iteratingc          	   C   s    t jdddd W d Q R X d S )Nzexit 0Úwéÿÿÿÿ)r   ÚmodeÚ	buffering)r   r	   )r   r   r   r   Útest_keywords<   s    zPopenTest.test_keywordsN)	Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r#   r   r   r   r   r      s   r   Ú__main__)Ú__doc__ZunittestZtestr   r   ÚsysÚ
executabler   ZTestCaser   r$   Úmainr   r   r   r   Ú<module>   s   -