o
    KXh                     @   sx   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 d dlm	Z	m
Z
 e
  G dd dejZedkr:e  dS dS )    N)support)	os_helper)
scriptsdirskip_if_missingc                   @   sX   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   F/opt/python-3.10.19/usr/lib/python3.10/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 s-w   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 sw   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   sD   

  


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%   r4   )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 )Nr5   r6   r7   r8   #! /usr/bin/env python -Rr%   r4   r
   r   r   r   test_pathfixH      z"TestPathfixFunctional.test_pathfixc                 C   s4   |  | dg dd |  | dg dd d S )Nr=   )r6   r7   -kz#! /usr/bin/python3 -Rr5   r8   r>   r
   r   r   r   test_pathfix_keeping_flagsT   r@   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 )Nr5   )r6   r7   -asz#! /usr/bin/python3 -sz#! /usr/bin/env python -Sz#! /usr/bin/env python -V)r6   r7   rC   vrA   z#! /usr/bin/python3 -vV)r6   r7   rC   ZRsz#! /usr/bin/python3 -Rsz!#! /usr/bin/env python -W default)r6   r7   rC   rD   rA   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)r6   r7   rC   z	W defaultrA      z%-a option doesn't support whitespaces)r-   r*   )r4   r
   r   r   r   test_pathfix_adding_errors{   s   
z0TestPathfixFunctional.test_pathfix_adding_errorsN)r   r   r   r   )__name__
__module____qualname__r   r   r   r   r"   r   r4   r<   r?   rB   rF   rH   r   r   r   r   r      s    
'r   __main__)r   r   r   Zunittesttestr   Ztest.supportr   Ztest.test_toolsr   r   ZTestCaser   rI   mainr   r   r   r   <module>   s    u