Your IP : 216.73.216.85


Current Path : /opt/alt/python36/lib64/python3.6/test/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/test/__pycache__/test_posix.cpython-36.opt-1.pyc

3

� f$��@s�dZddlmZejd�ZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZejjej�ejd�Ze
jejdkd�Zd	d
�Ze
je�d�ZGdd
�d
e
j�ZGdd�de
j�Zdd�Zedkr�e�dS)zTest posix functions�)�support�posixNz-dummy-symlink�� z(test is only meaningful on 32-bit buildscCsTttd�sdSytjd�Wn2tk
rN}z|jtjkr>dSWYdd}~XnXdS)N�sched_getschedulerFrT)�hasattrrr�OSError�errnoZENOSYS)�e�r�4/opt/alt/python36/lib64/python3.6/test/test_posix.py�_supports_scheds
r
zrequires POSIX scheduler APIc@s�	eZdZdd�Zdd�Zdd�Zejee	d�d�d	d
��Z
ejee	d�d�d
d��Zejee	d�d�dd��Zejee	d�d�dd��Z
ejee	d�d�dd��Zejee	d�d�dd��Zejee	d�d�dd��Zejee	d�d �d!d"��Zejee	d#�d$�d%d&��Zejee	d'�d(�d)d*��Zejee	d+�d,�d-d.��Zejeed/d0�ejkd1�ejeed2�d3�ejeed4�d5�d6d7����Zejee	d8�d9�ejeed2�d3�d:d;���Zejee	d<�d=�d>d?��Zejee	d@�dA�dBdC��Zejee	dD�dE�dFdG��Zejee	dH�dI�dJdK��Zejee	dH�dI�dLdM��Zejee	dN�dO�dPdQ��Zejee	dN�dO�dRdS��Z ejej!ejkdT�dUdV��Z"ejej!ej#kdW�dXdY��Z$ejee	dZ�d[�d\d]��Z%ejee	dZ�d[�e&d^d_���Z'ejee	d`�da�dbdc��Z(ejee	d`�da�e&ddde���Z)ejee	df�dg�dhdi��Z*ejee	dj�dk�dldm��Z+ejee	dn�do�dpdq��Z,ejeedr�ds�e-j.dtdudv�dwdx���Z/ejee	dy�dz�d{d|��Z0ejee	d}�d~�dd���Z1ejee	d��d��d�d���Z2ejee	d��d��d�d���Z3ejee	d��d��d�d���Z4ejee	d���oee5d��d��d�d���Z6ejee	d��d��ejee	d��d��d�d����Z7d�d��Z8ejee	d��d��d�d���Z9ejee	d��d��d�d���Z:ejee	d��d��d�d���Z;ejee	d��d��d�d���Z<d�d��Z=d�d��Z>d�d��Z?d�d��Z@eje	jAejkd��d�d���ZBejee	d��d��d�d���ZCejee	d��d��d�d���ZDejee	d��d��d�d���ZEejee	d��d��d�d„�ZFejeedÃdăe-j.dtdudŃd�dDŽ��ZGe-jHejeedÃdăe-j.dtdudŃd�dɄ���ZIejee	dʃd˃d�d̈́�ZJd�dτZKejee	dЃdуd�dӄ�ZLejee	dԃdՃd�dׄ�ZMejee	dԃdՃd�dل�ZNd�dۄZOejeed܃d݃d�d߄�ZPejee	d�d�d�d��ZQejee	d�d�ejeeRd�d�ejeed�d�d�d����ZSejeed�d�d�d��ZTejejUejVkd�d�d��ZWejejXejVkd�d�d���ZYejejZejVkd��d�d���Z[ejej5ejVkd��d�d���Z\ejej!ejVkd��d�d���Z]ejej^ejVkd���d�d��Z_ejej`ejVk�d��d�d��ZaejejbejVk�o�ee5d���d��d�d��ZcejejdejVk�d��d	�d
��ZeejejfejVk�d��d�d
��ZgejejhejVk�d��d�d��ZiejejjejVk�d��d�d��ZkejejlejVk�d��d�d��ZmejejnejVk�d��d�d��Zoejee	�d��d�Zpejee	�d��d�Zqep�d�d��Zrepejee	�d ��d!��d"�d#���Zset�d$�d%��Zuejee	�d&��d'��d(�d)��Zveq�d*�d+��Zweq�d,�d-��Zx�d.�d/�Zyejz�d0�ejee�d1��d2��d3�d4���Z{�d5�d6�Z|�d7�d8�Z}�d9�d:�Z~d0S(;�PosixTestercCsDttjd�}|j�tjg|_tj�|_|jj�tj	ddt
�dS)Nzw+�ignorez.* potential security risk .*)�openr�TESTFN�close�teardown_filesZcheck_warnings�_warnings_manager�	__enter__�warnings�filterwarnings�RuntimeWarning)�self�fprrr�setUp's


zPosixTester.setUpcCs.x|jD]}tj|�qW|jjddd�dS)N)rr�unlinkr�__exit__)rZ
teardown_filerrr�tearDown1szPosixTester.tearDowncCs\ddddddddd	d
ddd
ddg}x4|D],}tt|d�}|dk	r(|�|jt|d�q(WdS)N�ctermid�getcwd�getcwdb�uname�times�
getloadavg�getegid�geteuid�getgid�	getgroups�getpid�getpgrp�getppid�getuid�sync�)�getattrr�assertRaises�	TypeError)rZNO_ARG_FUNCTIONS�nameZ
posix_funcrrr�testNoArgFunctions6s
zPosixTester.testNoArgFunctions�	getresuidztest needs posix.getresuid()cCs6tj�}|jt|�d�x|D]}|j|d�qWdS)N�r)rr4�assertEqual�len�assertGreaterEqual)rZuser_ids�valrrr�test_getresuidEs
zPosixTester.test_getresuid�	getresgidztest needs posix.getresgid()cCs6tj�}|jt|�d�x|D]}|j|d�qWdS)Nr5r)rr;r6r7r8)rZ	group_idsr9rrr�test_getresgidMs
zPosixTester.test_getresgid�	setresuidztest needs posix.setresuid()cCs0tj�}|jtj|��|jtjddd��dS)Nr.���r>r>)rr4�assertIsNoner=)r�current_user_idsrrr�test_setresuidUszPosixTester.test_setresuidcCs:tj�}d|kr6|ddddf}|jttjf|��dS)Nrr.r>r>)rr4r0rr=)rr@Znew_user_idsrrr�test_setresuid_exception]sz$PosixTester.test_setresuid_exception�	setresgidztest needs posix.setresgid()cCs0tj�}|jtj|��|jtjddd��dS)Nr.r>r>r>)rr;r?rC)r�current_group_idsrrr�test_setresgidfszPosixTester.test_setresgidcCs:tj�}d|kr6|ddddf}|jttjf|��dS)Nrr.r>r>)rr;r0rrC)rrDZ
new_group_idsrrr�test_setresgid_exceptionnsz$PosixTester.test_setresgid_exception�
initgroupsztest needs os.initgroups()cCs�|jttj�|jttjd�|jttjdd�|jttjddt��tj�dkr�ytjtj��j	}Wnt
k
r�tjd��YnXytj|d�Wn2t
k
r�}z|j|jtj�WYdd}~XnX|jd�dS)Nr5Zfoorzneed a pwd entry�
z+Expected OSError to be raised by initgroups)r0r1rrG�object�osr,�pwd�getpwuid�pw_name�KeyError�unittest�SkipTestrr6r	�EPERM�fail)rr2r
rrr�test_initgroupsws"zPosixTester.test_initgroups�statvfsztest needs posix.statvfs()cCs|jtjtj��dS)N)�
assertTruerrTrJ�curdir)rrrr�test_statvfs�szPosixTester.test_statvfs�fstatvfsztest needs posix.fstatvfs()c
CsFttj�}z,|jtj|j���|jtj|j���Wd|j�XdS)N)	rrrrUrrX�filenorTr)rrrrr�
test_fstatvfs�s

zPosixTester.test_fstatvfs�	ftruncateztest needs posix.ftruncate()c
CsBttjd�}z&|jd�|j�tj|j�d�Wd|j�XdS)Nzw+�testr)	rrr�write�flushrr[rYr)rrrrr�test_ftruncate�s
zPosixTester.test_ftruncate�truncateztest needs posix.truncate()c
Cs<ttjd��}|jd�|j�WdQRXtjtjd�dS)N�wr\r)rrrr]r^rr`)rrrrr�
test_truncate�s
zPosixTester.test_truncate�execveNz/test needs execve() to support the fd parameter�forkztest needs os.fork()�waitpidztest needs os.waitpid()cCs�tjtjtj�}z^tj�}|dkrTtjtjjtj�d�t	j
|tjddgtj�n|jtj
|d�|df�Wdtj|�XdS)Nrz-c�pass)rJr�sys�
executable�O_RDONLYrd�chdir�path�splitrrc�environr6rer)rr�pidrrr�test_fexecve�szPosixTester.test_fexecve�waitidztest needs posix.waitid()cCshtj�}|dkrDtjtjjtj�d�tjtjtjddgtj	�n tj
tj|tj�}|j
||j�dS)Nrz-crf)rJrdrjrkrlrgrhrrcrmrp�P_PID�WEXITEDr6�si_pid)rrn�resrrr�test_waitid�szPosixTester.test_waitid�lockfztest needs posix.lockf()cCshtjtjtjtjB�}z@tj|d�tj|dtj�t	j
|t	jd�t	j
|t	jd�Wdtj
|�XdS)Nstestr�)rJrrr�O_WRONLY�O_CREATr]�lseek�SEEK_SETrrv�F_LOCK�F_ULOCKr)r�fdrrr�
test_lockf�szPosixTester.test_lockf�preadztest needs posix.pread()cCsrtjtjtjtjB�}zJtj|d�tj|dtj�|j	dt
j|dd��|j	dt
j|d��Wdtj
|�XdS)Nstestrsesrr.ste)rJrrr�O_RDWRryr]rzr{r6rr��readr)rr~rrr�
test_pread�szPosixTester.test_pread�pwriteztest needs posix.pwrite()cCsjtjtjtjtjB�}zBtj|d�tj|dtj�t	j
|dd�|jdt	j|d��Wdtj
|�XdS)Nstestrsxxr.stxxtrw)rJrrrr�ryr]rzr{rr�r6r�r)rr~rrr�test_pwrite�szPosixTester.test_pwrite�posix_fallocatez"test needs posix.posix_fallocate()cCs�tjtjtjtjB�}z`ytj|dd�WnHtk
rr}z,|j	t	j
kr`tjj
d	�r`tjd��n�WYdd}~XnXWdtj|�XdS)
Nr�
�sunos�freebsd�netbsd�openbsd�gnukfreebsdz test may fail on ZFS filesystems)r�r�r�r�r�)rJrrrrxryrr�rr	�EINVALrg�platform�
startswithrOrPr)rr~�instrrr�test_posix_fallocate�sz PosixTester.test_posix_fallocatecCsHytjddd�Wn0tk
rB}z|jtjkr2�WYdd}~XnXdS)N�*rr�i���)rr�rr	�EBADF)rr�rrr�test_posix_fallocate_errnos
z&PosixTester.test_posix_fallocate_errno�
posix_fadvisez test needs posix.posix_fadvise()cCs8tjtjtj�}ztj|ddtj�Wdtj|�XdS)Nr)	rJrrrrirr��POSIX_FADV_WILLNEEDr)rr~rrr�test_posix_fadviseszPosixTester.test_posix_fadvisecCsLytjdddtj�Wn0tk
rF}z|jtjkr6�WYdd}~XnXdS)Nr�ri���)rr�r�rr	r�)rr�rrr�test_posix_fadvise_errnos
z$PosixTester.test_posix_fadvise_errnoz!test needs fd support in os.utimec
CsHtj�}tjtjtj�}�ztj|�tj|d�|jt	tj|d�|jt	tj||df�|jt	tj|d|f�tj|t
|�t
|�f�tj|||f�|jttj|||f||fd�|jttj||dfdd�|jttj|d|dfd�tj|t
|�t
|t
|�d�f�tj|t
|�t
|t
|�d�fd�Wdtj|�XdS)N)�nsrge��A)NN)NN)NN)
�timerJrrrrir�utimer0r1�int�
ValueErrorr)r�nowr~rrr�test_utime_with_fds 
$*zPosixTester.test_utime_with_fdz.test needs follow_symlinks support in os.utimecCs�tj�}tjtjddd�|jttjtjddd�|jttjtj|dfdd�|jttjtjd|fdd�tjtjt|�t|�fdd�tjtj||fdd�tjtjdd�dS)NF)�follow_symlinks)NN)r�rr�rrr0r1r�)rr�rrr�test_utime_nofollow_symlinks3sz(PosixTester.test_utime_nofollow_symlinks�writevztest needs posix.writev()cCs�tjtjtjtjB�}zrtj|d�}|j|d�tj|dtj	�|jdt
j|d��yt
j|g�}Wntk
rxYnX|j|d�Wdtj
|�XdS)N�test1�tt2�t3r�rs
test1tt2t3)r�r�r�)rJrrrr�ryr�r6rzr{rr�rr)rr~�n�sizerrr�test_writev>szPosixTester.test_writevcCsjtjtjtjtjB�}zB|jt��}tj|ddgd�WdQRX|j	|j
jtj�Wdtj
|�XdS)N�xr��ii�)rJrrrr�ryr0rr�r6�	exceptionr	r�r)rr~�cmrrr�test_writev_overflow_32bitsTs z'PosixTester.test_writev_overflow_32bits�readvztest needs posix.readv()cCs�tjtjtjtjB�}z�tj|d�tj|dtj�dd�d
D�}|j	t
j||�d�|j	d	d
dgdd�|D��yt
j|g�}Wntk
r�YnX|j	|d�Wdtj
|�XdS)Ns
test1tt2t3rcSsg|]}t|��qSr)�	bytearray)�.0�irrr�
<listcomp>esz*PosixTester.test_readv.<locals>.<listcomp>�r5rr�stest1stt2st3cSsg|]}t|��qSr)�bytes)r�r�rrrr�gs)r�r5r)rJrrrr�ryr]rzr{r6rr�rr)rr~�bufr�rrr�
test_readv_szPosixTester.test_readvcCs�tjtjtjtjB�}z^td�gd}|jt��}tj	||�WdQRX|j
|jjtj
�|j
t|d�dd�Wdtj|�XdS)	Nrr�r�r�ii�i)rJrrrr�ryr�r0rr�r6r�r	r�r�r)rr~r�r�rrr�test_readv_overflow_32bitsusz&PosixTester.test_readv_overflow_32bits�dupztest needs posix.dup()c
CsBttj�}z(tj|j��}|j|t�tj	|�Wd|j	�XdS)N)
rrrrr�rY�assertIsInstancer�rJr)rrr~rrr�test_dup�s
zPosixTester.test_dup�confstrztest needs posix.confstr()cCs.|jttjd�|jttjd��dkd�dS)NZ
CS_garbage�CS_PATHrT)r0r�rr�r6r7)rrrr�test_confstr�szPosixTester.test_confstr�dup2ztest needs posix.dup2()c
CsDttj�}ttj�}ztj|j�|j��Wd|j�|j�XdS)N)rrrrr�rYr)r�fp1�fp2rrr�	test_dup2�s

zPosixTester.test_dup2�	O_CLOEXECzneeds os.O_CLOEXECr��cCs8tjtjtjtjB�}|jtj|�|jtj	|��dS)N)
rJrrrrir��
addCleanupr�assertFalse�get_inheritable)rr~rrr�test_oscloexec�szPosixTester.test_oscloexec�O_EXLOCKztest needs posix.O_EXLOCKcCs�tjtjtjtjBtjB�}|jttjtjtjtjBtj	B�tj
|�ttd�r�tjtjtjtj
BtjB�}|jttjtjtjtjBtj	B�tj
|�dS)N�O_SHLOCK)rJrrrrxr�ryr0r�
O_NONBLOCKrrrr�)rr~rrr�
test_osexlock�s

zPosixTester.test_osexlockr�ztest needs posix.O_SHLOCKcCs�tjtjtjtjBtjB�}tjtjtjtjBtjB�}tj|�tj|�tt	d�r�tjtjtjtjBtjB�}|j
ttjtjtjtj
BtjB�tj|�dS)Nr�)rJrrrrxr�ryrrrr0rrir�r�)rZfd1Zfd2r~rrr�
test_osshlock�s


zPosixTester.test_osshlock�fstatztest needs posix.fstat()cCs`ttj�}zF|jtj|j���|jtj|j���|jt	dtjt
|j���Wd|j�XdS)Nz4should be string, bytes, os.PathLike or integer, not)rrrrUrr�rY�stat�assertRaisesRegexr1�floatr)rrrrr�
test_fstat�s
zPosixTester.test_fstatr�ztest needs posix.stat()cCs�|jtjtj��|jtjtjtj���|jtdtjt	tjtj���|j
tdtjd�|j
tdtjttj��|j
tdtjttjtj���dS)Nz4should be string, bytes, os.PathLike or integer, not)
rUrr�rrrJ�fsencodeZassertWarnsRegex�DeprecationWarningr�r�r1�list)rrrr�	test_stat�s
zPosixTester.test_stat�mkfifozdon't have mkfifo()cCsvtjtj�ytjtjtjtjB�Wn0tk
rV}z|j	d|�WYdd}~XnX|j
tjtjtj�j��dS)Nzposix.mkfifo(): %s)
rrrrr�r��S_IRUSR�S_IWUSR�PermissionError�skipTestrU�S_ISFIFO�st_mode)rr
rrr�test_mkfifo�s zPosixTester.test_mkfifo�mknod�S_IFIFOzdon't have mknod()/S_IFIFOcCs�tjtj�tjtjBtjB}ytjtj|d�Wn<t	k
rn}z |j
|jtjtj
tjf�WYdd}~XnX|jtjtjtj�j��tjtj�ytjtj|ddd�Wn<t	k
r�}z |j
|jtjtj
tjf�WYdd}~XnXdS)Nr)rk�modeZdevice�dir_fd)rrrr�r�r�r�rr�r�assertInr	rQr��EACCESrUr�r�)rr�r
rrr�
test_mknod�s,zPosixTester.test_mknod�makedevztest needs posix.makedev()cCs�tjtj�}|j}|j|t�|j|d�tj|�}|j|t�|j|d�|j	tj|�|�|j
ttjt|��|j
ttj�|j
t
tftjd�tj|�}|j|t�|j|d�|j	tj|�|�|j
ttjt|��|j
ttj�|j
t
tftjd�tjjd��r |dk�r |jd�|j	tj||�|�|j
ttjt|�|�|j
ttj|t|��|j
ttj|�|j
ttj�dS)Nrr.r�lzEbpo-31044: on FreeBSD CURRENT, minor() truncates 64-bit dev to 32-bitr>r>)rr�rr�st_devr�r�r8�majorr6r0r1r�r��
OverflowError�minorrgr�r�r�r�)r�stZdevr�r�rrr�test_makedevs2


zPosixTester.test_makedevc	s����fdd�}tj�}tj�}|�||�|||�|�d|�|||�|�|d�|||�|dkr�d
}|�||�|||�|�dd�|||�|�||�|||�nztj�dkr�tjd	��nb�jt|�dd�|||��jt|�dd�|||�dtj	�k�r,�jt|�dd�|||�xRt
tfD]F}�jt|�||�|�|||��jt|�|||��|||��q6Wd
S)z/Common code for chown, fchown and lchown tests.cs0�dk	r,���}�j|j|��j|j|�dS)N)r6�st_uid�st_gid)�uid�gidr�)�first_paramr�	stat_funcrr�
check_stat,sz6PosixTester._test_all_chown_common.<locals>.check_statr.rr��HP-UX�SunOSz1Skipping because of non-standard chown() behaviorNr>r>lr>r>)r�r�r>r>)
rJr,r'r��systemrOrPr0rr(�strr�r1)	rZ
chown_funcr�r�r�r�r�Z	big_value�tr)r�rr�r�_test_all_chown_common*s>








z"PosixTester._test_all_chown_common�chownztest needs os.chown()cCsLtjtj�|jttjtjdd�tjtj�|j	tjtjt
tdd��dS)Nr.r�r>r>)rJrrrr0rrr��create_empty_filer�r/)rrrr�
test_chownes
zPosixTester.test_chown�fchownztest needs os.fchown()c
CsLtjtj�ttjd�}z$|j�}|jtj|t	tdd��Wd|j
�XdS)Nrar�)rJrrrrrYr�rrr/r)rZ	test_filer~rrr�test_fchownps
zPosixTester.test_fchown�lchownztest needs os.lchown()cCs8tjtj�tjttj�|jtjtjt	tdd��dS)N�lstat)
rJrrr�symlink�_DUMMY_SYMLINKr�rrr/)rrrr�test_lchown}szPosixTester.test_lchownrjztest needs posix.chdir()cCs"tjtj�|jttjtj�dS)N)rrjrJrVr0rrr)rrrr�
test_chdir�szPosixTester.test_chdircCs|jtjtjtj��dS)N)r�rrr�listdirrJrV)rrrr�test_listdir�szPosixTester.test_listdircCs|jtjtj��dS)N)r�rrrr)rrrr�test_listdir_default�sz PosixTester.test_listdir_defaultcCs|jtjtj�tjd��dS)N�.)r�rJr�rrrr)rrrr�test_listdir_bytes�szPosixTester.test_listdir_bytescCslxfttfD]Z}|jt��tj|d��}WdQRX|jtjt	j
�|�x|D]}|jt|�t
�qLWq
WdS)Nr)r��
memoryviewZassertWarnsr�rrr�rJr�rrZassertIs�typer�)r�cls�namesr2rrr�test_listdir_bytes_like�s
z#PosixTester.test_listdir_bytes_likez)test needs fd support for posix.listdir()cCsdtjtj�tj�}|jtj|�|jttjd��ttj|���|jttjd��ttj|���dS)N�.)	rrr rir�rr6�sortedr)r�frrr�test_listdir_fd�szPosixTester.test_listdir_fd�accessztest needs posix.access()cCs|jtjtjtj��dS)N)rUrrrrrJ�R_OK)rrrr�test_access�szPosixTester.test_access�umaskztest needs posix.umask()cCs$tjd�}|j|t�tj|�dS)Nr)rrr�r�)rZold_maskrrr�
test_umask�s
zPosixTester.test_umask�strerrorztest needs posix.strerror()cCs|jtjd��dS)Nr)rUrr)rrrr�
test_strerror�szPosixTester.test_strerror�pipeztest needs posix.pipe()cCs$tj�\}}tj|�tj|�dS)N)rrrJr)r�reader�writerrrr�	test_pipe�s
zPosixTester.test_pipe�pipe2ztest needs os.pipe2()�cCs�|jttjd�|jttjdd�tjd�\}}tj|�tj|�tjtjtjB�\}}|jtj|�|jtj|�|jtj	|��|jtj	|��|jtj
|��|jtj
|��|jttj|d�ytj
|dtj�Wntk
r�YnXdS)NZDEADBEEFrr.r�)r0r1rJr!rr�r�r�r�r��get_blockingrr�r]rZ
PIPE_MAX_SIZE)r�rrarrr�
test_pipe2�s"

zPosixTester.test_pipe2cCs8ddl}|jttj|jd�|jttj|jd�dS)Nrr.)�	_testcapir0r�rJr!ZINT_MAXZUINT_MAX)rr&rrr�test_pipe2_c_limits�szPosixTester.test_pipe2_c_limitsr�ztest needs posix.utime()cCs�tj�}tjtjd�|jttjtjd�|jttjtj|df�|jttjtjd|f�tjtjt|�t|�f�tjtj||f�dS)N)NN)r�rr�rrr0r1r�)rr�rrr�
test_utime�szPosixTester.test_utimec&Ks�tj|�}|jt|d��|jtjB}y|||f|�Wn>tk
rv}z"|jtjkrX�d}|j	|�WYdd}~XnXzftj|�}|j
|jtjB|j�yt|d�}	Wn2tk
r�}
z|j
|
jtj�WYdd}
~
XnXWdt
j||j�XdS)N�st_flagsz2chflag UF_IMMUTABLE not supported by underlying fszw+)rJr�rUrr)�UF_IMMUTABLErr	�
EOPNOTSUPPr�r6rrQr�chflags)rZchflags_funcZtarget_file�kwargsr��flags�err�msgZnew_str~r
rrr�_test_chflags_regular_file�s$

&z&PosixTester._test_chflags_regular_filer,ztest needs os.chflags()cCs|jtjtj�dS)N)r1rr,rr)rrrr�test_chflags
szPosixTester.test_chflags�lchflagsztest needs os.lchflags()cCs(|jtjtj�|jtjtjdd�dS)NF)r�)r1rr3rrr,)rrrr�test_lchflags_regular_filesz&PosixTester.test_lchflags_regular_filec
Cs
tjtj�}|jt|d��tjtjt�|jj	t�tj
t�}dd�}x�tj|fD]�}|j
tjB}y|t|�Wn>tk
r�}z"|jtjkr��d}|j|�WYdd}~XnXz@tjtj�}tj
t�}	|j|j
|j
�|j|j
tjB|	j
�Wd|t|j
�XqTWdS)Nr)cSstj||dd�S)NF)r�)rr,)rkr.rrr�chflags_nofollowsz;PosixTester.test_lchflags_symlink.<locals>.chflags_nofollowz2chflag UF_IMMUTABLE not supported by underlying fs)rJr�rrrUrrrr�appendrrr3r)r*rr	r+r�r6)
rZ	testfn_stZdummy_symlink_str5�fnr.r/r0Z
new_testfn_stZnew_dummy_symlink_strrr�test_lchflags_symlinks,

z!PosixTester.test_lchflags_symlinkcCsPtjdkrt}nt}x6tjj�D](\}}|jt|�|�|jt|�|�q WdS)N�nt)	rJr2r�r�rrm�itemsr6r)rZ	item_type�k�vrrr�test_environ4s
zPosixTester.test_environ�putenvzrequires os.putenv()c-Cs�|jt��tjdd�WdQRX|jt��tjdd�WdQRX|jt��tjdd�WdQRX|jt��tjdd�WdQRX|jt��tjd	d
�WdQRX|jt��tjdd�WdQRXdS)
NzFRUITVEGETABLEZcabbagesFRUITVEGETABLEscabbageZFRUITzorangeVEGETABLE=cabbagesFRUITsorangeVEGETABLE=cabbagezFRUIT=ORANGEZlemonsFRUIT=ORANGEslemon)r0r�rJr>)rrrr�test_putenv=szPosixTester.test_putenvr ztest needs posix.getcwd()csbd}tj�}tjjtj�d}z(ytj|�tj|�Wn
dSWdtj|�tj|�XdS)Nz8getcwd-test-directory-0123456789abcdef-01234567890abcdefz.getcwdrcsvytj|�Wntjd��YnXtj|�z*tj�|dkrX�||t|�d�Wdtjd�tj|�XdS)Nz?mkdir cannot create directory sufficiently deep for getcwd testir.z..)rJ�mkdirrOrPrjr r7�rmdir)�dirnameZcurrent_path_length)�_create_and_do_getcwdrrrC[s

zEPosixTester.test_getcwd_long_pathnames.<locals>._create_and_do_getcwd)	rJr rk�abspathrrr@rj�rmtree)rrBrV�	base_pathr)rCr�test_getcwd_long_pathnamesLs

z&PosixTester.test_getcwd_long_pathnames�getgrouplistztest needs posix.getgrouplist()rLztest needs pwd.getpwuid()r,ztest needs os.getuid()cCs<tjtj��d}tjtj��d}|j|tj||��dS)Nrr5)rKrLrJr,r�rrH)r�user�grouprrr�test_getgrouplistpszPosixTester.test_getgrouplistr%ztest needs os.getegid()cCs�tjd��}|j�j�}|j�}WdQRXytdd�|j�D��}Wntk
r^t�}YnX|dk	sn|rxtj	d��t
jdkr�ddl}|j
d�p�d}td	d�|jd
�dd�D��dkr�tj	d��|jtj��}|j|p�|tj�hk�dS)Nzid -G 2>/dev/nullcss|]}t|�VqdS)N)r�)r��grrr�	<genexpr>�sz-PosixTester.test_getgroups.<locals>.<genexpr>zneed working 'id -G'�darwinr�MACOSX_DEPLOYMENT_TARGETz10.0css|]}t|�VqdS)N)r�)r�r�rrrrM�srrr�r�z$getgroups(2) is broken prior to 10.6)r�r�)rJ�popenr��stripr�setrlr�rOrPrgr��	sysconfig�get_config_var�tuple�symmetric_differencerr(rUr%)rZidg�groupsZretZ
idg_groupsrSZdtZsymdiffrrr�test_getgroupsys 

$
zPosixTester.test_getgroupsz)test needs dir_fd support for os.access()cCsBtjtj�tj�}z|jtjtjtj	|d��Wdtj
|�XdS)N)r�)rrr rirUrrrrJrr)rrrrr�test_access_dir_fd�szPosixTester.test_access_dir_fdz'test needs dir_fd support in os.chmod()cCs|tjtjtj�tjtj�tj	�}zHtjtjtjtj
B|d�tjtj�}|j|dtj@tjtj
B�Wdtj
|�XdS)N)r�r)rJ�chmodrrr�r�rrr rir�r6�S_IRWXUr)rr�srrr�test_chmod_dir_fd�s"zPosixTester.test_chmod_dir_fdz'test needs dir_fd support in os.chown()cCs\tjtj�tjtj�tjtj�tj�}z tjtjt	j
�t	j�|d�Wdtj|�XdS)N)r�)
rrrr�rrr rir�rJr,r'r)rrrrr�test_chown_dir_fd�s zPosixTester.test_chown_dir_fdz&test needs dir_fd support in os.stat()cCs�tjtj�ttjd��}|jd�WdQRXtjtj�tj�}z�tjtj�}tjtj|d�}|j	||�tjtjdd�}|j	||�|j
tdtjtjtj�d�|j
tdtjtjt|�d�|j
ttjtjdd�Wdtj|�XdS)Nraz	testline
)r�zshould be integer or None, notr��l F�x:^V)rrrrr]rr rir�r6r�r1r�r0r�r)r�outfiler�s1�s2rrr�test_stat_dir_fd�s"zPosixTester.test_stat_dir_fdz'test needs dir_fd support in os.utime()cCs�tjtj�tj�}�zvtj�}tjtjd|d�tjtj|d�|jt	tjtj||d�|jt	tjtjd|d�|jt	tjtj|df|d�|jt	tjtjd|f|d�|jt	tjtj|df|d�tjtjt
|�t
|�f|d�tjtj||f|d�tjtjt
|�t
|t
|�d�f|d�tjtj|t
|�t
|t
|�d�fd�tjtjk�r�ytjtjd|d�Wnt
k
�r�YnXWdtj|�XdS)N)r��xge��A)r�r#F)r�r�)NN)rrr rir�r�rrr0r1r�rJ�supports_follow_symlinksr�r)rrr�rrr�test_utime_dir_fd�s,"
 
zPosixTester.test_utime_dir_fdz&test needs dir_fd support in os.link()cCs�tjtj�tj�}z|ytjtjtjd||d�Wn0tk
rb}z|jd|�WYdd}~Xn*X|j	tj
tj�dtj
tjd�d�Wdtj|�tjtjd�XdS)N�link)�
src_dir_fd�
dst_dir_fdzposix.link(): %sr.)
rrr rirgrrr�r�r6r�rr)rrr
rrr�test_link_dir_fd�s 
zPosixTester.test_link_dir_fdz'test needs dir_fd support in os.mkdir()cCs\tjtj�tj�}z(tjtjd|d�tjtjd�Wdtj|�tj	tjd�XdS)N�dir)r�)
rrr rir@rrr�rrE)rrrrr�test_mkdir_dir_fd�s
zPosixTester.test_mkdir_dir_fdzAtest requires both stat.S_IFIFO and dir_fd support for os.mknod()cCs�tjtj�tjtjBtjB}tjtj	�tj
�}ztytjtj|d|d�Wn<tk
r�}z |j
|jtjtjtjf�WYdd}~XnX|jtjtjtj�j��Wdtj|�XdS)Nr)r�)rrrr�r�r�r�rrr rir�rr�r	rQr�r�rUr�r�r)rr�rr
rrr�test_mknod_dir_fds,zPosixTester.test_mknod_dir_fdz&test needs dir_fd support in os.open()cCs�tjtj�ttjd��}|jd�WdQRXtjtj�tj�}tjtjtj|d�}z$tj|d�j	dd�}|j
d|�Wdtj|�tj|�XdS)Nraz	testline
)r��	zutf-8)�encoding)rrrrr]rr rir��decoder6r)rr`�a�brtrrr�test_open_dir_fds
zPosixTester.test_open_dir_fdz*test needs dir_fd support in os.readlink()cCsttjtjtjd�tjtj�tj�}z,|jtj	tjd�tj	tjd|d��Wdtj
tjd�tj|�XdS)Nrg)r�)rJrrrrrr rir6�readlinkrr)rrrrr�test_readlink_dir_fd$sz PosixTester.test_readlink_dir_fdz(test needs dir_fd support in os.rename()cCs�tjtj�tjtjd�tjtj�tj�}zRytjtjdtj||d�Wn"tjtjdtj��YnXtj	tj�Wdtj
|�XdS)NZren)rhri)rrrr�rrr ri�renamer�r)rrrrr�test_rename_dir_fd/szPosixTester.test_rename_dir_fdz)test needs dir_fd support in os.symlink()cCsjtjtj�tj�}z6tjtjtjd|d�|jtjtjd�tj�Wdtj	|�tj
tjd�XdS)Nrg)r�)rrr rirrrr6rtrr)rrrrr�test_symlink_dir_fd>s
zPosixTester.test_symlink_dir_fdz(test needs dir_fd support in os.unlink()cCs�tjtj�tj�}tjtjd�tjtjd�zRytjtjd|d�Wntjtjd��YnX|j	t
tjtjd�Wdtj|�XdS)N�del)r�rg)rrr rirr�rr�rr0rr)rrrrr�test_unlink_dir_fdHszPosixTester.test_unlink_dir_fdz(test needs dir_fd support in os.mkfifo()cCs�tjtj�tjtj�tj�}znytjtjtj	tj
B|d�Wn0tk
rn}z|jd|�WYdd}~XnX|j
tjtjtj�j��Wdtj|�XdS)N)r�zposix.mkfifo(): %s)rrrrrr rir�r�r�r�r�r�rUr�r�r)rrr
rrr�test_mkfifo_dir_fdWs zPosixTester.test_mkfifo_dir_fd�sched_yieldzdon't have scheduling support�sched_setaffinityz!don't have sched affinity supportcCstj�dS)N)rr|)rrrr�test_sched_yieldjszPosixTester.test_sched_yield�sched_get_priority_maxz!requires sched_get_priority_max()cCsltj}tj|�}tj|�}|j|t�|j|t�|j||�tjdkrh|j	t
tjd�|j	t
tjd�dS)NrNr�i��i��)r�SCHED_RR�sched_get_priority_minrr�r�r8rgr�r0r)rZpol�lo�hirrr�test_sched_priorityos


zPosixTester.test_sched_priorityc"Cs�dd�tjj�D�}tjd�}|j||�ytjtj��}Wn0tk
rl}z|jtj	kr\�WYdd}~XnX|j||�|j
ttjd
�|j
ttjd�tjd�}|j|j
t�tjjd��s&ytjd||�tjd|�Wn4tk
�r}z|jtj	k�r�WYdd}~XnX|j
ttjd
|�|j
ttjd||�|j
ttjd|d�|j
ttjdd�tjd�}|j
ttjd|�d}tj|�}|j
ttjd|�tj|d	�}|j
ttjd|�dS)NcSsg|]\}}|jd�r|�qS)ZSCHED_)r�)r�r2Zschedrrrr��szDPosixTester.test_get_and_set_scheduler_and_param.<locals>.<listcomp>rr.r�r��+l���)�sched_priorityr>r>)r�r�r>r>)r�__dict__r:rr�rJr+rr	rQr0�sched_getparamr�r�r�rgr�r��sched_setscheduler�sched_setparamr1�sched_paramr�)rZpossible_schedulersZmine�parentr
ZparamZlargerrr�$test_get_and_set_scheduler_and_params>



z0PosixTester.test_get_and_set_scheduler_and_param�sched_rr_get_intervalzno functioncCsrytjd�}Wn:tk
rH}z|jtjkr.�|jd�WYdd}~XnX|j|t�|j|d�|j	|d�dS)Nrz only works on SCHED_RR processesgg�?)
rr�rr	r�r�r�r�r8�
assertLess)rZintervalr
rrr�test_sched_rr_get_interval�sz&PosixTester.test_sched_rr_get_intervalcCsltjd�}|j|t�|jt|�d�|jttjd�x0|D](}|j|t�|j|d�|j	|d�q<WdS)Nrr.rr>l)
r�sched_getaffinityr�rRr8r7r0rr�r�)r�maskZcpurrr�test_sched_getaffinity�s

z"PosixTester.test_sched_getaffinitycCs�tjd�}t|�dkr|j�tjd|�|jtjd�|�|jttjdg�|jttjddg�|jt	tjddd>g�|jttjd|�dS)Nrr.r��i����r>)
rr�r7�popr}r6r0rr�r�)rr�rrr�test_sched_setaffinity�s
z"PosixTester.test_sched_setaffinitycCstjtjtjtjdS)N)r�	RTLD_LAZY�RTLD_NOW�RTLD_GLOBAL�
RTLD_LOCAL)rrrr�test_rtld_constants�szPosixTester.test_rtld_constantsz-running kernel may not match kernel in chroot�	SEEK_HOLEz(test needs an OS that reports file holescCs�ttjd���}|jd�|j�|j�}|j�}yrx@t|�D]4}|j|t	j
||t	j��|j|t	j
||t	j
��q<W|jtt	j
||t	j�|jtt	j
||t	j
�Wntk
r�tjd��YnXWdQRXdS)Nzr+bshellozOSError raised!)rrrr]r^�tellrY�ranger6rJrz�	SEEK_DATAZassertLessEqualr�r0rrOrP)rrr�Zfnor�rrr�
test_fs_holes�s

zPosixTester.test_fs_holescCs�x�d	D]�}tt|d�}|dkr qxjdtjfD]N}y|d|�Wq,tk
rx}z|jdj|�t|��PWYdd}~Xq,Xq,W|jd|�qWdS)
zf
        Test functions that call path_error2(), providing two filenames in their exceptions.
        rv�replacergNZnoodly2Zdoesnotexistfilenamez'doesnotexistfilename' -> '{}'z#No valid path_error2() test for os.)rvr�rg)	r/rJrrrr��formatr�rR)rr2Zfunction�dstr
rrr�test_path_error2�s
zPosixTester.test_path_error2cCs�tj}|d}|jtj|�tj|�d}z.|jt��tj|tjtj	B�}WdQRXWd|dk	rltj
|�X|jtjj
|��|jttj|�|jtjj
|��t|d�j
�|jttj|�dS)N��wb)rrr�rr0r�rJrrxryrr�rk�existsr@r�)rr7�fn_with_NULr~rrr�test_path_with_null_characters
"z)PosixTester.test_path_with_null_charactercCs�tjtj�}|d}|jtj|�tj|�d}z.|jt��tj|tj	tj
B�}WdQRXWd|dk	rrtj|�X|jtj
j|��|jttj|�|jtj
j|��t|d�j�|jttj|�dS)Nr�r�)rJr�rrr�rr0r�rrxryrr�rkr�r@r�)rr7r�r~rrr�test_path_with_null_bytes
"z$PosixTester.test_path_with_null_byte)�__name__�
__module__�__qualname__rrr3rO�
skipUnlessrrr:r<rArBrErFrSrWrZr_rbr/rJ�supports_fdrorurr�r�r�r�r�r�r�r�rer�r��requires_32br�r�r�r�r�r�rZrequires_linux_versionr�r�r�r�r�r�r�r�r�r�r�rrrr	r
rrrrrrrr r%Zcpython_onlyr'r(r1r2r4r8r=r?rGrKrKrXr�supports_dir_fdrYrZr]r�r^rcrfrgrjr@rlr�rmrrsrtrurvrwrrxrrzr�r{Zrequires_sched_hZrequires_sched_affinityr~r��requires_schedr�r�r�r�r�Z_skipInRpmBuildr�r�r�r�rrrrr%s
	





	!;

!	$
 "
""""
"")"

rc@sPeZdZdd�Zdd�Zejeed�d�dd��Z	ejeed	�d
�dd��Z
d
S)�PosixGroupsTestercCsLtj�dkrtjd��ttd�s*tjd��tjdkr>tjd��tj�|_dS)Nrznot enough privilegesr(zneed posix.getgroupsrNzgetgroups(2) is broken on OSX)	rr,rOrPrrgr�r(�saved_groups)rrrrr*s




zPosixGroupsTester.setUpcCsHttd�rtj|j�n,ttd�rDtjtj��j}tj||jd�dS)N�	setgroupsrGr)	rrr�r�rKrLr,rMrG)rr2rrrr3s


zPosixGroupsTester.tearDownrGztest needs posix.initgroups()cCsDt|jpdg�d}tjtj��j}tj||�|j|tj	��dS)Nrr.)
�maxr�rKrLrr,rMrGr�r()rrLr2rrrrS:sz!PosixGroupsTester.test_initgroupsr�ztest needs posix.setgroups()cCs:x4dgttd��gD]}tj|�|j|tj��qWdS)Nrr�)r�r�rr�ZassertListEqualr()rrWrrr�test_setgroupsDs
z PosixGroupsTester.test_setgroupsN)r�r�r�rrrOr�rrrSr�rrrrr�(s		r�c
Cs ztjtt�Wdtj�XdS)N)rZrun_unittestrr�Z
reap_childrenrrrr�	test_mainKsr��__main__l)�__doc__r\r�
import_modulerr	rgr�rJr�rKr�ZtempfilerOrrk�joinZ
gettempdirrrr��maxsizer�r
r�ZTestCaserr�r�r�rrrr�<module>sB


#