B
    v9a                 @   sp   d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z
mZ ddlZe
  G dd dejZdS )zTest Tools/scripts/fixcid.py.    )StringION)support)skip_if_missing
scriptsdirc               @   s6   e Zd Zdd Zdd Zdd Zddd	d
ddZdS )Testc          	   C   s<   d}d}|  || }d}d}| |dj||||d d S )Nzint xx = "xx\"xx"[xx];
zint xx = 'x\'xx' + xx;
zint yy = "xx\"xx"[yy];
zint yy = 'x\'xx' + yy;
z01
< {old1}> {new1}{new1}2
< {old2}> {new2}{new2})old1old2new1new2)
run_scriptassertMultiLineEqualformat)selfr   r   outputr	   r
    r   !/usr/lib/python3.7/test_fixcid.pytest_parse_strings   s    zTest.test_parse_stringsc             C   s    | j dddd}| |d d S )Nzxx yy
*aa bb
)z-c-z4/* xx altered */
int xx;
/* aa unaltered */
int aa;
)	substfileargsinputz1
< /* xx altered */
> /* yy altered */
/* yy altered */
2
< int xx;
> int yy;
int yy;
/* aa unaltered */
4
< int aa;
> int bb;
int bb;
)r   r   )r   r   r   r   r   test_alter_comments   s    zTest.test_alter_commentsc          	   C   s   t tj | tjtj t jtjd}t|d}|	d W d Q R X tt jtjdd}|	d W d Q R X t jt
d}| jtjfd}| |d| d S )	Nzfile.cwzint xx;
zfile.pyzxx = 'unaltered'
z	fixcid.py)r   z{}:
1
< int xx;
> int yy;
)osmkdirr   TESTFN
addCleanupZrmtreepathjoinopenwriter   r   r   r   )r   Z
c_filenamefilescriptr   r   r   r   test_directory;   s    zTest.test_directory )r   zxx yy
)r   r   c      
      C   s  t jd }t|d}|| W d Q R X | t j| dd|gt| }tj	t
d}t td| t tdt|r t  ^}t  J ytj|dd W n0 tk
r }	 z| |	jd	 W d d }	~	X Y nX W d Q R X W d Q R X W d Q R X W d Q R X | S )
Nz.substr   z	fixcid.pyz-sargvstdin__main__)Zrun_namer   )r   r   r   r    r   unlinklistr   r   r   r   Z	swap_attrsysr   Zcaptured_stdoutZcaptured_stderrrunpyZrun_path
SystemExitZassertEqualcodegetvalue)
r   r   r   r   Zsubstfilenamer!   r%   r"   r   exitr   r   r   r   L   s    


HzTest.run_scriptN)r$   )__name__
__module____qualname__r   r   r#   r   r   r   r   r   r      s   r   )__doc__ior   r   Zos.pathr+   r*   Ztestr   Ztest.test_toolsr   r   ZunittestZTestCaser   r   r   r   r   <module>   s   