a
    ze                     @   sl   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 )    )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   1/usr/lib/python3.9/test/test_tools/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    n1 sV0    Y  tt jtjdd}|	d W d    n1 s0    Y  t jt
d}| jtjfd}| |d| d S )	Nzfile.cwzint xx;
zfile.pyzxx = 'unaltered'
	fixcid.py)r   z{}:
1
< int xx;
> int yy;
)osmkdirr   TESTFN
addCleanup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   sp  t jd }t|d}|| W d    n1 s40    Y  | t j| dd|gt| }tj	t
d}t td| t tdt| t  ~}t  V ztj|dd W n2 ty }	 z| |	jd	 W Y d }	~	n
d }	~	0 0 W d    n1 s0    Y  W d    n1 s0    Y  W d    n1 s>0    Y  W d    n1 s^0    Y  | S )
Nz.substr   r   z-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&    
(zTest.run_scriptN)r&   )__name__
__module____qualname__r   r   r%   r   r   r   r   r   r      s   r   )ior   r   Zos.pathr-   r,   testr   Ztest.test_toolsr   r   ZunittestZTestCaser   r   r   r   r   <module>   s   