a
    ze                     @   sh   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 e  G dd dej	Z
edkrde  dS )    N)support)
scriptsdirskip_if_missingc                   @   sT   e Zd ZejedZdd ZdddZ	dd	 Z
d
d Zdd Zdd Zdd ZdS )TestPathfixFunctionalz
pathfix.pyc                 C   s   |  tjtj d S )N)
addCleanupr   unlinkTESTFNself r   2/usr/lib/python3.9/test/test_tools/test_pathfix.pysetUp   s    zTestPathfixFunctional.setUpr    c                 C   s  |rt j|d}|}n
tj}|}t|ddd$}	|	| dd  W d    n1 sZ0    Y  t }
t	j
tj| jg|d|i t jd|
id	d
}|dkr|jdkr| d}| |j|| | |j|
|dt j| | |j|
|dt j| t|ddd}	|	 }W d    n1 s80    Y  |d}| |dd  ddg |d }|jdkr| || |S )Nzscript-A_1.pywutf8)encoding
zprint("Hello world")
z-nZPYTHONIOENCODINGT)envcapture_outputr   r   z: updating
r   zprint("Hello world"))ospathjoinr   r   openwritesysgetfilesystemencoding
subprocessrun
executablescriptenviron
returncodeassertEqualstdoutdecodereplacelinesepstderrreadsplit)r
   ZshebangZpathfix_flagsexitcoder%   r)   	directoryfilenameZpathfix_argfr   procoutputlinesZnew_shebangr   r   r   pathfix   s@    2

  (
zTestPathfixFunctional.pathfixc                 C   sX   t jd }| t j| t| dtj| d}| | j	dddg||dd d S )	Nz.dzrecursedown('z')
#! /usr/bin/env python-i/usr/bin/python3)r-   r)   #! /usr/bin/python3)
r   r   r   rmtreer   mkdirr   basenamer$   r3   )r
   ZtmpdirZexpected_stderrr   r   r   test_recursive:   s    

z$TestPathfixFunctional.test_recursivec                 C   s4   |  | dddgd |  | dddgd d S )Nr4   r5   r6   r7   #! /usr/bin/env python -Rr$   r3   r	   r   r   r   test_pathfixG   s    z"TestPathfixFunctional.test_pathfixc                 C   s4   |  | dg dd |  | dg dd d S )Nr<   )r5   r6   -kz#! /usr/bin/python3 -Rr4   r7   r=   r	   r   r   r   test_pathfix_keeping_flagsS   s    z0TestPathfixFunctional.test_pathfix_keeping_flagsc                 C   s|   |  | dg dd |  | dg dd |  | dg dd |  | dg dd	 |  | d
g dd d S )Nr4   )r5   r6   -asz#! /usr/bin/python3 -sz#! /usr/bin/env python -Sz#! /usr/bin/env python -V)r5   r6   rA   vr?   z#! /usr/bin/python3 -vV)r5   r6   rA   ZRsz#! /usr/bin/python3 -Rsz!#! /usr/bin/env python -W default)r5   r6   rA   rB   r?   z#! /usr/bin/python3 -sW defaultr=   r	   r   r   r   test_pathfix_adding_flag_   sF    z.TestPathfixFunctional.test_pathfix_adding_flagc                 C   s   | j dg dddd d S )Nz#! /usr/bin/env python -E)r5   r6   rA   z	W defaultr?      z%-a option doesn't support whitespaces)r,   r)   )r3   r	   r   r   r   test_pathfix_adding_errorsz   s    z0TestPathfixFunctional.test_pathfix_adding_errorsN)r   r   r   r   )__name__
__module____qualname__r   r   r   r   r!   r   r3   r;   r>   r@   rD   rF   r   r   r   r   r      s     
'r   __main__)r   r   r   Zunittesttestr   Ztest.test_toolsr   r   ZTestCaser   rG   mainr   r   r   r   <module>   s   u