a
    ze                     @   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v 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   sb   d}|t |f }t|}| }W d    n1 s80    Y  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.9/test/test_popen.py_do_test_commandline   s    &zPopenTest._do_test_commandlinec                 C   sJ   |  ttj | dddg | dg d | dg d t  d S )Nzfoo barfoobarz foo "spam and eggs" "silly walk")r   zspam and eggsz
silly walkzfoo "a \"quoted\" arg" bar)r   za "quoted" argr   )ZassertRaises	TypeErrorr   r	   r   r   reap_childrenr   r   r   r   
test_popen   s    zPopenTest.test_popenc                 C   sR   |  td d  td }tjdkr<|  |d n|  t|d d S )Nexit 0zexit 42nt*   )r   r   r	   closenamewaitstatus_to_exitcode)r   statusr   r   r   test_return_code-   s
    
zPopenTest.test_return_codec                 C   s>   t d }| | d W d    n1 s00    Y  d S Nz
echo hellozhello
)r   r	   r   r
   r   fr   r   r   test_contextmanager5   s    zPopenTest.test_contextmanagerc                 C   s@   t d"}| t|dg W d    n1 s20    Y  d S r"   )r   r	   r   listr#   r   r   r   test_iterating9   s    zPopenTest.test_iteratingc                 C   s4   t jdddd W d    n1 s&0    Y  d S )Nr   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unittesttestr   r   sys
executabler   ZTestCaser   r-   mainr   r   r   r   <module>   s   .