Your IP : 216.73.216.213


Current Path : /opt/alt/python38/lib64/python3.8/test/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/__pycache__/test_os.cpython-38.opt-2.pyc

U

i�f�[�	@s&ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZzddlZWnek
�rdZYnXzddl Z Wnek
�r6dZ YnXzddl!Z!Wnek
�r^dZ!YnXzddl"Z"dd�e"�#�D�Z$Wnee%fk
�r�gZ$YnXzddl&m'Z'm(Z(Wn ek
�r�ej)Z'Z(YnXddl*m+Z+ddl,m-Z-m.Z.d	Z/e0ed
��re�1�dkZ/e0ed��r2ej2j3�r2ej2j3�4d�Z5nd	Z5ej�4d
��oNe�6�dkZ7dd�Z8d�dd�Z9Gdd�dej:�Z;Gdd�dej:�Z<Gdd�dej:�Z=Gdd�dej:�Z>ddlm?Z?Gdd�de?j@�ZAGdd�dej:�ZBe�Ce0ed �d!�Gd"d#�d#eB��ZDGd$d%�d%eB�ZEe�Ce0ed �d!�Gd&d'�d'eD��ZFGd(d)�d)ej:�ZGe�Ce0ed*�d+�Gd,d-�d-ej:��ZHGd.d/�d/ej:�ZIGd0d1�d1ej:�ZJGd2d3�d3ej:�ZKe�Ce0ed4�d5�Gd6d7�d7ej:��ZLe�Md8�d9k�p�e�Md:�d9k�p�e�Md;�d9kZNe�OeNd<�e�Oejd=kd>�Gd?d@�d@ej:���ZPejQd�dAdB��ZRe�Ce0edC�dD�GdEdF�dFej:��ZSe�CejdGkdH�GdIdJ�dJej:��ZTGdKdL�dLej:�ZUGdMdN�dNej:�ZVe�OejdGkdO�GdPdQ�dQej:��ZWe�OejdGkdO�GdRdS�dSej:��ZXe�CejdGkdH�GdTdU�dUej:��ZYe�CejdGkdH�GdVdW�dWej:��ZZe�Ce0edX�dY�GdZd[�d[ej:��Z[e�CejdGkdH�ej\Gd\d]�d]ej:���Z]e�CejdGkdH�Gd^d_�d_ej:��Z^e�CejdGkdH�Gd`da�daej:��Z_ej\Gdbdc�dcej:��Z`Gddde�deej:�ZaGdfdg�dgej:�ZbGdhdi�diej:�ZcGdjdk�dkej:�Zde�edl�e�Ce0edm�dn�Gdodp�dpej:���Zfe�Ce0edq��ode0edr�ds�Gdtdu�duej:��ZgGdvdw�dwejheji�Zje�Ce0edx�dy�Gdzd{�d{ej:��Zkd|d}�Zle�Cel�d~�e�mdd�d��Gd�d��d�ej:���Zne�Ce0ed��d��Gd�d��d�ej:��Zoe�Ce0ed��d��e�md�d��Gd�d��d�ej:���ZpGd�d��d�ej:�ZqGd�d��d�ej:�ZrGd�d��d�ej:�ZsGd�d��d�ej:�Zte�Ce0ed��d��Gd�d��d�ej:��ZuGd�d��d�ej:�ZvGd�d��d�ej:�ZwGd�d��d�ej:�ZxGd�d��d�ej:�Zye0ed���rGd�d��d�ex�Zze{d�k�r"e�|�dS)��N)�support)�win32_is_iotcCsg|]
}|j�qS�)Zpw_uid)�.0�urr�1/opt/alt/python38/lib64/python3.8/test/test_os.py�
<listcomp>0sr)�INT_MAX�PY_SSIZE_T_MAX��assert_python_ok)�
unix_shell�FakePathF�geteuid�thread_infoZlinuxthreadsZfreebsdcCst�tt|�d|�S)Nzrequires os.%s)�unittest�
skipUnless�hasattr�os��namerrr�requires_os_funcMsr�contentc	Cs&t|dd��}|�|�W5QRXdS)N�xbr)�open�write)�filenameZcontent�fprrr�create_fileQsrc@s$eZdZdd�Zdd�Zdd�ZdS)�	MiscTestscCst��}|�|t�dS�N)r�getcwd�assertIsInstance�str��self�cwdrrr�test_getcwdWszMiscTests.test_getcwdc
CsNd}d}d}|d|t|�}t����}t�|���}|}t��}|�||�|t|�ttjj	�}|dkrv�qt|�|kr�|dkr�|d|�}tj�
||�}zt�|�t�|�WnXt
k
r�Y�qYn@tk
�r}	z |	jtjk�rWY��qn�W5d}	~	XYnX|}q>tj�r6tdt|����W5QRXW5QRXdS)Ni���Zpython_test_dir_�arz!Tested current directory length: )�len�tempfileZTemporaryDirectoryrZ
change_cwdrr!�assertEqual�path�sep�join�mkdir�chdir�FileNotFoundError�OSError�errnoZENAMETOOLONG�verbose�print)
r%Zmin_lenZdirlen�dirnameZtmpdirr-�expectedr&Zneed�excrrr�test_getcwd_long_path[s6

zMiscTests.test_getcwd_long_pathcCs.t��}|�|t�|�t�|�t���dSr )r�getcwdbr"�bytesr,�fsdecoder!r$rrr�test_getcwdb�szMiscTests.test_getcwdbN)�__name__�
__module__�__qualname__r'r:r>rrrrrVs5rc@seZdZdd�ZeZdd�Zdd�Zejdd��Z	d	d
�Z
eje�e
ekd�eje
dd
dd�dd����Zdd�Zdd�Ze�ejdkd�dd��Zdd�Zdd�Zdd�Zd d!�Zd"d#�Ze�eed$�d%�d&d'��Ze�eed$�d%�d(d)��Ze�eed$�d%�d*d+��Zd,S)-�	FileTestscCstj�tj�rt�tj�dSr )rr-�lexistsr�TESTFN�unlink�r%rrr�setUp�szFileTests.setUpcCs:t�tjtjtjB�}t�|�|�t�tjtj	��dSr )
rrrrD�O_CREAT�O_RDWR�close�
assertTrue�access�W_OK�r%�frrr�test_access�s
zFileTests.test_accessc	Cs�t�tjtjtjB�}t�|�}zJd}||dkrht�|�|d7}|dkrV|�d�|t�|�}}q&W5t�|�Xt�	||d�|�
ttj|d�dS)Nr��
z%couldn't allocate two consecutive fds��a)
rrrrDrHrI�duprJ�skipTest�
closerange�assertRaisesr3r)r%�first�secondZretriesrrr�test_closerange�s


zFileTests.test_closerangecCs<tj}t�|�}|�ttj|d�t�|�}|�||�dS�Nr)	rrD�sys�getrefcountrX�	TypeErrorr�renamer,)r%r-�old�newrrr�test_rename�s


zFileTests.test_renamec	Cslttjd��V}|�d�|��|��}t�|dd�t�|d�}|�	t
|�t�|�	|d�W5QRXdS)N�w+b�spamr�)rrrDr�flush�filenor�lseek�readr,�typer<)r%�fobj�fd�srrr�	test_read�s
zFileTests.test_readzneeds INT_MAX < PY_SSIZE_T_MAXrRrQF)�sizeZmemuseZdry_runc	CsT|�tjtj�ttjd�ttjd��}t�|��|�}W5QRX|�	|d�dS)Nstest�rb)
�
addCleanuprrErDrrrrjrhr,)r%rpr�datarrr�test_large_read�s
zFileTests.test_large_readc	Cs�t�tjtjtjB�}|�ttj|d�t�|d�t�|t	d��t�|t
d��t�|�ttjd�� }|�|�
���dddg�W5QRXdS)	N�beanssbacon
seggs
sspam
rqsbaconseggsre)rrrrDrH�O_WRONLYrXr_r�	bytearray�
memoryviewrJr,rj�
splitlines)r%rmrlrrr�
test_write�s
�zFileTests.test_writecGs"tj|tjdd�}|�|d�dS)NT)�
creationflags�shellr)�
subprocessZcallZCREATE_NEW_CONSOLEr,)r%�argsZretcoderrr�write_windows_console�s
�zFileTests.write_windows_console�win32z$test specific to the Windows consolecCs*d}|�tjd|�|�tjdd|�dS)Nzprint('x' * 100000)�-cz-u)rr]�
executable�r%�coderrr�test_write_windows_console�sz$FileTests.test_write_windows_consolecGs,t�tjtj�}tj|f|��}|��dSr )rrrrD�O_RDONLY�fdopenrJ)r%r~rmrOrrr�
fdopen_helper�szFileTests.fdopen_helpercCsBt�tjtjtjB�}t�|�|��|�d�|�dd�dS)N�r�d)rrrrDrHrIrJr��r%rmrrr�test_fdopens


zFileTests.test_fdopenc	Cs�tjd}|�tjtj�|�tj|�ttjd�t|d�t�tj|�|�ttj	tj�t
|d��}|�|��d�W5QRXdS)Nz.2�1�2r��1)
rrDrrrErr�replacerXr2�statrr,rj)r%�TESTFN2rOrrr�test_replaces

zFileTests.test_replacecCs"tjttjddd�}t�|�dS)N�)r-�flags�mode�dir_fd)rr�__file__r�rJrNrrr�test_open_keywordss�zFileTests.test_open_keywordsc	Cs@t�td�}z|dtjddd�Wnttfk
r:YnXdS)N�symlink�targetF)�src�dst�target_is_directoryr�)rZ
get_attributerrD�NotImplementedErrorr3)r%r�rrr�test_symlink_keywordss�
zFileTests.test_symlink_keywords�copy_file_rangeztest needs os.copy_file_range()c	Cs(|�t��t�ddd�W5QRXdS)NrrQi����)rX�
ValueErrorrr�rFrrr�#test_copy_file_range_invalid_values"sz-FileTests.test_copy_file_range_invalid_valuesc	
Cstjd}d}ttj|�|�tjtj�ttjd�}|�|j�|��}t|d�}|�tj|�|�|j�|��}zt�	||d�}Wn:t
k
r�}z|jtjkr��|�
|�W5d}~XYnBX|�|tdd��t|d��}|�|��|d|��W5QRXdS)Nz.3�
0123456789rqrd�r�)rrDrrrrErrJrhrr�r3r4�ENOSYSrV�assertIn�ranger,rj)	r%r�rs�in_file�in_fd�out_file�out_fd�i�errr�test_copy_file_range's(

zFileTests.test_copy_file_rangec

CsFtjd}d}d}d}d}ttj|�|�tjtj�ttjd�}|�|j�|��}t|d�}|�tj|�|�|j�|��}	ztj	||	|||d�}
Wn:t
k
r�}z|jtjkr��|�
|�W5d}~XYnnX|�|
td	|d
��t|d��}|��}W5QRX|�|d|�d|�|�||d�||||
��dS)Nz.4r�r��r�rqrd)Z
offset_srcZ
offset_dstrrQ�)rrDrrrrErrJrhrr�r3r4r�rVr�r�rjr,)
r%ZTESTFN4rsZ
bytes_to_copyZin_skipZout_seekr�r�r�r�r�r�rjrrr�test_copy_file_range_offsetIs<


�
�z%FileTests.test_copy_file_range_offsetN) r?r@rArG�tearDownrPr[r�cpython_onlyrcrorrr	r
Z
bigmemtestrtrzrr]�platformr�r�r�r�r�r�rrr�r�r�rrrrrB�s<


�
�
	


!rBc@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�	e
ed�d�d
d��Ze�	e
ed�d�dd��Z
e�	ejdkd�dd��Ze�	ejdkd�e�	e
ed�d�dd���Zdd�Ze�	ejdkd�dd��Ze�	ejdkd�dd ��Ze�	ejdkd�d!d"��Zd#S)$�StatAttributeTestscCs(tj|_|�tj|j�t|jd�dS)N�ABC)rrD�fnamerrrErrFrrrrGxszStatAttributeTests.setUpc
	Cs�t�|�}|�|tjd�|�|jd�t|�}tt�D]d}|dd�dkr:|��}|�d�rjdd�}ndd�}|�|t||��|tt|��|�	||�q:d�
�D]8}tt||�d�}t||d	�d
}|j||dd�q�z|d
|�
d�Wntk
�rYnXzd|_|�
d�Wntk
�r:YnXzd|_|�
d�Wnttfk
�rjYnXzd|_|�
d�Wntk
�r�YnXzt�d�}	|�
d�Wntk
�r�YnXzt�d�}	Wntk
�r�YnXdS)Nr�ZST_ZTIMEcSst|�Sr )�int��xrrr�trunc��z7StatAttributeTests.check_stat_attributes.<locals>.trunccSs|Sr rr�rrrr��r�zst_atime st_mtime st_ctimei��Z_nsi'rS��deltar(�No exception raisedrQ�rR�rrQrSr�rfr�r����	rR���
�)rr�r,�ST_SIZE�st_size�dir�lower�endswith�getattrr��splitr��assertAlmostEqual�fail�
IndexError�st_mode�AttributeError�st_rdevr_�parrot�stat_result)
r%r��result�membersr�attrr�ZfloatyZnanosecondy�result2rrr�check_stat_attributes}s^


�
z(StatAttributeTests.check_stat_attributescCs|�|j�dSr )r�r�rFrrr�test_stat_attributes�sz'StatAttributeTests.test_stat_attributescCsHz|j�t���}Wn$tk
r8|�d|j�YnX|�|�dS)Nz#cannot encode %a for the filesystem)r��encoder]�getfilesystemencoding�UnicodeEncodeErrorrVr�)r%r�rrr�test_stat_attributes_bytes�s
z-StatAttributeTests.test_stat_attributes_bytescCsft�|j�}ttjd�D]F}t�||�}|�d|�|dkrJ|�d|�t�|�}|�	||�qdS)NrQsstat_resultrfscos
stat_result
)
rr�r�r��pickle�HIGHEST_PROTOCOL�dumpsr��loadsr,�r%r��proto�pZ	unpickledrrr�test_stat_result_pickle�s
z*StatAttributeTests.test_stat_result_pickle�statvfsztest needs os.statvfs()cCst�|j�}|�|j|d�d}t|�D]"\}}|�t|d|�||�q*|�t|j	t
��|�t|�d�zd|_|�d�Wnt
k
r�YnXzd|_|�d�Wnt
k
r�YnXzt�d�}|�d�Wntk
r�YnXzt�d�}Wntk
�rYnXdS)	Nr�)
ZbsizeZfrsizeZblocksZbfreeZbavail�filesZffreeZfavail�flagZnamemaxZf_rRrQr�r�r�)rr�r�r,�f_bfree�	enumerater�rK�
isinstance�f_fsidr�r*r�r�r��statvfs_resultr_)r%r�r��value�memberr�rrr�test_statvfs_attributes�s4
z*StatAttributeTests.test_statvfs_attributes�need os.statvfs()cCsft�|j�}ttjd�D]F}t�||�}|�d|�|dkrJ|�d|�t�|�}|�	||�qdS)NrQsstatvfs_resultrfscos
statvfs_result
)
rr�r�r�r�r�r�r�r�r,r�rrr�test_statvfs_result_pickle�s
z-StatAttributeTests.test_statvfs_result_pickler��Win32 specific testsc
Cs\zt�d�WnHtk
r,|�d�Yn,tk
rV}z|�d�W5d}~XYnXdS)Nzc:\pagefile.syszc:\pagefile.sys does not existzCould not stat pagefile.sys)rr�r2rVr3r��r%r�rrr�test_1686475szStatAttributeTests.test_1686475�pipezrequires os.pipe()c	Csht��\}}zt�|�W5t�|�t�|�X|�t��}t�|�W5QRX|�|jjtj	�dSr )
rr�rJr�rXr3r,�	exceptionr4�EBADF)r%r��w�ctxrrr�
test_15261s
zStatAttributeTests.test_15261cCsF|�t|d��|�t|jt��|�d|jko:dkn�dS)N�st_file_attributesrl��)rKrr�rr�)r%r�rrr�check_file_attributes#sz(StatAttributeTests.check_file_attributesz$st_file_attributes is Win32 specificcCszt�|j�}|�|�|�|jtj@d�tjd}t�	|�|�
tj|�t�|�}|�|�|�|jtj@tj�dS)Nrr�)rr�r�rr,r�FILE_ATTRIBUTE_DIRECTORYrrDr0rr�rmdir)r%r�r7rrr�test_file_attributes(s

�




�z'StatAttributeTests.test_file_attributescCsdtj�tjd|j�}|�tj|�t|d�d}t	j
d|ddg|d�t�|�}|�|j
d�dS)	NZTEMPr�r�z
icacls.exez/denyz*S-1-5-32-545:(S)�r{r)rr-r/�environr�rrrrErr}�
check_callr��assertNotEqualr�)r%r�ZDETACHED_PROCESSr�rrr�test_access_denied=s

�
z%StatAttributeTests.test_access_deniedcCs6dtj�t���d}t�|�}|�|jtj�dS)Nz//./r)rr-�
splitdriver!r�r,r��S_IFBLK)r%r�r�rrr�test_stat_block_deviceRs
z)StatAttributeTests.test_stat_block_deviceN)r?r@rArGr�r�r�r�rrrrr�r�r]r�r�rrrrrrrrrr�ws2A

+�

	�

r�c@s�eZdZdd�Zdd�Zd)dd�Zdd	�Zed
d��Zdd
�Z	dd�Z
e�e
je
jkd�dd��Ze�e
je
jkd�dd��Ze�e
je
jkd�dd��Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zejd'd(��ZdS)*�
UtimeTestscCsDtj|_tj�|jd�|_|�tj|j�t�	|j�t
|j�dS)N�f1)rrDr7rr-r/r�rr�rmtreer0rrFrrrrG\s
zUtimeTests.setUpcCs4t�|�}|j|dkp2|j|dkp2|j|dkS)Nr�r�r�)rr��st_atime�st_mtime�st_ctime)r%r�strrr�support_subsecondds
��zUtimeTests.support_subsecondNcCs�|s
|j}|�|�}|r"d}d}nd}d}||||f�t�|�}|rt|j|j|ddd�|j|j|ddd�n$|�|j|d�|�|j|d�|�|j|�|�|j	|�dS)Ni8Z�;l�
o]�rTlP�9��&�.>g���ư>r�)
r�rrr�r�rrr,�st_atime_ns�st_mtime_ns)r%�set_timerr�atime_ns�mtime_nsrrrr�_test_utimels"

zUtimeTests._test_utimecCsdd�}|�|�dS)NcSstj||d�dS�N��ns�r�utime�rr!rrrr�sz'UtimeTests.test_utime.<locals>.set_time�r�r%rrrr�
test_utime�szUtimeTests.test_utimecCs|ddS)Nrg��&�.>rr rrr�	ns_to_sec�szUtimeTests.ns_to_seccs�fdd�}��|�dS)Ncs0|\}}��|�}��|�}t�|||f�dSr �r(rr#�rr!rrZatime�mtimerFrrr�s

z2UtimeTests.test_utime_by_indexed.<locals>.set_timer%r&rrFr�test_utime_by_indexed�sz UtimeTests.test_utime_by_indexedcs�fdd�}��|�dS)Ncs2|\}}��|�}��|�}tj|||fd�dS)N)�timesr)r*rFrrr�s

z0UtimeTests.test_utime_by_times.<locals>.set_timer%r&rrFr�test_utime_by_times�szUtimeTests.test_utime_by_timesz9follow_symlinks support for utime required for this test.cCsdd�}|�|�dS)NcSstj||dd�dS)NF)r!�follow_symlinksr"r$rrrr�sz9UtimeTests.test_utime_nofollow_symlinks.<locals>.set_timer%r&rrr�test_utime_nofollow_symlinks�sz'UtimeTests.test_utime_nofollow_symlinksz,fd support for utime required for this test.cCsdd�}|�|�dS)Nc	Ss.t|dd��}tj|��|d�W5QRXdS)N�wbrr )rrr#rh)rr!rrrrr�sz*UtimeTests.test_utime_fd.<locals>.set_timer%r&rrr�
test_utime_fd�szUtimeTests.test_utime_fdz0dir_fd support for utime required for this test.cCsdd�}|�|�dS)Nc	SsDtj�|�\}}t�|tj�}ztj|||d�W5t�|�XdS)N)r�r!)rr-r�rr�rJr#)rr!r7r�dirfdrrrr�s
z.UtimeTests.test_utime_dir_fd.<locals>.set_timer%r&rrr�test_utime_dir_fd�szUtimeTests.test_utime_dir_fdcCsdd�}|j||jd�dS)NcSstj||d�dSrr"r$rrrr�sz1UtimeTests.test_utime_directory.<locals>.set_time�r)rr7r&rrr�test_utime_directory�szUtimeTests.test_utime_directorycCsbt��}||j�|�|j�s$d}nd}t�|j�}d|j||j|f}|j|j|||d�dS)Ng�?g�������?zst_time=%r, current=%r, dt=%r)r��msg)�timer�rrr�rr�)r%rZcurrentr�rr7rrr�_test_utime_current�s
�
�zUtimeTests._test_utime_currentcs�fdd�}��|�dS)Ncst��j�dSr �rr#r�r5rFrrr�sz/UtimeTests.test_utime_current.<locals>.set_time�r9r&rrFr�test_utime_current�szUtimeTests.test_utime_currentcs�fdd�}��|�dS)Ncst��jd�dSr r:r5rFrrr�sz3UtimeTests.test_utime_current_old.<locals>.set_timer;r&rrFr�test_utime_current_old�sz!UtimeTests.test_utime_current_oldcCsltjdkrhtj�tj�|��dd}ddl}|jj}|�	dd�}|�
|ddddd|t|��}|rh|jSdS)Nr�r�\�r�)
r]r�rr-r�abspath�ctypes�windll�kernel32Zcreate_unicode_bufferZGetVolumeInformationWr*r�)r%r-�rootrArC�buf�okrrr�get_file_system�s

�zUtimeTests.get_file_systemcCsJ|�|j�dkr|�d�d}t�|j||f�|�t�|j�j|�dS)NZNTFSz
requires NTFSr)	rGr7rVrr#r�r,r�r)r%Zlargerrr�test_large_times

zUtimeTests.test_large_timec
Cs�|�t��tj|jddd�W5QRX|�t��t�|jddg�W5QRX|�t��t�|jd�W5QRX|�t��t�|jd�W5QRX|�t��tj|jddgd�W5QRX|�t��tj|jdd�W5QRX|�t��tj|jdd�W5QRXtjtjk�rD|�t��tj|jddd�W5QRXtjtjk�r�t	|jdd	��,}|�t��t�|�
�d�W5QRXW5QRXtjtjk�r�|�t��tj|jdd	d
�W5QRXdS)N)r�r�r r�)r�)r�r�r�F�r/r1r�r�)rXr�rr#r�r_�supports_follow_symlinksr��supports_fdrrh�supports_dir_fd)r%rrrr�test_utime_invalid_argumentss0$z'UtimeTests.test_utime_invalid_argumentsc	Cs�dd�}|�t��tj|j|d�dfd�W5QRX|�t��tj|j|d�dfd�W5QRX|�t��tj|j|d�dfd�W5QRXdS)NcsG�fdd�d�}|�S)NcseZdZ�fdd�ZdS)z?UtimeTests.test_issue31577.<locals>.get_bad_int.<locals>.BadIntcs�Sr r)r~��divmod_ret_valrr�
__divmod__.szJUtimeTests.test_issue31577.<locals>.get_bad_int.<locals>.BadInt.__divmod__N)r?r@rArQrrOrr�BadInt-srRr)rPrRrrOr�get_bad_int,sz/UtimeTests.test_issue31577.<locals>.get_bad_int�*rQr r)rQrSr�)rXr_rr#r�)r%rSrrr�test_issue31577(s""zUtimeTests.test_issue31577)N)r?r@rArGrrr'�staticmethodr(r,r.rrrr#rKr0rLr2rMr4r6r9r<r=rGrHrNrr�rUrrrrr[s:

	�
�
�


r)�
mapping_testsc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Ze�	e
o>ej�
e
�d
�dd��Ze�	e
o^ej�
e
�d
�d
d��Zdd�Zdd�Zdd�Zdd�Ze�	ejd�dd��Ze�dd�dd��Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�ZdS)(�EnvironTestsNcCsBttj�|_tjrttj�|_|����D]\}}|tj|<q*dSr )	�dictrr�_EnvironTests__save�supports_bytes_environ�environb�_EnvironTests__saveb�
_reference�items�r%�keyr�rrrrG?s
zEnvironTests.setUpcCs:tj��tj�|j�tjr6tj��tj�|j�dSr )rr�clear�updaterZr[r\r]rFrrrr�Fs


zEnvironTests.tearDowncCsdddd�S)NZVALUE1ZVALUE2ZVALUE3)ZKEY1ZKEY2ZKEY3rrFrrrr^MszEnvironTests._referencecCstj��tjSr )rrrbrFrrr�_empty_mappingPs
zEnvironTests._empty_mappingzrequires a shellc	CsNtj��tjjdd�t�dt��}|����}|�|d�W5QRXdS)NZWorld)ZHELLOz%s -c 'echo $HELLO')	rrrbrc�popenr
rj�stripr,)r%rer�rrr�test_update2Us

zEnvironTests.test_update2c	Csdt�dt��L}t|�}|�t|�d�|�t|�d�|�t|�d�|�tt|�W5QRXdS)Nz %s -c 'echo "line1
line2
line3"'zline1
zline2
zline3
)rrer
�iterr,�nextrX�
StopIteration)r%re�itrrr�test_os_popen_iter^s�zEnvironTests.test_os_popen_itercCs8tj��D](\}}|�t|�t�|�t|�t�q
dSr )rrr_r,rkr#)r%ra�valrrr�test_keyvalue_typesksz EnvironTests.test_keyvalue_typescCs.|����D]\}}|�tj�|�|�qdSr )r^r_r,rr�getr`rrr�
test_itemspszEnvironTests.test_itemsc
Cs4tj}|�t|�d�d�dd�|��D����dS)Nzenviron({{{}}})z, css|]\}}d�||�VqdS)z
{!r}: {!r}N��format)rrar�rrr�	<genexpr>xs�z-EnvironTests.test___repr__.<locals>.<genexpr>)rrr,�reprrrr/r_)r%�envrrr�
test___repr__us�zEnvironTests.test___repr__c	CsFtj�tj�}ddddg}dtj�|�i}tj}z2t|�t_|�|t���|�|tjdd��W5|t_X|�|t�i��|�dt�ddi��|�|t�|��tj	�rBz&t
jdd	��d
dd�}W5QRXWntk
r�YnX|�
ttj|�|�t�d
di�dg�|�t�d
di�dg�|�t�ddi�dg�dS)Nz/montyz/pythonr?z/flying/circus�PATH�ru�r?T)�recordr�r�)rw�PATHr{�abc�abc)r�defpathr��pathsepr/rrY�assertSequenceEqual�
get_exec_pathr[�warnings�catch_warnings�BytesWarningrXr�)r%Zdefpath_listZ	test_pathZtest_envZ
saved_environZ	mixed_envrrr�test_get_exec_path|s8
���zEnvironTests.test_get_exec_pathz#os.environb required for this test.cCs�d}z|�t��d�}Wn,tk
rDdt��f}|�|�YnX|tjd<|�tjd|�|�tjd|�d}|tjd<|�tjd|�|�	t��d�}|�tjd|�dS)	Nueuro€�surrogateescapez'U+20AC character is not encodable to %sZunicodesunicode��sbytesr<)
r�r]r�r�rVrrr,r\�decode)r%r�Zvalue_bytesr7Z	value_strrrr�
test_environb�s$
��

zEnvironTests.test_environbrRr�cCs@tjdkr&dd}|�ttjj|�nd}|�ttjj|�dS)Nr�r�iP�zkey=)r]r�rXr�rr�__delitem__r3)r%rarrr�test_unset_error�s

zEnvironTests.test_unset_errorc	Cs�d}|�|tj�|�t��}tj|W5QRX|�|jjd|�|�|jj	�|�t��}tj|=W5QRX|�|jjd|�|�|jj	�dS)NZ
missingkeyr)
�assertNotInrrrX�KeyError�assertIsr�r~rK�__suppress_context__)r%Zmissing�cmrrr�
test_key_type�szEnvironTests.test_key_typecCsLt|�}d}t|�dtj|<zt|�|�tj|d�W5tj|=XdS)NZ__new_key__Ztest_environ_iteration)rhrirrr,)r%Z
collection�iteratorZnew_keyrrr�_test_environ_iteration�s
z$EnvironTests._test_environ_iterationcCs|�tj�dSr )r�rrrFrrr�(test_iter_error_when_changing_os_environ�sz5EnvironTests.test_iter_error_when_changing_os_environcCs|�tj���dSr )r�rrr_rFrrr�.test_iter_error_when_changing_os_environ_items�sz;EnvironTests.test_iter_error_when_changing_os_environ_itemscCs|�tj���dSr )r�rr�valuesrFrrr�/test_iter_error_when_changing_os_environ_values�sz<EnvironTests.test_iter_error_when_changing_os_environ_values)r?r@rAZ	type2testrGr�r^rdrrr
rr-�existsrgrlrnrprvr�r[r�rZrequires_mac_verr�r�r�r�r�r�rrrrrX;s8�
�
)�



rXc@sVeZdZdd�Zdd�Zdd�Zddd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�ZdS)�	WalkTestscKs$d|kr|�d�|d<tj|f|�S�Nr/�followlinks)�popr�walk)r%�top�kwargsrrrr��szWalkTests.walkc
Cs*tjj}|�tjtj�|tjd�|_||jd�|_||jd�|_	||jd�}||d�}||jd�}||jd�}||d�}||d�}||d	�|_
|tjd
�}|tjd
d�}	||d�}
||d
�}||d�}t�|j	�t�|�t�|�t�|�||||	|fD].}
t|
d��}|�
d|
d�W5QRX�qt���r�t�tj�|�|j
�t�d|
d�t�|dd�|d�t�|dd�|d�|dd	gdd
ddgf|_n|dgdgf|_t�|d�zt�|�Wn(tk
�r�|�tj|tj�Yn4Xt�|tj�t�|�t�|�|jddd�=dS)NZTEST1�SUB1�SUB11�SUB2ZSUB21�tmp1�tmp2Ztmp3�linkZTEST2�tmp4Zbroken_linkZbroken_link2Zbroken_link3r�zI'm z" and proud of it.  Blame test_os.
ZbrokenTZtmp5rrQ)rr-r/rrrrrD�	walk_path�	sub1_path�
sub11_path�	link_path�makedirsrr�can_symlinkr�r@�	sub2_tree�chmod�listdir�PermissionErrorr��S_IRWXUrEr)r%r/Z	sub2_pathZ
sub21_pathZ	tmp1_pathZ	tmp2_pathZ	tmp3_pathZ	tmp5_pathZt2_pathZ	tmp4_pathZbroken_link_pathZbroken_link2_pathZbroken_link3_pathr-rOrrrrG�sX








 
��

zWalkTests.setUpcCs�t|�|j��}|�t|�d�|ddddk}|dd��|dd|d��|dd|d��|�|d|jddgd	gf�|�|d||jd
gdgf�|�|d||jggf�|�|dd||j�dS)NrfrrQr�r�rS���r�r�r�r�)	�listr�r�r,r*�sortr�r�r��r%�allZflippedrrr�test_walk_topdown>s zWalkTests.test_walk_topdownNcCs�|dkr|j}g}|�|�D],\}}}|�|||f�d|kr|�d�q|�t|�d�|�|d|jdgdgf�|dd��|dd��|�|d|j�dS)Nr�rSrr�r�rQr�)r�r��append�remover,r*r�r�)r%r�r�rD�dirsr�rrr�test_walk_pruneOszWalkTests.test_walk_prunecCs|�t|j��dSr )r�rr�rFrrr�test_file_like_pathbszWalkTests.test_file_like_pathcCs�t|j|jdd��}|�t|�d|�|ddddk}|dd��|dd|d	��|dd|d��|�|d|jdd
gdgf�|�|||jggf�|�||d|jdgd
gf�|�|dd||j�dS)NF��topdownrfr�rQrr�rSr�r�r�r�r�)	r�r�r�r,r*r�r�r�r�r�rrr�test_walk_bottom_upes$
�

���zWalkTests.test_walk_bottom_upcCsht��s|�d�|j|jdd�}|D]2\}}}||jkr&|�|g�|�|dg�qdq&|�d�dS)Nzneed symlink supportTrIr�z+Didn't follow symlink with followlinks=True)rr�rVr�r�r�r,r�)r%�walk_itrDr�r�rrr�test_walk_symlinkzs

zWalkTests.test_walk_symlinkc
Cs�g}|j|j|jd�}t|�\}}}|�|g�d}tj�||�}tj�||d�}t�||�z\dd�|D�}	|�	|�|�
||	�|�
||	�|D]"}
|
|kr�|�tj�||
�|	�q�W5t�||�XdS)N)�onerrorr�z.newcSsg|]\}}}|�qSrr)rr��drOrrrr�sz/WalkTests.test_walk_bad_dir.<locals>.<listcomp>)r�r�r�rir,rr-r/r`rKr�r�)r%�errorsr�rDr�r��dir1Zpath1Zpath1new�roots�dir2rrr�test_walk_bad_dir�s"
zWalkTests.test_walk_bad_dircsd}tj�tjd��tjj�fdg|��}t�|���fdd�td�D�}t|d�D]>}||rjdgnggf}|D]}��t|�|�qvtj�	|�}qZ��fdd�td�D�}�}t|d�D]D}|||kr�dgnggf}|D]}��t|�|�q�tj�|d�}q�dS)	N�Zdeepr�csg|]}�j�dd��qS)Fr��r��r�j��baser%rrr�sz7WalkTests.test_walk_many_open_files.<locals>.<listcomp>r�rQcsg|]}�j�dd��qS)Tr�r�r�r�rrr�s)
rr-r/rrDr�r�r,rir7)r%Zdepthr�Zitersr�r8rkrr�r�test_walk_many_open_files�s"
z#WalkTests.test_walk_many_open_files)N)r?r@rAr�rGr�r�r�r�r�r�r�rrrrr��sE
r��fwalkzTest needs os.fwalk()c@sHeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dZ
dS)�
FwalkTestscks,|j|f|�D]\}}}}|||fVqdSr )r�)r%r�r�rDr�r�Zroot_fdrrrr��szFwalkTests.walkcOstj||�Sr )rr��r%r~r�rrrr��szFwalkTests.fwalkc
Cs�|��}|��}tjddd�D]�\}}|j||d�|j||d�i}tjf|�D]\}}}t|�t|�f||<qR|jf|�D]4\}}}}	|�||�|�	||t|�t|�f�q~qdS)N�TFrS��repeat)r�r�)r�r/)
�copy�	itertools�productrcrr��setr�r�r,)
r%�walk_kwargs�fwalk_kwargsr�r/r8rDr�r��rootfdrrr�_compare_to_walk�szFwalkTests._compare_to_walkcCsdtji}|�||�dS)Nr�)rrDr�)r%r�rrr�test_compare_to_walk�s
zFwalkTests.test_compare_to_walkc	CsJz8t�dtj�}dtji}|��}||d<|�||�W5t�|�XdS)N�.r�r�)rrJrr�rrDr�r�)r%rmr�r�rrr�test_dir_fd�s
zFwalkTests.test_dir_fdcCs|tjddd�D]h\}}tj|df}|j|d|i�D]B\}}}}t�|�t�|�|�t	t�
|��t	|�t	|�B�q2qdS)Nr�rSr�r/)r�r�rrDr�r�fstatr�r,r�r�)r%r�r/r~rDr�r�r�rrr�test_yields_correct_dir_fd�s

z%FwalkTests.test_yields_correct_dir_fdcCs\t�d�}t�|�td�D]}|�tj�D]}q,qt�d�}|�tj|�|�||�dS)NrQ�)	rrUrJr�r�rrDrrr,)r%Zminfdr�r�Znewfdrrr�test_fd_leak�s


zFwalkTests.test_fd_leakN)r?r@rAr�r�r�r�r�r�r�r�rrrrr��s
r�c@seZdZdd�ZdS)�BytesWalkTestsc	ks�d|kr|�d�|d<tjt�|�f|�D]p\}}}t�|�}tttj|��}tttj|��}|||fVtttj|��|dd�<tttj|��|dd�<q*dSr�)r�rr��fsencoder=r��map)	r%r�r��broot�bdirs�bfilesrDr�r�rrrr��s
zBytesWalkTests.walkN)r?r@rAr�rrrrr��sr�c@seZdZddd�ZdS)�BytesFwalkTestsr�cos�tjt�|�f|�|�D]t\}}}}t�|�}tttj|��}	tttj|��}
||	|
|fVtttj|	��|dd�<tttj|
��|dd�<qdSr )rr�r�r=r�r�)r%r�r~r�r�r�r��topfdrDr�r�rrrr�s$
zBytesFwalkTests.fwalkN)r�)r?r@rAr�rrrrr�sr�c@s^eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	�
ejd
kd�dd��Z
dd�ZdS)�MakedirTestscCst�tj�dSr �rr0rrDrFrrrrGszMakedirTests.setUpc
Cs�tj}tj�|ddd�}t�|�tj�|dddd�}t�|�|�ttjtj�tj�|dddddtj�}t�|�tj�|dtjddddd�}t�|�dS�Nr�r�Zdir3Zdir4Zdir5Zdir6)	rrDrr-r/r�rXr3�curdir)r%r�r-rrr�test_makedirs


�zMakedirTests.test_makedirc	Cs�t�d���tj}tj�|d�}tj�|d�}t�|d�|�tj�|��|�tj�	|��tj
dkr�|�t�|�j
d@d�|�t�|�j
d@d�W5QRXdS)NrSr�r�im�ntr�i�)rZ
temp_umaskrDrr-r/r�rKr��isdirrr,r�r�)r%r��parentr-rrr�	test_mode(s
zMakedirTests.test_modecCs�tj�tjd�}d}t�d�}t�||�|�ttj||�|jttj||dd�tj|ddd�tj||dd�t�|�tjtj�	d	�dd�dS)
Nr�r��F��exist_oki�T)r�r��/)
rr-r/rrD�umaskr�rXr3r@)r%r-r��old_maskrrr� test_exist_ok_existing_directory4s

z-MakedirTests.test_exist_ok_existing_directoryc	Cs�tj�tjd�}tj}d}t�d�}z�t�t�	tj�j
�}zt�tj||B�Wntk
rnt
�d��YnXt�	tj�j
|@|kr�t
�d��t�|||B�tj||dd�t�|t�t�	|�j
�|@�tj|||Bdd�W5t�|�XdS)Nr�r�r�zCannot set S_ISGID for dir.z No support for S_ISGID dir mode.Tr�)rr-r/rrDr��S_ISGIDr��S_IMODE�lstatr�r�r�r�SkipTestr�)r%r-r�r�r�Zexisting_testfn_moderrr�test_exist_ok_s_isgid_directoryBs&
�
 z,MakedirTests.test_exist_ok_s_isgid_directoryc	Cs|tj}tj�tjd�}t|d��}|�d�W5QRX|�ttj	|�|jttj	|dd�|jttj	|dd�t�
|�dS)Nr�r�r}Fr�T)rrDrr-r/rrrXr3r�r�)r%r�r-rOrrr�#test_exist_ok_existing_regular_file]sz0MakedirTests.test_exist_ok_existing_regular_filer�zrequires WindowscCsdtj}tj�tj�tjd��}tj|dd�tjd|dgdd�}t�	|�|�
|��|�d��dS)	Nr�i�)r�z	cacls.exez/sZoem)�encodingz6 "D:P(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICI;FA;;;OW)")rrDrr-r@r/r0r}�check_outputrr,rf)r%r�r-�outrrr�test_win32_mkdir_700gs
�z!MakedirTests.test_win32_mkdir_700c	CsLtj�tjdddddd�}tj�|�s>|tjkr>tj�|�}qt�|�dSr�)rr-r/rrDr�r7�
removedirs�r%r-rrrr�ss�zMakedirTests.tearDownN)r?r@rArGr�r�r�rrrrrrrr�rrrrr�s

r��chownzTest needs chownc@s�eZdZedd��Zdd�Ze�ee	d�d�dd��Z
e�eoHee
�d	kd
�dd��Ze�eojee
�d	kd
�dd��Zedd��ZdS)�ChownFileTestscCst�tj�dSr r���clsrrr�
setUpClass�szChownFileTests.setUpClasscCs�t�tj�}|j}|j}ddt�d�t�	dd�fD]0}|�
ttjtj||�|�
ttjtj||�q2|�
t�tj||��|�
t�tjdd��dS)Ng�y��r����rS)rr�rrD�st_uid�st_gid�decimalZDecimal�	fractionsZFractionrXr_r	�assertIsNone)r%r��uid�gidr�rrr�*test_chown_uid_gid_arguments_must_be_index�sz9ChownFileTests.test_chown_uid_gid_arguments_must_be_index�	getgroupszneed os.getgroupscCs�t��}t|�dkr|�d�|dd�\}}t�tj�j}t�tj||�t�tj�j	}|�
||�t�tj||�t�tj�j	}|�
||�dS)NrSztest needs at least 2 groups)rrr*rVr�rrDrr	rr,)r%�groupsZgid_1Zgid_2rrrrr�test_chown_gid�s
zChownFileTests.test_chown_gidrQz0test needs root privilege and more than one usercCsvtdd�\}}t�tj�j}t�tj||�t�tj�j}|�||�t�tj||�t�tj�j}|�||�dS�NrS)	�	all_usersrr�rrDrr	rr,)r%�uid_1�uid_2rrrrr�test_chown_with_root�sz#ChownFileTests.test_chown_with_rootz2test needs non-root account and more than one userc	CsXtdd�\}}t�tj�j}|�t��&t�tj||�t�tj||�W5QRXdSr)	rrr�rrDrrXr�r	)r%rrrrrr�test_chown_without_permission�s
z,ChownFileTests.test_chown_without_permissioncCst�tj�dSr )rrrrDrrrr�
tearDownClass�szChownFileTests.tearDownClassN)r?r@rA�classmethodr
rrrrrr�
root_in_posixr*rrrr rrrrr
s


�

�
r
c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�RemoveDirsTestscCst�tj�dSr )rr�rrDrFrrrrG�szRemoveDirsTests.setUpcCst�tj�dSr )rrrDrFrrrr��szRemoveDirsTests.tearDowncCsxtj�tjd�}t�|�tj�|d�}t�|�t�|�|�tj�|��|�tj�|��|�tj�tj��dS)N�dira�dirb)	rr-r/rrDr0r�assertFalser��r%r$r%rrr�test_remove_all�s


zRemoveDirsTests.test_remove_allcCs�tj�tjd�}t�|�tj�|d�}t�|�ttj�|d��t�|�|�tj�	|��|�
tj�	|��|�
tj�	tj��dS�Nr$r%�file.txt)rr-r/rrDr0rrr&r�rKr'rrr�test_remove_partial�s


z#RemoveDirsTests.test_remove_partialc	Cs�tj�tjd�}t�|�tj�|d�}t�|�ttj�|d��|�t��t�	|�W5QRX|�
tj�|��|�
tj�|��|�
tj�tj��dSr))rr-r/rrDr0rrXr3rrKr�r'rrr�test_remove_nothing�s

z#RemoveDirsTests.test_remove_nothingN)r?r@rArGr�r(r+r,rrrrr#�s

r#c@seZdZdd�ZdS)�DevNullTestsc	CsXttjdd��}|�d�|��W5QRXttjd��}|�|��d�W5QRXdS)Nr1r�hellorqr�)rr�devnullrrJr,rjrNrrr�test_devnull�s

zDevNullTests.test_devnullN)r?r@rAr0rrrrr-�sr-c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�URandomTestscCsr|�tt�d��d�|�tt�d��d�|�tt�d��d�|�tt�d��d�|�tt�d��d�dS)NrrQrRr�i�)r,r*r�urandomrFrrr�test_urandom_length�s
z URandomTests.test_urandom_lengthcCs0t�d�}|�|t�t�d�}|�||�dS�N�)rr2r"r<r
�r%Zdata1Zdata2rrr�test_urandom_value�s

zURandomTests.test_urandom_valuecCs<d�dd|ddf�}td|�}|d}|�t|�|�|S)N�
zimport os, syszdata = os.urandom(%s)zsys.stdout.buffer.write(data)zsys.stdout.buffer.flush()r�rQ)r/rr,r*)r%�countr�r�stdoutrrr�get_urandom_subprocess�s�
z#URandomTests.get_urandom_subprocesscCs$|�d�}|�d�}|�||�dSr4)r;r
r6rrr�test_urandom_subprocesss

z$URandomTests.test_urandom_subprocessN)r?r@rAr3r7r;r<rrrrr1�sr1�	getrandomzneed os.getrandom()c@s@eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�GetRandomTestsc
CsPzt�d�Wn<tk
rJ}z|jtjkr8t�d��n�W5d}~XYnXdS)NrQz%getrandom() syscall fails with ENOSYS)rr=r3r4r�rr)rr9rrrr
szGetRandomTests.setUpClasscCs*t�d�}|�|t�|�t|�d�dSr4)rr=r"r<r,r*�r%rsrrr�test_getrandom_types
z"GetRandomTests.test_getrandom_typecCst�d�}|�|d�dS)Nrr�)rr=r,)r%�emptyrrr�test_getrandom0s
zGetRandomTests.test_getrandom0cCs|�ttd��dS)N�GRND_RANDOM)rKrrrFrrr�test_getrandom_random#sz$GetRandomTests.test_getrandom_randomcCs,zt�dtj�Wntk
r&YnXdS�NrQ)rr=�
GRND_NONBLOCK�BlockingIOErrorrFrrr�test_getrandom_nonblock)sz&GetRandomTests.test_getrandom_nonblockcCs$t�d�}t�d�}|�||�dSr4)rr=r
r6rrr�test_getrandom_value1s

z#GetRandomTests.test_getrandom_valueN)
r?r@rAr!r
r@rBrDrHrIrrrrr>s
r>ZHAVE_GETENTROPYrQZHAVE_GETRANDOMZHAVE_GETRANDOM_SYSCALLz*os.random() does not use a file descriptorZvxworksz$VxWorks can't set RLIMIT_NOFILE to 1c@s0eZdZe�ed�dd��Zdd�Zdd�ZdS)	�URandomFDTestsz!test requires the resource modulecCsd}td|�dS)Na�if 1:
            import errno
            import os
            import resource

            soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
            resource.setrlimit(resource.RLIMIT_NOFILE, (1, hard_limit))
            try:
                os.urandom(16)
            except OSError as e:
                assert e.errno == errno.EMFILE, e.errno
            else:
                raise AssertionError("OSError not raised")
            r�rr�rrr�test_urandom_failureCsz#URandomFDTests.test_urandom_failurecCsd}td|�\}}}dS)Naif 1:
            import os
            import sys
            import test.support
            os.urandom(4)
            with test.support.SuppressCrashReport():
                os.closerange(3, 256)
            sys.stdout.buffer.write(os.urandom(4))
            �-Scr)r%r��rcr�errrrr�test_urandom_fd_closedZs	z%URandomFDTests.test_urandom_fd_closedcCs�|�tjtj�ttjd�djtjd�}td|�\}}}|�t|�d�|�	|dd�|dd��td|�\}}}|�t|�d�|�	||�dS)Nsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxa�if 1:
            import os
            import sys
            import test.support
            os.urandom(4)
            with test.support.SuppressCrashReport():
                for fd in range(3, 256):
                    try:
                        os.close(fd)
                    except OSError:
                        pass
                    else:
                        # Found the urandom fd (XXX hopefully)
                        break
                os.closerange(3, 256)
            with open({TESTFN!r}, 'rb') as f:
                new_fd = f.fileno()
                # Issue #26935: posix allows new_fd and fd to be equal but
                # some libc implementations have dup2 return an error in this
                # case.
                if new_fd != fd:
                    os.dup2(new_fd, fd)
                sys.stdout.buffer.write(os.urandom(4))
                sys.stdout.buffer.write(os.urandom(4))
            )rDrLr�rrf)
rrrrErDrrrrr,r*r
)r%r�rMrrNZout2Zerr2rrr�test_urandom_fd_reopenedhs�z'URandomFDTests.test_urandom_fd_reopenedN)	r?r@rArr�resourcerKrOrPrrrrrJ>s

rJc#slg��fdd�}�fdd�}z6tj}tj}tj}|t_|t_|dk	rJ|t_�VW5|t_|t_|t_XdS)Ncs��d||f�td��dS)N�execvzexecv called)r��RuntimeError�rr~��callsrr�
mock_execv�sz#_execvpe_mockup.<locals>.mock_execvcs ��d||f�ttjd��dS)N�execvez
execve called)r�r3r4ZENOTDIRrTrUrr�mock_execve�sz$_execvpe_mockup.<locals>.mock_execve)rrRrXr~)r~rWrYZ
orig_execvZorig_execveZorig_defpathrrUr�_execvpe_mockup�s	
rZrRzneed os.execv()c@steZdZe�ed�dd��Zdd�Zdd�Ze�	e
ed�d	�d
d��Zdd
�Z
dd�Ze�	ejdkd�dd��ZdS)�	ExecTestsz4avoid triggering a linuxthreads bug: see issue #4970cCs|�ttjddgd�dS)Nzno such app-)rXr3r�execvperFrrr�test_execvpe_with_bad_program�s�z'ExecTests.test_execvpe_with_bad_programcCsN|�ttjdd�|�ttjdg�|�ttjdd�|�ttjddg�dS)N�notepadrryr?)rXr�rrRrFrrr�test_execv_with_bad_arglist�sz%ExecTests.test_execv_with_bad_arglistcCsB|�ttjdgd�|�ttjdgi�|�ttjddgi�dS)Nr^r?)rXr�rr\rFrrr�test_execvpe_with_bad_arglist�sz'ExecTests.test_execvpe_with_bad_arglist�_execvpez)No internal os._execvpe function to test.c
	Cs�tjd}|tkr:d}tj�t�|�|�}|}dddg}n6d}dddg}tj�||�}tjdkrlt�|�}n|}d	d
i}t��@}|�t	tj
||�|�t|�d�|�|dd
||ff�W5QRXt|d��F}|jt
tj
|||d�|�t|�d�|�|dd|||ff�W5QRXt��j}|��}	|tk�r>||	d<n||	d<|jt
tj
|||	d�|�t|�d�|�|dd|||	ff�W5QRXdS)NZabsolutepaths
executablesprognameZarg1Zarg2r�Zprognamer�ZspamrurQrrR)r~rxrXr{rw)rr.r<r-r/r�rrZrXrSrar,r*r3r�r�)
r%Z	test_typeZprogram_pathZprogram�fullpathZnative_fullpathZ	argumentsrurVZenv_pathrrr�_test_internal_execvpe�s^


�"�
�

�
�z ExecTests._test_internal_execvpecCs"|�t�tjdkr|�t�dS)Nr�)rcr#rrr<rFrrr�test_internal_execvpe_str�s

z#ExecTests.test_internal_execvpe_strc	Cs�tjddg}tj��}d|d<|�t��t�|d||�W5QRXtj��}d|d<|�t��t�|d||�W5QRXtj��}d|d	<|�t��t�|d||�W5QRXdS)
Nr��pass�cabbage�FRUITVEGETABLEr�orangeVEGETABLE=cabbage�FRUIT�lemon�FRUIT=ORANGE)r]r�rrr�rXr�rX)r%r~�newenvrrr�test_execve_invalid_env�s


z!ExecTests.test_execve_invalid_envr�zWin32-specific testc
Cs`zt�ddgi�Wn<tk
rP}z|�|jdkp<|jdk�W5d}~XYnX|�d�dS)Nr?�argrzNo OSError raised)rrXr3rKZwinerrorr�r�rrr�test_execve_with_empty_paths
,z%ExecTests.test_execve_with_empty_pathN)r?r@rAr�skipIf�USING_LINUXTHREADSr]r_r`rrrrcrdrmr]r�rorrrrr[�s�
�
/r[r�r�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�Win32ErrorTestsc
Csvzt�tj�WnPtk
r(d}YnJtk
r`}zd}|�dtj|f�W5d}~XYnX|�dtj�dS)NFTz.file %s must not exist; os.stat failed with %szfile %s must not exist)rr�rrDr2r3r�)r%r�r9rrrrGs�zWin32ErrorTests.setUpcCs|�ttjtjtjd�dS)Nz.bak)rXr3rr`rrDrFrrrrc(szWin32ErrorTests.test_renamecCs|�ttjtj�dSr )rXr3rr�rrDrFrrr�test_remove+szWin32ErrorTests.test_removecCs|�ttjtj�dSr )rXr3rr1rrDrFrrr�
test_chdir.szWin32ErrorTests.test_chdirc	Cs>|�tjtj�ttjd��}|�ttjtj�W5QRXdS)Nr�)	rrrrErDrrXr3rr0rNrrr�
test_mkdir1szWin32ErrorTests.test_mkdircCs|�ttjtjd�dSr )rXr3rr#rrDrFrrrr'7szWin32ErrorTests.test_utimecCs|�ttjtjd�dSr\)rXr3rr�rrDrFrrr�
test_chmod:szWin32ErrorTests.test_chmodN)
r?r@rArGrcrsrtrur'rvrrrrrrsrrc	@s�eZdZddddddddd	g	Zd
d�ZeD]Zee�e�de<q*d
d�Ze�	e
ed�d�dd��Ze�	e
ed�d�dd��Z
e�	e
ed�d�dd��Ze�	e
ed�d�dd��Ze�	e
ed�d �d!d"��Ze�	e
ed#�d$�d%d&��Ze�	e
ed'�d(�d)d*��Ze�	e
ed+�d,�d-d.��Ze�	e
ed/�d0�d1d2��Ze�	e
ed3�d4�d5d6��Ze�	e
ed7�d8�d9d:��Ze�	e
ed;�d<�d=d>��Ze�	e
ed?�d@�dAdB��ZdCdD�Ze�	e
edE�dF�dGdH��ZdIS)J�
TestInvalidFD�fchdirrUr��	fdatasyncr��fstatvfs�fsync�	tcgetpgrp�ttynamecs�fdd�}|S)Ncstt��r|�tt���dSr )rr�checkr�rF�rOrr�helperDs
z(TestInvalidFD.get_single.<locals>.helperr)rOr�rrr�
get_singleCszTestInvalidFD.get_singleZtest_c
Gs\z|t��f|��Wn2tk
rH}z|�|jtj�W5d}~XYnX|�d|�dS)Nz5%r didn't raise an OSError with a bad file descriptor)r�make_bad_fdr3r,r4r�r�)r%rOr~r�rrrr~Ks"�zTestInvalidFD.check�isattyztest needs os.isatty()cCs|�t�t���d�dS�NF)r,rr�rr�rFrrr�test_isattyTszTestInvalidFD.test_isattyrWztest needs os.closerange()c	Cstt��}td�D]0}zt�||�Wntk
r:YqXqBq|dkrTt�d��|�t�	|||d�d�dS)NrRrSz5Unable to acquire a range of invalid file descriptorsrQ)
rr�r�rr�r3rrr,rW)r%rmr�rrrr[Xs�zTestInvalidFD.test_closerange�dup2ztest needs os.dup2()cCs|�tjd�dS)N�)r~rr�rFrrr�	test_dup2hszTestInvalidFD.test_dup2�fchmodztest needs os.fchmod()cCs|�tjd�dSr\)r~rr�rFrrr�test_fchmodlszTestInvalidFD.test_fchmod�fchownztest needs os.fchown()cCs|�tjdd�dS)Nr�)r~rr�rFrrr�test_fchownpszTestInvalidFD.test_fchown�	fpathconfztest needs os.fpathconf()cCs |�tjd�|�tjd�dS)N�PC_NAME_MAX)r~r�pathconfr�rFrrr�test_fpathconftszTestInvalidFD.test_fpathconf�	ftruncateztest needs os.ftruncate()cCs |�tjd�|�tjd�dSr\)r~r�truncater�rFrrr�test_ftruncateyszTestInvalidFD.test_ftruncateriztest needs os.lseek()cCs|�tjdd�dSr\)r~rrirFrrr�
test_lseek~szTestInvalidFD.test_lseekrjztest needs os.read()cCs|�tjd�dSrE)r~rrjrFrrrro�szTestInvalidFD.test_read�readvztest needs os.readv()cCstd�}|�tj|g�dS)NrR)rwr~rr�)r%rErrr�
test_readv�szTestInvalidFD.test_readv�	tcsetpgrpztest needs os.tcsetpgrp()cCs|�tjd�dSr\)r~rr�rFrrr�test_tcsetpgrpt�szTestInvalidFD.test_tcsetpgrptrztest needs os.write()cCs|�tjd�dS)N� )r~rrrFrrrrz�szTestInvalidFD.test_write�writevztest needs os.writev()cCs|�tjdg�dS)Nr|)r~rr�rFrrr�test_writev�szTestInvalidFD.test_writevcCs|�tj�|�tjd�dS�NT)r~r�get_inheritable�set_inheritablerFrrr�test_inheritable�szTestInvalidFD.test_inheritable�get_blocking�-needs os.get_blocking() and os.set_blocking()cCs|�tj�|�tjd�dSr�)r~rr��set_blockingrFrrr�
test_blocking�szTestInvalidFD.test_blockingN)r?r@rAZsinglesr�rO�localsr~rrrrr�r[r�r�r�r�r�r�ror�r�rzr�r�r�rrrrrw>sR
�	












�rwc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�	LinkTestscCs tj|_tj�tjd�|_dS)N�2)rrD�file1rr-r/�file2rFrrrrG�szLinkTests.setUpcCs,|j|jfD]}tj�|�rt�|�qdSr )r�r�rr-r�rE)r%�filerrrr��szLinkTests.tearDownc
Cs�t|�zt�||�Wn0tk
rH}z|�d|�W5d}~XYnXt|d��8}t|d��"}|�tj�|�	�|�	���W5QRXW5QRXdS)N�
os.link(): %sr�)
rrr�r�rVrrKr-�sameopenfilerh)r%r�r�r�r�f2rrr�
_test_link�s zLinkTests._test_linkcCs|�|j|j�dSr )r�r�r�rFrrr�	test_link�szLinkTests.test_linkcCs(|�t|jt���t|jt����dSr )r�r<r�r]r�r�rFrrr�test_link_bytes�s�zLinkTests.test_link_bytescCs\zt�d�Wntk
r,t�d��YnX|jd7_|jd|_|�|j|j�dS)N�ñz#Unable to encode for this platform.r�)rr��UnicodeErrorrrr�r�r�rFrrr�test_unicode_name�szLinkTests.test_unicode_nameN)	r?r@rArGr�r�r�r�r�rrrrr��s
r�zPosix specific testsc@s�eZdZdZdZe�eed�d�dd��Z	e�eed�d�dd	��Z
e�eed
�d�dd
��Ze�eed�d�dd��Ze�eed�d�dd��Z
e�eed�d�dd��Ze�eed�d�dd��Ze�eed�d�dd��ZdS)�PosixUidGidTests��setuidztest needs os.setuid()cCsBt��dkr|�ttjd�|�ttjd�|�ttj|j�dS�Nrz
not an int)r�getuidrXr3r�r_�
OverflowError�UID_OVERFLOWrFrrr�test_setuid�szPosixUidGidTests.test_setuid�setgidztest needs os.setgid()cCsFt��dkr ts |�ttjd�|�ttjd�|�ttj|j�dSr�)	rr��HAVE_WHEEL_GROUPrXr3r�r_r��GID_OVERFLOWrFrrr�test_setgid�szPosixUidGidTests.test_setgid�seteuidztest needs os.seteuid()cCsBt��dkr|�ttjd�|�ttjd�|�ttj|j�dSr�)	rr�rXr3r�r_�setegidr�r�rFrrr�test_seteuid�szPosixUidGidTests.test_seteuidr�ztest needs os.setegid()cCsFt��dkr ts |�ttjd�|�ttjd�|�ttj|j�dSr�)	rr�r�rXr3r�r_r�r�rFrrr�test_setegid�szPosixUidGidTests.test_setegid�setreuidztest needs os.setreuid()cCsnt��dkr|�ttjdd�|�ttjdd�|�ttjdd�|�ttj|jd�|�ttjd|j�dSr�)rr�rXr3r�r_r�r�rFrrr�
test_setreuid�szPosixUidGidTests.test_setreuidcCst�tjddg�dS)Nr�z,import os,sys;os.setreuid(-1,-1);sys.exit(0)�r}r	r]r�rFrrr�test_setreuid_neg1�s
�z#PosixUidGidTests.test_setreuid_neg1�setregidztest needs os.setregid()cCsrt��dkr"ts"|�ttjdd�|�ttjdd�|�ttjdd�|�ttj|jd�|�ttjd|j�dSr�)	rr�r�rXr3r�r_r�r�rFrrr�
test_setregid�szPosixUidGidTests.test_setregidcCst�tjddg�dS)Nr�z,import os,sys;os.setregid(-1,-1);sys.exit(0)r�rFrrr�test_setregid_neg1s
�z#PosixUidGidTests.test_setregid_neg1N)r?r@rAr�r�rrrrr�r�r�r�r�r�r�r�rrrrr��s$






r�c@sNeZdZdd�Zdd�Zdd�Zdd�Ze�e	e
d	�d
�dd��Zd
d�ZdS)�Pep383Testscs�tjrtj|_ntjr tj|_ntj|_t�|j�|_g��fdd�}|tj�tjr`|tj�tjrp|tj��s~|�	d�t
�|_t�|j�zL�D]B}t�
tj�|j|��t�|�}||jkr�td��|j�|�q�Wnt�|j��YnXdS)Ncs4zt�|�}Wntk
r$YdSX��|�dSr )rr�r�r�)�fn��bytesfnrr�add_filenames
z'Pep383Tests.setUp.<locals>.add_filenamez&couldn't create any non-ascii filenamezduplicate filename)r�TESTFN_UNENCODABLEr�ZTESTFN_NONASCIIrDrr�ZbdirZTESTFN_UNICODErVr��	unicodefnr0Zcreate_empty_filer-r/r=r��add�shutilr)r%r�r�rr�rrG
s6







zPep383Tests.setUpcCst�|j�dSr )r�rr�rFrrrr�2szPep383Tests.tearDownc	Csl|j}tt�|j��}|�||�t��}z0t�tj�|�tt���tt�tj���W5t�|�XdSr )	r�r�rr�r�r,r!r1r.)r%r8�foundZcurrent_directoryrrr�test_listdir5s$zPep383Tests.test_listdircCs.|jD]"}ttj�|j|�d�}|��qdS�Nrq)r�rrr-r/r�rJ)r%r�rOrrr�	test_openAs
zPep383Tests.test_openr�r�cCs*|jD]}tj�|j|�}t�|�qdSr )r�rr-r/r�r�)r%r��fullnamerrr�test_statvfsFs
zPep383Tests.test_statvfscCs&|jD]}t�tj�|j|��qdSr )r�rr�r-r/r�)r%r�rrr�	test_statOs
zPep383Tests.test_statN)
r?r@rArGr�r�r�rrrrr�r�rrrrr�s%�
r�c@sFeZdZdd�Zdd�Zdd�Zdd�Ze�d	�d
d��Z	dd
�Z
dS)�Win32KillTestscCsvddl}ddlm}ddl}|jjj}|j|_|j|�	|j
�|j|�	|j�|�	|j�|�	|j�f|_d}t
jtjdd�|�gt
jt
jt
jd�}|�|jj�|�|jj�|�|jj�d\}}	||	k�rJ|��dk�rJ|�t|��}
||�|j���|
|�|
�ddd�}|�|dd�|
j�r6|� ||
j�!���qTt"�#d	�|d
7}q�|�$d�t%�&|j'|�|� |�(�|�dS)Nr��wintypes�runningr�z<import sys;sys.stdout.write('{}');sys.stdout.flush();input())r:�stderr�stdin�rr�zPeekNamedPipe failed皙�����?rQz1Did not receive communication from the subprocess))rAr��msvcrtrBrC�
PeekNamedPipe�BOOL�restype�HANDLE�POINTERZc_char�DWORD�argtypesr}�Popenr]r�rr�PIPErrr:rJr�r��pollZcreate_string_bufferr*Z
get_osfhandlerhZsizeofr
r�r,r�r8�sleepr�r�kill�pid�wait)r%ZsigrAr�r�r�r7�procr9�maxrEZrsltrrr�_killUsX




�
����


zWin32KillTests._killcCs|�tj�dSr )r��signal�SIGTERMrFrrr�test_kill_sigterm�sz Win32KillTests.test_kill_sigtermcCs|�d�dS)Nr�)r�rFrrr�
test_kill_int�szWin32KillTests.test_kill_intcCs�dt��}t�dd|�}d|d<tjtjtj�	tj�
t�d�|gtjd�}d\}}||kr�|�
�dkr�|ddkrvq�t�d�|d7}qTt�|jtj�|�d	�t�|j|�t�d
�|�
�s�t�|jtj�|�d�|��dS)Nz
test_os_%sr�rQrzwin_console_handler.pyrr�r�z'Subprocess didn't finish initializationg�?zsubprocess did not stop on {})�uuidZuuid1�mmapr}r�r]r�rr-r/r7r�ZCREATE_NEW_PROCESS_GROUPr�r8r�r�r�r��SIGINTr�rr)r%ZeventrZtagname�mr�r9r�rrr�_kill_with_event�s0���



zWin32KillTests._kill_with_eventz.subprocesses aren't inheriting Ctrl+C propertycCsdddlm}ddl}|�|j��}|jjj}|�|j�|jf|_|j|_	||d�|�
tjd�dS)Nrr��CTRL_C_EVENT)
rAr�r�Zc_intrBrC�SetConsoleCtrlHandlerr�r�r�r�r�r�)r%r�rAZNULLr�rrr�test_CTRL_C_EVENT�s

�
z Win32KillTests.test_CTRL_C_EVENTcCs|�tjd�dS)N�CTRL_BREAK_EVENT)r�r�rrFrrr�test_CTRL_BREAK_EVENT�sz$Win32KillTests.test_CTRL_BREAK_EVENTN)r?r@rAr�r�r�r�r�skipr�rrrrrr�Ss6
r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�Win32ListdirTestsc
Cs�g|_td�D]r}d|}tj�tj|�}d|}tj�tj|�}t�|�t|d��}|�	d|�W5QRX|j�
||g�q|j��dS)NrSzSUB%dzFILE%dr�z'I'm %s and proud of it. Blame test_os.
)�
created_pathsr�rr-r/rrDr�rr�extendr�)r%r�Zdir_nameZdir_path�	file_nameZ	file_pathrOrrrrG�s
zWin32ListdirTests.setUpcCst�tj�dSr )r�rrrDrFrrrr��szWin32ListdirTests.tearDowncCsH|�tt�tj��|j�|�tt�t�tj���dd�|jD��dS)NcSsg|]}t�|��qSr�rr��rr-rrrr�szCWin32ListdirTests.test_listdir_no_extended_path.<locals>.<listcomp>)r,�sortedrr�rrDrr�rFrrr�test_listdir_no_extended_path�s��z/Win32ListdirTests.test_listdir_no_extended_pathcCshdtj�tj�}|�tt�|��|j�dt�	tj�tj��}|�tt�|��dd�|jD��dS)N�\\?\�\\?\cSsg|]}t�|��qSrrrrrrr�sz@Win32ListdirTests.test_listdir_extended_path.<locals>.<listcomp>)
rr-r@rrDr,r	r�rr�rrrr�test_listdir_extended_path�s��z,Win32ListdirTests.test_listdir_extended_pathN)r?r@rArGr�r
r
rrrrr�s
r�readlinkzneeds os.readlink()c@szeZdZdZej�e�Ze�	e�Z
e�	e�Zdd�Zdd�Z
dd�Zdd	�Zejd
d��Zejdd
��Zejdd��ZdS)�
ReadlinkTestsZreadlinktestcCsbtj�|�}tj�|�}tjdkrRdd�}||�r>|dd�}||�rR|dd�}|�||�dS)Nr�cSs|�t|t�rdnd�S)Nrr)�
startswithr�r<)r�rrr�<lambda>	s�z/ReadlinkTests.assertPathEqual.<locals>.<lambda>rf)rr-�normcaser]r�r,)r%�left�rightZ
has_prefixrrr�assertPathEqual�s
zReadlinkTests.assertPathEqualcCsT|�tj�|j��|�tj�|j��|�tj�|j��|�tj�|j��dSr )	rKrr-r��filelink_target�filelinkb_targetr&�filelink�	filelinkbrFrrrrG	szReadlinkTests.setUpcCs0t|j�}|�ttj|j�|�ttj|�dSr )rrrXr3rr)r%rrrr�test_not_symlink	s
zReadlinkTests.test_not_symlinkcCs(|�ttjd�|�ttjtd��dS)Nzmissing-link)rXr2rrrrFrrr�test_missing_link	s
�zReadlinkTests.test_missing_linkcCsBt�|j|j�|�tj|j�t|j�}|�t�	|�|j�dSr )
rr�rrrrrrErrr)r%rrrr�
test_pathlike	s
zReadlinkTests.test_pathlikecCsNt�|j|j�|�tj|j�t�t|j��}|�	||j�|�
|t�dSr )rr�rrrrrrErrrr"r<rrrr�test_pathlike_bytes#	s
z!ReadlinkTests.test_pathlike_bytescCsJt�|j|j�|�tj|j�t�|j�}|�||j�|�	|t
�dSr )rr�rrrrrrErrr"r<rrrr�
test_bytes+	s
zReadlinkTests.test_bytesN)r?r@rArrr-r@r�rr�rrrrGrrr�skip_unless_symlinkrrrrrrrr�s



rc@s�eZdZdZej�e�ZdZ	ej�
e�ZdZdd�Z
dd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Ze�ej�d�o�ej�d�d�dd��Zdd�Zdd �Zd!S)"�Win32SymlinkTestsZfilelinktestZdirlinktestzmissing linkcCsdSr rrFrrrrG=	szWin32SymlinkTests.setUpcCsRtj�|j�rt�|j�tj�|j�r4t�|j�tj�|j�rNt�|j�dSr )	rr-r�rr��dirlinkrrC�missing_linkrFrrrr�D	szWin32SymlinkTests.tearDowncCs`t�|j|j�|�tj�|j��|�tj�|j��|�tj�|j��|�	|j|j�dSr )
rr��dirlink_targetr!rKr-r�r��islink�
check_statrFrrr�test_directory_linkL	s
z%Win32SymlinkTests.test_directory_linkcCs`t�|j|j�|�tj�|j��|�tj�|j��|�tj�|j��|�	|j|j�dSr )
rr�rrrKr-r��isfiler$r%rFrrr�test_file_linkS	s
z Win32SymlinkTests.test_file_linkcCs6|j}tj�|�rt�|�d}d}t�|||�dS)Nz"c:\\target does not exist.29r3c740T)r"rr-rCr�r�)r%Zlinknamer�Z
target_is_dirrrr�_create_missing_dir_linkZ	s
z*Win32SymlinkTests._create_missing_dir_linkcCs|��t�|j�dSr )r)rr�r"rFrrr�,test_remove_directory_link_to_missing_targetd	sz>Win32SymlinkTests.test_remove_directory_link_to_missing_targetcCs |��|�tj�|j��dSr )r)r&rr-r�r"rFrrr�.test_isdir_on_directory_link_to_missing_targetk	sz@Win32SymlinkTests.test_isdir_on_directory_link_to_missing_targetcCs|��t�|j�dSr )r)rrr"rFrrr�.test_rmdir_on_directory_link_to_missing_targeto	sz@Win32SymlinkTests.test_rmdir_on_directory_link_to_missing_targetcCsn|�t�|�t�|��|�t�|�t�|��t�|�}|�t�|�t�|��|�t�|�t�|��dSr )r,rr�r
r�r�)r%r�r�Z
bytes_linkrrrr%s	s

zWin32SymlinkTests.check_statc	Cs@tj�tj�}tj�|d�}tj�|d�}|�tj|�t�|�t�|�t�|�tj�tj�|d��}t	|�t�
�}z�t�|�tj�|d�}t�tj�
|�d�|�dt�t�
���|�t�|�t�d��t�|�|�t�|�t�tj�
|���t�|�|�t�|�t�tj�
|���W5t�|�XdS)N�level2�level3r�r�)rr-r@rrDr/rrrr0rr!r1r��relpathr�r�r,r�)r%Zlevel1r-r.r�Zorig_dirr�rrr�
test_12084{	s2




�
�zWin32SymlinkTests.test_12084�C:\Users\All Users�C:\ProgramDatazTest directories not foundcCs"t�d�}|�tj�|d��dS)Nr1r2)rrrKr-�samefile)r%r�rrr�
test_29248�	s
zWin32SymlinkTests.test_29248c	Cs�d}tjj|gd�}d||f||f|dd�|dd�fg}|D]�\}}zt�||�Wntk
rpYn&Xzt�|�Wntk
r�YnXzt�t�|�t�|��Wntk
r�YqDXzt�|�WqDtk
r�YqDXqDdS)NZXXXXXXXXXXXXXXXXXXXXXXXXXXXrRr>�)rr-r/r�r2r�r3r�)r%Zsegmentr-Z
test_casesr��destrrr�test_buffer_overflow�	s.
�z&Win32SymlinkTests.test_buffer_overflowcs�tj�d��tj���s"|�d��fdd�t�t���d�D�}|D]\}tj	r`t
�t
d|�t�|�}|�|t�
|��|�t
�|j��|�|jt
j�q�qF|�d�dS)Nz$%LOCALAPPDATA%\Microsoft\WindowsAppsz%test requires a WindowsApps directorycsg|]}tj��|��qSr)rr-r/�rr)�rDrrr�	s�z6Win32SymlinkTests.test_appexeclink.<locals>.<listcomp>z*.exezTesting withz$test requires an app execution alias)rr-�
expandvarsr�rV�fnmatch�filterr�rr5r6r�r,r�r&�S_ISLNKr�Zst_reparse_tagZIO_REPARSE_TAG_APPEXECLINK)r%�aliases�aliasrrr9r�test_appexeclink�	s 

�

z"Win32SymlinkTests.test_appexeclinkN)r?r@rArrr-r@r�rr!r7r#r"rGr�r&r(r)r*r+r,r%r0rrrCr�r4r7r@rrrrr 4	s,
#
�
#r c@sDeZdZdZej�ej�e��Z	dd�Z
dd�Zdd�Zdd	�Z
d
S)�Win32JunctionTestsZjunctiontestcCsdSr rrFrrrrG�	szWin32JunctionTests.setUpcCstj�|j�rt�|j�dSr )rr-rC�junctionrErFrrrr��	szWin32JunctionTests.tearDowncCs�t�|j|j�|�tj�|j��|�tj�|j��|�tj�	|j��|�
t�|j�t�|j��|�
t�|j�t�|j��|�tj�|j��|�
tj�d|j�tj�t�|j���dS)Nr)�_winapi�CreateJunction�junction_targetrBrKrr-rCr�r�r
r�r�r,r&r$rrrFrrr�test_create_junction�	s�z'Win32JunctionTests.test_create_junctioncCs\t�|j|j�|�tj�|j��|�tj�|j��t�	|j�|�
tj�|j��dSr )rCrDrErBrKrr-r�rCrEr&rFrrr�test_unlink_removes_junction�	s
z/Win32JunctionTests.test_unlink_removes_junctionN)r?r@rArBrr-r7r@r�rErGr�rFrGrrrrrA�	s
rAc@seZdZdd�ZdS)�Win32NtTestsc
Cs0t�d�}t�d�}ddl}|jddd�}|jj|j_|jj|j	_|jj|jj
f|j	_|��}|j��}|�	||�
|��}|�d|�|j}dd	d
tg}td�D]V}	|D]L}
z|�|
�Wntk
r�YnXzt�|
�Wq�tk
r�Yq�Xq�q�|�	||�
|��}|�d|�|j|}|�d|�dS)Nr�rArzKernel32.dllT)Zuse_last_errorrQz\\?\C:z\\?\NULz	\\?\CONINrR)r�
import_moduleZctypes.wintypesZWinDLLr�r�ZGetCurrentProcessr�r�ZGetProcessHandleCountZLPDWORDr�r�Zbyrefr,r�r�r�Z_getfinalpathname�	Exceptionrr�)r%r�rAZkernelZhprocZhandle_countrFZbefore_count�	filenames�_rZhandle_deltarrr�test_getfinalpathname_handles	
sB

�
�

z*Win32NtTests.test_getfinalpathname_handlesN)r?r@rArMrrrrrH
srHc@s$eZdZdd�Zdd�Zdd�ZdS)�NonLocalSymlinkTestscCst�d�dS)Nz
base/some_dir)rr�rFrrrrG<
szNonLocalSymlinkTests.setUpcCst�d�dS)Nr�)r�rrFrrrr�E
szNonLocalSymlinkTests.tearDowncCstj�dd�}t�d|�dS)Nr�Z	some_linkZsome_dir)rr-r/r�)r%r�rrr�test_directory_link_nonlocalH
sz1NonLocalSymlinkTests.test_directory_link_nonlocalN)r?r@rArGr�rOrrrrrN9
s	rNc@seZdZdd�Zdd�ZdS)�FSEncodingTestscCs(|�t�d�d�|�t�d�d�dS)Nsabc�uabcŁ)r,rr�r=rFrrr�test_nopZ
szFSEncodingTests.test_nopc	CsHdD]>}zt�|�}Wntk
r.YqYnX|�t�|�|�qdS)N)u	unicodeŁulatiné�ascii)rr�r�r,r=)r%r�r�rrr�
test_identity^
s
zFSEncodingTests.test_identityN)r?r@rArQrSrrrrrPY
srPc@sVeZdZdd�Ze�e�d�oDe�oDe	j
�d�pDee
d�oDee
d�d�dd	��Zd
S)�DeviceEncodingTestscCs|�t�d��dS)Ni@�)rr�device_encodingrFrrr�test_bad_fdk
szDeviceEncodingTests.test_bad_fdr�win�nl_langinfo�CODESETz>test requires a tty and either Windows or nl_langinfo(CODESET)cCs(t�d�}|�|�|�t�|��dSr\)rrUZassertIsNotNonerK�codecs�lookup)r%rrrr�test_device_encodingo
s

z(DeviceEncodingTests.test_device_encodingN)r?r@rArVrrrr�rr]r�rr�localer\rrrrrTi
s"�rTc@sXeZdZe�eed�d�dd��Zdd�Zdd�Z	d	d
�Z
e�ejdkd�d
d��Z
dS)�PidTests�getppidztest needs os.getppidcCs<tjtjddgtjd�}|��\}}|�t|�t�	��dS)Nr�zimport os; print(os.getppid()))r:)
r}r�r]r�r�Zcommunicater,r�r�getpid)r%r�r:rLrrr�test_getppidy
s
��zPidTests.test_getppidcCs�tjdkr(dtj�d�dd|�d�g}ntjd|g}t�tjtj|�}t�|d�\}}tjdkrr|�||d>�n$|�t�	|�|�|�t�
|�|�|�||�dS)Nr��"r�rr�)r]r�r�r�spawnv�P_NOWAIT�waitpidr,rK�	WIFEXITED�WEXITSTATUS)r%r��exitcoder~r�Zpid2�statusrrr�
check_waitpid�
s

zPidTests.check_waitpidcCs|jddd�dS)Nrer)r�rh�rjrFrrr�test_waitpid�
szPidTests.test_waitpidcCs"d}d|�d�}|j||d�dS)N�zimport sys; sys.exit(�)�rhrk)r%rhr�rrr�test_waitpid_exitcode�
szPidTests.test_waitpid_exitcoder��win32-specific testcCs"d}d|�d�}|j||d�dS)Nl:z$import _winapi; _winapi.ExitProcess(rnrork)r%ZSTATUS_CONTROL_C_EXITr�rrr�test_waitpid_windows�
szPidTests.test_waitpid_windowsN)r?r@rArrrrrarjrlrpr]r�rrrrrrr^x
s
r^c@s$eZdZddd�dd�Zed�dd��Zed�d	d
��Zed�dd
��Zed�dd��Zed�dd��Z	ed�dd��Z
ed�dd��Zed�dd��Zed�dd��Z
ed�dd ��Zed�d!d"��Zed�d#d$��Zed�d%d&��Zed�d'd(��Zd)d*�Zed�d+d,��Zed�d-d.��Zd/S)0�
SpawnTestsF��with_env�	use_bytesc	Cs�d|_tj}|�tj|�|s*d|j}n8ttj�|_t	t
���|_|j|j|j<d|j|jf}t
|d��}|�|�W5QRXtj|g}|r�dd�|D�}dd�|j��D�|_|S)	N�zimport sys; sys.exit(%s)z4import sys, os; magic = os.environ[%r]; sys.exit(%s)r�cSsg|]}t�|��qSrrr8rrrr�
sz*SpawnTests.create_args.<locals>.<listcomp>cSs"i|]\}}t�|�t�|��qSrr)r�k�vrrr�
<dictcomp>�
s�z*SpawnTests.create_args.<locals>.<dictcomp>)rhrrDrrrErYrrrur#r�Zuuid4rarrr]r�r_)r%rurvrr�rr~rrr�create_args�
s(
�
�zSpawnTests.create_args�spawnlcCs2|��}tjtj|df|��}|�||j�dSr\)r{rr|�P_WAITr,rh�r%r~rhrrr�test_spawnl�
szSpawnTests.test_spawnl�spawnlecCs<|jdd�}tjtj|df||jf��}|�||j�dS�NT)rur)r{rr�r}rur,rhr~rrr�test_spawnle�
szSpawnTests.test_spawnle�spawnlpcCs2|��}tjtj|df|��}|�||j�dSr\)r{rr�r}r,rhr~rrr�test_spawnlp�
szSpawnTests.test_spawnlp�spawnlpecCs<|jdd�}tjtj|df||jf��}|�||j�dSr�)r{rr�r}rur,rhr~rrr�
test_spawnlpe�
szSpawnTests.test_spawnlperccCs.|��}t�tj|d|�}|�||j�dSr\)r{rrcr}r,rhr~rrr�test_spawnv�
szSpawnTests.test_spawnv�spawnvecCs6|jdd�}t�tj|d||j�}|�||j�dSr��r{rr�r}rur,rhr~rrr�test_spawnve�
szSpawnTests.test_spawnve�spawnvpcCs.|��}t�tj|d|�}|�||j�dSr\)r{rr�r}r,rhr~rrr�test_spawnvp�
szSpawnTests.test_spawnvp�spawnvpecCs6|jdd�}t�tj|d||j�}|�||j�dSr�)r{rr�r}rur,rhr~rrr�
test_spawnvpe�
szSpawnTests.test_spawnvpecCs�|��}t�tj|d|�}t�|d�}|�|d|�|d}ttd�rp|�t�|��|�t�	|�|j
�n|�||j
d>�dS)NrrQrfr�)r{rrcrdrer,rrKrfrgrh)r%r~r�r�rirrr�test_nowait�
s
zSpawnTests.test_nowaitcCs8|jddd�}t�tj|d||j�}|�||j�dS)NTrtrr�r~rrr�test_spawnve_bytes�
szSpawnTests.test_spawnve_bytescCs>|��}|�ttjtj|d�|�ttjtj|dd�dS�Nrr?)r{rXr�rr|rd�r%r~rrr�test_spawnl_noargsszSpawnTests.test_spawnl_noargscCsB|��}|�ttjtj|di�|�ttjtj|ddi�dSr�)r{rXr�rr�rdr�rrr�test_spawnle_noargs
szSpawnTests.test_spawnle_noargscCsv|��}|�ttjtj|dd�|�ttjtj|dg�|�ttjtj|dd�|�ttjtj|ddg�dS�Nrrryr?)r{rXr�rrcrdr�rrr�test_spawnv_noargss
zSpawnTests.test_spawnv_noargscCs~|��}|�ttjtj|ddi�|�ttjtj|dgi�|�ttjtj|ddi�|�ttjtj|ddgi�dSr�)r{rXr�rr�rdr�rrr�test_spawnve_noargss
zSpawnTests.test_spawnve_noargsc	Csdtjddg}tj��}d|d<z|tj|d||�}Wntk
rJYnX|�|d�tj��}d|d<z|tj|d||�}Wntk
r�YnX|�|d�tj��}d	|d
<z|tj|d||�}Wntk
r�YnX|�|d�tj	}|�
tj|�t|d��}|�
d�W5QRXtj|g}tj��}d
|d<|tj|d||�}|�|d�dS)Nr�rerfrgr�rhrirjrkr�zPimport sys, os
if os.getenv("FRUIT") != "orange=lemon":
    raise AssertionErrorzorange=lemon)r]r�rrr�r}r�r,rrDrrrErr)r%Zspawnr~rlrhrrrrr�_test_invalid_env s>




zSpawnTests._test_invalid_envcCs|�tj�dSr )r�rr�rFrrr�test_spawnve_invalid_envNsz#SpawnTests.test_spawnve_invalid_envcCs|�tj�dSr )r�rr�rFrrr�test_spawnvpe_invalid_envRsz$SpawnTests.test_spawnvpe_invalid_envN)r?r@rAr{rrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrs�
sD













.
rsz>Skip due to platform/environment differences on *NIX buildbots�getloginztest needs os.getloginc@seZdZdd�ZdS)�
LoginTestscCst��}|�t|�d�dSr\)rr�r
r*)r%Z	user_namerrr�
test_getlogin\szLoginTests.test_getloginN)r?r@rAr�rrrrr�Ysr��getpriority�setpriorityz'needs os.getpriority and os.setpriorityc@seZdZdd�ZdS)�ProgramPriorityTestscCs�t�tjt���}t�tjt��|d�zFt�tjt���}|dkr^|dkr^t�	d|��n|�
||d�W5zt�tjt��|�Wn0tk
r�}z|jtjkr��W5d}~XYnXXdS)NrQ�z?unable to reliably test setpriority at current nice level of %s)rr��PRIO_PROCESSr`r�r3r4ZEACCESrrr,)r%r�rNZnew_priorrr�test_set_get_priorityfs�z*ProgramPriorityTests.test_set_get_priorityN)r?r@rAr�rrrrr�asr�c@sveZdZGdd�dej�Zdd�Zedd��Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�ZeZdd�Zdd�ZdS)�SendfileTestServerc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)zSendfileTestServer.HandlercCs.tj�||�g|_d|_d|_|�d�dS)NTFs220 ready
)�asynchat�
async_chat�__init__�	in_buffer�
accumulate�closed�push)r%�connrrrr�}s
z#SendfileTestServer.Handler.__init__cCs |�d�}|jr|j�|�dS)N�)�recvr�r�r�r?rrr�handle_read�s
z&SendfileTestServer.Handler.handle_readcCsd�|j�S)Nr�)r/r�rFrrr�get_data�sz#SendfileTestServer.Handler.get_datacCs|��d|_dSr�)rJr�rFrrr�handle_close�sz'SendfileTestServer.Handler.handle_closecCs�dSr rrFrrr�handle_error�sz'SendfileTestServer.Handler.handle_errorN)r?r@rAr�r�r�r�r�rrrr�Handler{s
r�cCsptj�|�tj�|�|�tjtj�|�	|�|�
d�|j��dd�\|_|_
d|_d|_t��|_dS)Nr�rSF)�	threading�Threadr��asyncore�
dispatcherZ
create_socket�socketZAF_INETZSOCK_STREAMZbindZlistenZgetsockname�host�port�handler_instance�_activeZLock�_active_lock)r%Zaddressrrrr��s

zSendfileTestServer.__init__cCs|jSr )r�rFrrrr��szSendfileTestServer.runningcCs$t��|_tj�|�|j��dSr )r�ZEvent�_SendfileTestServer__flagr��startr�rFrrrr��s
zSendfileTestServer.startcCsd|_|��dSr�)r�r/rFrrr�stop�szSendfileTestServer.stopcCs&t|jdd�st�d�q|��dS)Nr�F���MbP?)r�r�r8r�r�rFrrrr��szSendfileTestServer.waitcCsLd|_|j��|jr@tjr@|j��tjddd�|j��qt�	�dS)NTr�rQ)Ztimeoutr9)
r�r�r�r�Z
socket_mapr��acquireZloop�releaseZ	close_allrFrrr�run�s

zSendfileTestServer.runcCs|��\}}|�|�|_dSr )Zacceptr�r�)r%r�Zaddrrrr�
handle_accept�sz SendfileTestServer.handle_acceptcCs|��dSr )rJrFrrr�handle_connect�sz!SendfileTestServer.handle_connectcCsdSr\rrFrrr�writable�szSendfileTestServer.writablecCs�dSr rrFrrrr��szSendfileTestServer.handle_errorN)r?r@rAr�r�r�r��propertyr�r�r�r�r�r�r�r�r�r�rrrrr�ys

	r��sendfileztest needs os.sendfile()c@s
eZdZddZej�d�o8ej�d�o8ej�d�Ze�	ed�Z
e�	ejdkd�Ze
d	d
��Ze
dd��Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Ze
dd��Ze
dd ��Ze
ed!d"���Ze
ed#d$���Ze
e�	eed%�d&�d'd(���Zd)S)*�TestSendfiles�12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde�ZlinuxZsolarisZsunosz%requires headers and trailers supportr�z(test is only meaningful on 32-bit buildscCst��|_ttj|j�dSr )rZthreading_setuprarrD�DATArrrrr
�s
zTestSendfile.setUpClasscCstj|j�t�tj�dSr )rZthreading_cleanuprarErDrrrrr �szTestSendfile.tearDownClasscCs~ttjdf�|_|j��t��|_|j�|jj|jj	f�|j�
d�|j�d�|j��|_
ttjd�|_|j��|_dS)NrrQr�rq)r�rZHOST�serverr�r��clientZconnectr�r�Z
settimeoutr�rh�socknorrDr�rFrrrrG�s

zTestSendfile.setUpcCs0|j��|j��|jjr&|j��d|_dSr )r�rJr�r�r�r�rFrrrr��s



zTestSendfile.tearDownc
Osfztj||�WStk
r^}z2|jtjkr0�n|jtjtjfkrLWY�
qn�W5d}~XYqXqdSr )rr�r3r4Z
ECONNRESET�EAGAIN�EBUSY)r%r~r�rNrrr�sendfile_wrapper�s
zTestSendfile.sendfile_wrappercCs�d}d}d}|t|j�krd|�|j|j||�}|dkr8qd||7}||7}|�||k�|�||�q|�|t|j��|j�t	j
�|j��|j�
�|jj��}|�t|�t|j��|�||j�dS)Nrr�)r*r�r�r�rhrKr,r��shutdownr��	SHUT_RDWRrJr�r�r�r�)r%�
total_sent�offset�nbytes�sentrsrrr�test_send_whole_file	s$

z!TestSendfile.test_send_whole_filecCs�d}t|j�d}t|j�|}d}||krj|�|j|j||�}|dkrJqj||7}||7}|�||k�q$|j�tj	�|j�
�|j��|jj
��}|jt|j�dd�}|�|t|��|�t|�t|��|�||�dS)NrrSr�)r*r�r�r�rhrKr�r�r�r�rJr�r�r�r�r,)r%r�r�Z	must_sendr�r�rsr8rrr�test_send_at_certain_offsets&

z(TestSendfile.test_send_at_certain_offsetc
Cs�t|j�d}zt�|j|j|d�}Wn0tk
rV}z|jtjkrF�W5d}~XYnX|�	|d�|j
�tj
�|j
��|j��|jj��}|�	|d�dS)Nr�rr�)r*r�rr�r�rhr3r4�EINVALr,r�r�r�r�rJr�r�r�r�)r%r�r�r�rsrrr�test_offset_overflow6s

z!TestSendfile.test_offset_overflowc	Cs@|�t��}t�|j|jdd�W5QRX|�|jjtj	�dS)Nr�r�)
rXr3rr�r�rhr,r�r4r��r%r�rrr�test_invalid_offsetGsz TestSendfile.test_invalid_offsetc	CsFtjf|jddd�d|ji��|jrBtj|j|jdddddd�dS)Nrr�)rr�r9�inr)r�r9�headers�trailersr�)rr�r�rh�SUPPORT_HEADERS_TRAILERSrFrrr�
test_keywordsLs��zTestSendfile.test_keywordscCs�d}d|jdd�}tj|j|jddddgd�}|�|d�||7}d}|t|�kr�tt|�|d�}|�|j|j||�}|dkr�q�|�||�||7}||7}qJ|�	|t|��|j
��|j�
�|jj��}|�	t|�t|��dS)	Nrsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyr�r�sxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy�r�i)r�rr�r�rhZassertLessEqualr*�minr�r,r�rJr�r�r�r��hash)r%r�Z
expected_datar�r�r�rsrrr�test_headersVs0��


zTestSendfile.test_headersc	Cs�tjd}d}|�tj|�t||�t|d��P}tj|j|�	�ddddgd�|j
��|j�
�|jj��}|�|d	�W5QRXdS)
Nr�sabcdefrqrr�s123456s789�r�sabcde123456789)rrDrrrErrrr�r�rhr�rJr�r�r�r�r,)r%r�Z	file_datarOrsrrr�
test_trailersos

�

zTestSendfile.test_trailersc	CsXd|jj_|�t��(}tj|j|jddddgdd�W5QRX|�	|j
jtj�dS)NFr�x���r��
r�r�r�rXr3rr�r�rhr,r�r4r�r�rrr�test_headers_overflow_32bitss
�z)TestSendfile.test_headers_overflow_32bitsc	CsXd|jj_|�t��(}tj|j|jddddgdd�W5QRX|�	|j
jtj�dS)NFrr�r�r�r�r�r�rrr�test_trailers_overflow_32bits�s
�z*TestSendfile.test_trailers_overflow_32bits�SF_NODISKIOztest needs os.SF_NODISKIOc
CsZztj|j|jddtjd�Wn6tk
rT}z|jtjtjfkrD�W5d}~XYnXdS)Nrr�)r�)	rr�r�rhr�r3r4r�r�)r%rNrrr�
test_flags�s�
zTestSendfile.test_flagsN)r?r@rAr�r]r�rr�rrZrequires_headers_trailers�maxsizeZrequires_32br!r
r rGr�r�r�r�r�r�r�r�r�r�r�rrr�rrrrr��sN����




�r�c	Cs|ttd�sdSzZttjdd��B}zt�|��dd�Wn$tk
rZYW5QR�W�dSXW5QRXW5t�tj�XdS)N�setxattrFrr�	user.testr�T)	rrrrErDrr�rhr3)rrrr�supports_extended_attributes�s
$r�z(no non-broken extended attribute supportrSr��'c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ExtendedAttributeTestsc
	Ks�tj}|�tj|�t|�|�t��}|||d�f|�W5QRX|�|jj	t	j
�||�}	|�|	t�|||d�df|�t
|	�}
|
�d�|�t
||��|
�|�||df|�d�|||d�dtjf|�|�||df|�d�|�t��}|||d�dtjf|�W5QRX|�|jj	t	j�|�t��}|||d�dtjf|�W5QRX|�|jj	t	j
�|||d�dtjf|�|
�d�|�t
||��|
�|||d�f|�|�t��}|||d�f|�W5QRX|�|jj	t	j
�|
�d�|�t
||��|
�|�|||d�f|�d�|||d�df|�|�|||d�f|�d�|||d�f|�td	d
�td�D��}|D]}|||df|��q||�t
||��t
|	�t
|�B�dS)
N�	user.testr�r�r.sbyez
user.test2sfoosaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacss|]}d�|�VqdS)zuser.test{}Nrq)rr�rrrrs�sz;ExtendedAttributeTests._check_xattrs_str.<locals>.<genexpr>r�r�)rrDrrrErrXr3r,r�r4ZENODATAr"r�r�r�r�
XATTR_REPLACE�XATTR_CREATEZEEXISTr�r	r�)
r%rn�getxattrr��removexattr�	listxattrr�r�r�Z
init_xattrZxattrZmany�thingrrr�_check_xattrs_str�sL
""

z(ExtendedAttributeTests._check_xattrs_strcOsB|jtf|�|�t�tj�|jtjf|�|�t�tj�dSr )rr#rrErDrr�r�rrr�
_check_xattrs�sz$ExtendedAttributeTests._check_xattrscCs|�tjtjtjtj�dSr �rrr�r�r�r�rFrrr�test_simple�s�z"ExtendedAttributeTests.test_simplecCs |jtjtjtjtjdd�dS)NFrIrrFrrr�
test_lpath�s�z!ExtendedAttributeTests.test_lpathcCs4dd�}dd�}dd�}dd�}|�||||�dS)	Nc
Ws6t|d��"}tj|��f|��W5QR�SQRXdSr�)rrr�rh�r-r~rrrrr��sz1ExtendedAttributeTests.test_fds.<locals>.getxattrc	Ws0t|dd��}tj|��f|��W5QRXdS�Nr1r)rrr�rhrrrrr��sz1ExtendedAttributeTests.test_fds.<locals>.setxattrc	Ws0t|dd��}tj|��f|��W5QRXdSr)rrr�rhrrrrr��sz4ExtendedAttributeTests.test_fds.<locals>.removexattrc
Ws6t|d��"}tj|��f|��W5QR�SQRXdSr�)rrr�rhrrrrr��sz2ExtendedAttributeTests.test_fds.<locals>.listxattr)r)r%r�r�r�r�rrr�test_fds�s
zExtendedAttributeTests.test_fdsN)r?r@rArrrrrrrrrr��s
0r��get_terminal_sizezrequires os.get_terminal_sizec@seZdZdd�Zdd�ZdS)�
TermsizeTestsc
Csxzt��}WnJtk
rV}z,tjdks:|jtjtjfkrD|�d��W5d}~XYnX|�	|j
d�|�	|jd�dS)Nr��failed to query terminal sizer)rrr3r]r�r4r��ENOTTYrVZassertGreaterEqual�columns�lines)r%rpr�rrr�test_does_not_crash
s
z!TermsizeTests.test_does_not_crashc
Cs�zt�ddg�����}Wn&ttjtfk
r@|�d�YnXt|d�t|d�f}zt	�
tj�
��}WnJtk
r�}z,tjdks�|jtjtjfkr�|�d��W5d}~XYnX|�||�dS)NZsttyrpzstty invocation failedrQrr�r
)r}rr�r�r2ZCalledProcessErrorr�rVr�rrr]�	__stdin__rhr3r�r4r�rr,)r%rpr8Zactualr�rrr�test_stty_match
s�
zTermsizeTests.test_stty_matchN)r?r@rArrrrrrr	
sr	�memfd_createzrequires os.memfd_creater�rwc@seZdZdd�ZdS)�MemfdCreateTestsc	Cs�t�dtj�}|�|d�|�tj|�|�t�|��t|ddd�� }|�	d�|�
|��d�W5QRXt�d�}|�tj|�|�t�|��dS)NZHir�r1F)�closefdsmemfd_creater�)rr�MFD_CLOEXECr
rrrJr&r�rrr,�tell)r%rmrO�fd2rrr�test_memfd_create2
s

z"MemfdCreateTests.test_memfd_createN)r?r@rArrrrrr/
src@seZdZdd�Zdd�ZdS)�OSErrorTestscCs�Gdd�dt�}g|_g|_tjdk	r.tj}ntj}|j�|�|j�||��tjdk	rbtj}nt�	tj�}|j�|�|j�t
|��|j�t|��|j|j|_dS)Nc@seZdZdS)zOSErrorTests.setUp.<locals>.StrN�r?r@rArrrr�StrB
sr)
r#�bytes_filenames�unicode_filenamesrr�rDr�ZTESTFN_UNDECODABLErr�rwrxrK)r%rZdecodedZencodedrrrrGA
s

zOSErrorTests.setUpcCs0|jtjf|jtjdf|jtjf|jtjtjf|jtjf|jtjf|jtj	fg}t
jdkr�|�|j
tjdf|j
tjdf|jtjdf|jtjdf|jtjff�n,|�|jtjf|jtjdf|jtjdff�ttd�r�|�|jtjddf�ttd��r|�|jtjddf�ttd��r.|�|jtjdf�ttd	��rN|�|jtjdf�ttd
��rn|�|jtjdf�ttd��r�|�|jtjf�ttd��r�t
jdk�r�|�|j
tjdf�|�|jtjdf�n|�|jtjdf�ttd
��r(|�|jtjf|jtjdf|jtjddf|jtjdff�ttd��rH|�|jtjdf�ttd��rf|�|jtj f�|D]�^}}}|D]�}zJt!|t"t#f��r�||f|��n&|�$t%d��||f|��W5QRXWnLt&k
�r�}z|�'|j(|t"|��W5d}~XYn&t)k
�rYnX|�*d�+|���qx�qjdS)Nr�r�sdstr�r	r�lchownr��chflags�lchflags�chrootr�r�r�suser�lchmodrz	should bezNo exception thrown by {}),rKrr1r�r�rr�rr�rEr]r�rrr`r�rr�rr�r	rr�rrr r�r�r�r�r�r!rr�r#r<ZassertWarnsRegex�DeprecationWarningr3r�r�UnicodeDecodeErrorr�rr)r%ZfuncsrK�funcZ	func_argsrrNrrr�test_oserror_filenameW
sz




�	

�
�

�$z"OSErrorTests.test_oserror_filenameN)r?r@rArGr%rrrrr@
src@seZdZdd�ZdS)�
CPUCountTestscCs8t��}|dk	r*|�|t�|�|d�n
|�d�dS)Nrz&Could not determine the number of CPUs)r�	cpu_countr"r��
assertGreaterrV)r%Zcpusrrr�test_cpu_count�
s
zCPUCountTests.test_cpu_countN)r?r@rAr)rrrrr&�
sr&c@s�eZdZdd�Ze�edkd�dd��Ze�edkd�dd��Ze�	e
ed	�d
�dd��Zd
d�Z
dd�Ze�	e
ed�d�dd��Zdd�Zdd�Ze�	ejdkd�dd��Ze�	e
ed�d�dd ��Ze�	e
ed!�d"�d#d$��ZdS)%�FDInheritanceTestscCsPt�ttj�}|�tj|�|�t�|�d�t�|d�|�t�|�d�dS�NFT)	rrr�r�rrrJr,r�r�r�rrr�test_get_set_inheritable�
s
z+FDInheritanceTests.test_get_set_inheritableNz
need fcntlcCsnt�ttj�}|�tj|�|�t�|�d�t�|tj	�}|tj
M}t�|tj|�|�t�|�d�dSr+)rrr�r�rrrJr,r��fcntl�F_GETFD�
FD_CLOEXECZF_SETFD)r%rmr�rrr�test_get_inheritable_cloexec�
sz/FDInheritanceTests.test_get_inheritable_cloexeccCsft�ttj�}|�tj|�|�t�|tj�tj	@tj	�t�
|d�|�t�|tj�tj	@d�dS)NTr)rrr�r�rrrJr,r-r.r/r�r�rrr�test_set_inheritable_cloexec�
s��z/FDInheritanceTests.test_set_inheritable_cloexec�O_PATHzneed os.O_PATHcCsnt�ttj�}|�tj|�|�t�|�d�t�|d�|�t�|�d�t�|d�|�t�|�d�dSr+)	rrr�r2rrrJr,r�r�r�rrr�test_get_set_inheritable_o_path�
sz2FDInheritanceTests.test_get_set_inheritable_o_pathc	Cs�t��}|�t��}t�|�W5QRX|�|jjtj	�|�t��}t�
|d�W5QRX|�|jjtj	�|�t��}t�
|d�W5QRX|�|jjtj	�dS�NTF)rr�rXr3rr�r,r�r4r�r�)r%rmrrrr�test_get_set_inheritable_badf�
sz0FDInheritanceTests.test_get_set_inheritable_badfcCs2t�ttj�}|�tj|�|�t�|�d�dSr�)rrr�r�rrrJr,r�r�rrrr��
szFDInheritanceTests.test_openr�zneed os.pipe()cCsPt��\}}|�tj|�|�tj|�|�t�|�d�|�t�|�d�dSr�)rr�rrrJr,r�)r%ZrfdZwfdrrr�	test_pipe�
s
zFDInheritanceTests.test_pipecCsJt�ttj�}|�tj|�t�|�}|�tj|�|�t�|�d�dSr�)	rrr�r�rrrJrUr,r��r%Zfd1rrrr�test_dup�
s

zFDInheritanceTests.test_dupcCs(t�d�}|�tj|�|�|d�dS�NrQr)rrUrrrJr(r�rrr�test_dup_standard_stream�
s
z+FDInheritanceTests.test_dup_standard_streamr�rqcCsHt�dtj�}|�tj|�t�|�}|�tj|�|�t�|��dS)NZNUL)rrr�rrrJrUr&r�r7rrr�test_dup_nul�
s

zFDInheritanceTests.test_dup_nulr�zneed os.dup2()cCs�t�ttj�}|�tj|�t�ttj�}|�tj|�|�t�||�|�|�t�	|��t�ttj�}|�tj|�|�tj||dd�|�|�
t�	|��dS)NF)Zinheritable)rrr�r�rrrJr,r�rKr�r&)r%rmrZfd3rrrr�szFDInheritanceTests.test_dup2�openptyzneed os.openpty()cCsPt��\}}|�tj|�|�tj|�|�t�|�d�|�t�|�d�dSr�)rr<rrrJr,r�)r%Z	master_fdZslave_fdrrr�test_openptys
zFDInheritanceTests.test_openpty)r?r@rAr,rrpr-r0r1rrrr3r5r�r6r8r:r]r�r;r�r=rrrrr*�
s&






r*c@sHeZdZddddejfdfddddd	eed
d�fgZdd�Zd
d�ZdS)�PathTConverterTests)r�TrN)r�FrNrLFN)rF�rN)rFr?Nrr?rJcCs�tj}tjdkrd}}ntj�d�}t|�}t�t|�tjtjB�}|�	tj
tj�|�	tj|�t|�}t|�}|jD�]"\}}}	}
|j
|d���ztt|�}Wn"tk
r�YW5QR�qzYnX||||fD]H}|dkr�q�|j
||d��&||f|	��}
|
dk	�r|
|
�W5QRXq�|�td��||f|	��W5QRX|�rn||f|	��}
|
dk	�r�|
|
�n&|�td��||f|	��W5QRXW5QRXqzdS)Nr�rRr)rr-zto return str or byteszos.PathLike)rrDrrr�rrrvrHrrrErJ�	functionsZsubTestr�r��assertRaisesRegexr_)r%Zstr_filenameZbytes_fspath�bytes_filenamermZ
int_fspathZ
str_fspathrZallow_fdZ
extra_argsZ
cleanup_fnr�r-r�rrr�test_path_t_converter,sN

�
�

�z)PathTConverterTests.test_path_t_converterc	Cs�d}|�t|d��t�td��W5QRX|�t|d��t�td��W5QRX|�t|d��t�tt���W5QRXdS)Nz-__fspath__\(\) to return str or bytes, not %sr�rS�floatg���Q�@�object)rAr_rr�rrE)r%r7rrr�&test_path_t_converter_and_custom_classXsz:PathTConverterTests.test_path_t_converter_and_custom_class)	r?r@rAr�F_OKr�r@rCrFrrrrr> s�	,r>r�r�c@seZdZdd�ZdS)�
BlockingTestscCsnt�ttj�}|�tj|�|�t�|�d�t�|d�|�t�|�d�t�|d�|�t�|�d�dSr4)	rrr�r�rrrJr,r�r�r�rrrr�eszBlockingTests.test_blockingN)r?r@rAr�rrrrrHbsrHc@seZdZdd�ZdS)�ExportsTestscCs |�dtj�|�dtj�dS)Nrr�)r�r�__all__rFrrr�test_os_allsszExportsTests.test_os_allN)r?r@rArKrrrrrIrsrIc@s�eZdZejZdd�Zd8dd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zd9dd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Ze�ejejkd$�d%d&��Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Z d1d2�Z!d3d4�Z"d5d6�Z#d7S):�TestScandircCs>tj�tj�|_t�|j�|_|�tj|j�t�	|j�dSr )
rr-�realpathrrDr��
bytes_pathrrrr0rFrrrrG{szTestScandir.setUpr*cCs2t|t�r|jn|j}tj�||�}t|d�|S)Nspython)r�r<rNr-rr/r)r%rr-rrrrr�s
zTestScandir.create_filecCs2tdd�t�|j�D��}|�t|���|�|S)Ncss|]}|j|fVqdSr r�r�entryrrrrs�s�z*TestScandir.get_entries.<locals>.<genexpr>)rYr�scandirr-r,r	�keys)r%�names�entriesrrr�get_entries�s

�zTestScandir.get_entriescCsZ|rJt|�D]:}|�d�sq|dkr&q|�t||�t||�|||f�qn|�||�dS)NZst_)�st_dev�st_ino�st_nlink)r�rr,r�)r%Zstat1Zstat2Zskip_fieldsr�rrr�assert_stat_equal�s
�zTestScandir.assert_stat_equalcCs2|�|tj�|�|j|�|�|jtj�|j|��|�|��tj|jdd�j	�t�|j�}|�|�
�t�|j��|�|�
�t�|j��|�|��tj�|j��tj|jdd�}|�|j
dd�t�|j��|�|j
dd�t�|j��|�|��|tjdk�o|�|�|jdd�|tjdk�dS)NFrIr�)r"r�DirEntryr,rr-r/�inoder�rW�is_dir�S_ISDIRr��is_file�S_ISREG�
is_symlinkr$rY)r%rPrr\r^r`Z
entry_statZentry_lstatrrr�check_entry�s>
�

�

�
�
�
�
��zTestScandir.check_entryc	
Cs�ttd�}t��}tj�|jd�}t�|�|�d�}|r�zt�|tj�|jd��Wn0t	k
r�}z|�
d|�W5d}~XYnX|r�tj|tj�|jd�dd�t�|tj�|jd	��ddg}|r�|�d�|r�|�
d
�|�|�}|d}|�|dddd�|d}|�|dddd�|�rB|d}|�|dddd�|�r||d}|�|dddd�|d	}|�|d	ddd�dS)Nr�r�r*z
link_file.txtr��symlink_dirT)r��symlink_file.txt)rbrcF)rrrr�r-r/r0rr�r�rVr�r�rrUra)	r%r�r�r7rr�rSrTrPrrr�test_attributes�sB


 �


zTestScandir.test_attributescCsNt|t�r|jn|j}tt�|��}|�t|�d�|d}|�|j	|�|Sr9)
r�r<rNr-r�rrQr,r*r)r%rr-rTrPrrr�	get_entry�szTestScandir.get_entrycCs|j|d�}|�tj�|��S)Nr)rrerr-�basename)r%rrrrr�create_file_entry�szTestScandir.create_file_entryc	Csf|��}t��}zDt�|j�tdd�t��D��}|�t|�	��tj�
|�g�W5t�|�XdS)Ncss|]}|j|fVqdSr rrOrrrrs�sz5TestScandir.test_current_directory.<locals>.<genexpr>)rrr!r1r-rYrQr,r	rRrf)r%rZold_dirrTrrr�test_current_directory�s�z"TestScandir.test_current_directorycCs|��}|�t|�d�dS)Nz<DirEntry 'file.txt'>)rgr,rt�r%rPrrr�	test_repr�szTestScandir.test_reprcCs*|��}|�t�|�tj�|jd��dS)Nr*)rgr,r�fspathr-r/rirrr�test_fspath_protocol�sz TestScandir.test_fspath_protocolcCsNt�d�}|j|d�}t�|�}|�|t�|�|tj�t�|j�|��dS)Nz
bytesfile.txtr)	rr�rgrkr"r<r,r-r/)r%rBZbytes_entryrkrrr�test_fspath_protocol_bytess

�z&TestScandir.test_fspath_protocol_bytescCs�tj�|jd�}t�|�|�d�}t�|�tjdkrF|�|���|�	|�
��|�	|���tjdkr�|�t
|j�|��|jdd�n0|�|��d�|�t
|j�|jt
|jdd�dS)Nr�r�FrIr)rr-r/r0rerrrKr\r&r^r`rXr2r[r�r()r%r-rPrrr�test_removed_dir
s




zTestScandir.test_removed_dircCs�|��}t�|j�|�|���tjdkr:|�|���|�|�	��tjdkrv|�
t|j�|�
�|j
dd�n0|�|��d�|�
t|j
�|j
t|j
dd�dS)Nr�FrIr)rgrrEr-r&r\rrKr^r`rXr2r[r�r(rirrr�test_removed_file s

zTestScandir.test_removed_filecCs�t��s|�d�S|�d�}t�|tj�|jd��|�ddg�}|d}t�	|�|�
|��d�|�|�
��|�|���|�|j
dd��|�|jdd��|�|���|�t|j�|jdd�dS)Nzcannot create symbolic linkr*zsymlink.txtrFrI)rr�rVrrr�r-r/rUrEr(r[r&r\r^rKr`rXr2r�)r%rrTrPrrr�test_broken_symlink3s"

�
zTestScandir.test_broken_symlinkc	Csp|�d�t�|j�}tt�|��}|�t|�d|�|d}|�|jd�|�|jt�tj�	|jd���dS�Nr*rQrsfile.txt)
rrr�r-r�rQr,r*rr/)r%�
path_bytesrTrPrrrrHs
�zTestScandir.test_bytesc
Cs�|�d�ttfD]�}|t�|j��}|�t��tt�	|��}W5QRX|�
t|�d|�|d}|�
|jd�|�
|jt�tj�
|jd���|�t|j�t�|�t|j�t�qdSrq)rrwrxrr�r-�assertWarnsr"r�rQr,r*rr/r�rkr<)r%rrrrTrPrrr�test_bytes_likeTs
�zTestScandir.test_bytes_likez.fd support for listdir required for this test.c	CsT|�tjtj�|�d�dg}t��rJt�dtj�	|jd��|�
d�t�|jtj�}z�t�|��}t|�}W5QRXdd�|D�}|�t|�|�|�|t�|��|D]�}|�|j|j�|�t�|�|j�|�|��|jdk�tjtjkr�tj|j|d�}|�|��|�tj|j|dd�}|�|jdd�|�q�W5t�
|�XdS)	Nr*r�cSsg|]
}|j�qSrrrOrrrrrsz'TestScandir.test_fd.<locals>.<listcomp>rJF)r�r/rI)r�rrQrLrrr�r�r-r/r�rr�rJr�r,r	r�rrkr`r�rM)r%Zexpected_namesrmrkrTrSrPrrrr�test_fdds.

zTestScandir.test_fdcCs|�ttjd�dS)Nr?)rXr2rrQrFrrr�test_empty_path�szTestScandir.test_empty_pathcCsN|�d�t�|j�}t|�}|�t|�d|�t|�}|�t|�d|�dS)Nr*rQr)rrrQr-r�r,r*)r%r�rTZentries2rrr�test_consume_iterator_twice�s
z'TestScandir.test_consume_iterator_twicecCs$digfD]}|�ttj|�q
dS)NgX9��v��?)rXr_rrQ)r%�objrrr�test_bad_path_type�szTestScandir.test_bad_path_typec	CsR|�d�|�d�t�|j�}t|�|��|��|���~W5QRXdS�Nr*�	file2.txt)rrrQr-rirJ�check_no_resource_warning�r%r�rrr�
test_close�s


zTestScandir.test_closec	CsN|�d�|�d�t�|j��}t|�W5QRX|���~W5QRXdSrz)rrrQr-rir|r}rrr�test_context_manager�s


z TestScandir.test_context_managerc	Cs@|�d�|�d�t�|j��}t|�|��W5QRXdSrz)rrrQr-rirJr}rrr�test_context_manager_close�s


z&TestScandir.test_context_manager_closec
Csl|�d�|�d�|�t��.t�|j��}t|�ddW5QRXW5QRX|���~W5QRXdS)Nr*r{rQr)rrX�ZeroDivisionErrorrrQr-rir|r}rrr�test_context_manager_exception�s


z*TestScandir.test_context_manager_exceptionc	Csv|�d�|�d�t�|j�}t|�|�t��~t��W5QRXt�|j�}t	|�|�
��~W5QRXdSrz)rrrQr-rirs�ResourceWarningrZ
gc_collectr�r|r}rrr�test_resource_warning�s


z!TestScandir.test_resource_warningN)r*)r*)$r?r@rArr|rGrrUrYrardrergrhrjrlrmrnrorprrtrrrr�rLrurvrwryr~rr�r�r�rrrrrLxs<

)	
�

rLc@sVeZdZeej�Zdd�Zdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dS)�
TestPEP519cCs dD]}|�||�|��qdS)N)r.sgoodbyessome/path/and/file�r,rk)r%�brrr�test_return_bytes�szTestPEP519.test_return_bytescCs dD]}|�||�|��qdS)N)ZhelloZgoodbyezsome/path/and/filer�)r%rnrrr�test_return_string�szTestPEP519.test_return_stringcCsLdD]B}t|�}|�||�|��|�dt�|��|�dt�|��qdS)N)�path/like/object�path/like/objectr�r�)rr,rkrr�r=)r%r�Zpathlikerrr�test_fsencode_fsdecode�s
z!TestPEP519.test_fsencode_fsdecodecCsB|�d|�td���|�tttj��|�ttd�tj��dS)Nz#feelthegilr�)r,rkrrK�
issubclassr�PathLiker�rFrrrr�szTestPEP519.test_pathlikecCs4tddi�}ttt|�fD]}|�t|j|�qdS)NZblahr)rkr�rrXr_rk)r%Zvapor�orrr�test_garbage_in_exception_out�sz(TestPEP519.test_garbage_in_exception_outcCs|�t|j�dSr )rXr_rkrFrrr�test_argument_required�sz!TestPEP519.test_argument_requiredcCsR|�t|jtd��tddi�}d|_|�t|j|��|�t|jtt���dS)NrTZfoorrQ)rXr_rkrrk�
__fspath__r�)r%�crrr�test_bad_pathlike�s
�zTestPEP519.test_bad_pathlikecCs8Gdd�dtj�}|�tt|��|�tttj��dS)Nc@seZdZdS)z0TestPEP519.test_pathlike_subclasshook.<locals>.ANrrrrr�A�sr�)rr�r&r�rrK)r%r�rrr�test_pathlike_subclasshook�sz%TestPEP519.test_pathlike_subclasshookN)r?r@rArVrrkr�r�r�rr�r�r�r�rrrrr��s
r�c@seZdZdd�ZdS)�
TimesTestscCsnt��}|�|tj�dD]}t||�}|�|t�qtjdkrj|�|jd�|�|j	d�|�|j
d�dS)N)�user�system�
children_user�children_system�elapsedr�r)rr-r"�times_resultr�rDrr,r�r�r�)r%r-Zfieldr�rrr�
test_times�s

zTimesTests.test_timesN)r?r@rAr�rrrrr��sr��_fspathc@seZdZeej�ZdS)�TestPEP519PurePythonN)r?r@rArVrr�rkrrrrr�sr��__main__)r)N)}r�r�rZ�
contextlibrr4r;rr�r]r�rr�r�r�r�r�r}r]Z	sysconfigr+r�r8rr�r�Ztestrr�rrQ�ImportErrorr-rC�pwdZgetpwallrr�Z	_testcapir	r
r�Ztest.support.script_helperrZtest.supportr
rr"rrr�versionrrq�getgidr�rrZTestCaserrBr�rrWZBasicTestMappingProtocolrXr�rr�r�r�r�r
r#r-r1r>Zget_config_varZOS_URANDOM_DONT_USE_FDrprJ�contextmanagerrZr[rrrwr�r�r�r�rrrr rArHrNrPrTr^rsrr�r�r�r�r�r�r�Zrequires_linux_versionr�r	rrr&r*r>rHrIrLr�r�r�r?�mainrrrr�<module>sV




Aae_5EG
j;)	-����M �h#d%CGs/<0!1+7�VN�Q,
]
yB�P7