Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_posix.cpython-34.pyc

�
g fJ��@s/dZddlmZejd�ZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZejjej�ejd�ZGdd�dej�ZGdd	�d	ej�Zd
d�Zedkr+e�ndS)
zTest posix functions�)�support�posixNz-dummy-symlinkc@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	dL�dM�dNdO��ZejejejkdP�dQdR��Z ejejej!kdS�dTdU��Z"ejee	dV�dW�dXdY��Z#ejee	dZ�d[�d\d]��Z$ejee	d^�d_�d`da��Z%ejee	db�dc�ddde��Z&ejee	df�dg�dhdi��Z'ejeedj�dk�e(j)dldmdn�dodp���Z*ejee	dq�dr�dsdt��Z+ejee	du�dv�dwdx��Z,ejee	dy�dz�d{d|��Z-ejee	d}�d~�dd���Z.ejee	d��d��d�d���Z/ejee	d��o�ee0d��d��d�d���Z1ejee	d}�d~�ejee	d��d��d�d����Z2d�d��Z3ejee	d��d��d�d���Z4ejee	d��d��d�d���Z5ejee	d��d��d�d���Z6ejee	d��d��d�d���Z7d�d��Z8d�d��Z9d�d��Z:eje	j;ejkd��d�d���Z<ejee	d��d��d�d���Z=ejee	d��d��d�d���Z>ejee	d��d��d�d���Z?ejee	d��d��d�d���Z@ejeed��d��e(j)dldmd��d�d����ZAe(jBejeed��d��e(j)dldmd��d�d�����ZCejee	d��d��d�d���ZDd�d��ZEejee	d��d��d�d���ZFejee	d��d��d�d���ZGejee	d��d��d�d���ZHd�d��ZIejee	d��d��d�d���ZJejee	d��d��ejeeKd��d��ejeed��d��d�d�����ZLejeed��d��d�d���ZMejejNejOkd��d�d���ZPejejQejOkd��d�d���ZRejejSejOkd��d�d���ZTejej0ejOkd��d�d���ZUejejejOkd��d�d���ZVejejWejOkd��d�d���ZXejejYejOkd��d�d���ZZejej[ejOko�
ee0d��d��d�d���Z\ejej]ejOkd��d�d���Z^ejej_ejOkd��d�d���Z`ejejaejOkd�dd��ZbejejcejOkd�dd��ZdejejeejOkd�dd��ZfejejgejOkd	�d
d��Zhejee	d�d
�Ziejee	d�d�Zjeidd��Zkeiejee	d�d�dd���Zlejee	d�d�dd��Zmejee	d�d�dd��Znejdd��Zoejd d!��Zpd"d#�Zqejrd$�ejeed%�d&�d'd(���Zsd)d*�Ztd+d,�Zud-d.�Zvd0S(/�PosixTestercCs^ttjd�}|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�fp�r�4/opt/alt/python34/lib64/python3.4/test/test_posix.py�setUps

zPosixTester.setUpcCs;x|jD]}tj|�q
W|jjddd�dS)N)r	r�unlinkr
�__exit__)rZ
teardown_filerrr�tearDown$szPosixTester.tearDowncCs�ddddddddd	d
ddd
ddg}xI|D]A}tt|d�}|dk	r:|�|jt|d�q: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�testNoArgFunctions)s
zPosixTester.testNoArgFunctions�	getresuidztest needs posix.getresuid()cCsGtj�}|jt|�d�x|D]}|j|d�q)WdS)N�r)rr,�assertEqual�len�assertGreaterEqual)rZuser_ids�valrrr�test_getresuid8s
zPosixTester.test_getresuid�	getresgidztest needs posix.getresgid()cCsGtj�}|jt|�d�x|D]}|j|d�q)WdS)Nr-r)rr3r.r/r0)rZ	group_idsr1rrr�test_getresgid@s
zPosixTester.test_getresgid�	setresuidztest needs posix.setresuid()cCsBtj�}|jtj|��|jtjddd��dS)Nr&���r6r6)rr,�assertIsNoner5)r�current_user_idsrrr�test_setresuidHszPosixTester.test_setresuidcCsLtj�}d|krH|ddddf}|jttj|�ndS)Nrr&r6r6)rr,r(�OSErrorr5)rr8Znew_user_idsrrr�test_setresuid_exceptionPsz$PosixTester.test_setresuid_exception�	setresgidztest needs posix.setresgid()cCsBtj�}|jtj|��|jtjddd��dS)Nr&r6r6r6)rr3r7r<)r�current_group_idsrrr�test_setresgidYszPosixTester.test_setresgidcCsLtj�}d|krH|ddddf}|jttj|�ndS)Nrr&r6r6)rr3r(r:r<)rr=Z
new_group_idsrrr�test_setresgid_exceptionasz$PosixTester.test_setresgid_exception�
initgroupsztest needs os.initgroups()cCs|jttj�|jttjd�|jttjdd�|jttjddt��tj�dkrytjtj��j	}Wn!t
k
r�tjd��YnXytj|d�Wn;t
k
r}z|j|jtj�WYdd}~XqX|jd�ndS)Nr-Zfoorzneed a pwd entry�
z+Expected OSError to be raised by initgroups)r(r)rr@�object�osr$�pwd�getpwuid�pw_name�KeyError�unittest�SkipTestr:r.�errno�EPERM�fail)rr*�errr�test_initgroupsjs
)zPosixTester.test_initgroups�statvfsztest needs posix.statvfs()cCs|jtjtj��dS)N)�
assertTruerrOrC�curdir)rrrr�test_statvfs�szPosixTester.test_statvfs�fstatvfsztest needs posix.fstatvfs()c
Cs]ttj�}z<|jtj|j���|jtj|j���Wd|j�XdS)N)	rrrrPrrS�filenorOr)rrrrr�
test_fstatvfs�s
 zPosixTester.test_fstatvfs�	ftruncateztest needs posix.ftruncate()c
CsUttjd�}z1|jd�|j�tj|j�d�Wd|j�XdS)Nzw+�testr)	rrr�write�flushrrVrTr)rrrrr�test_ftruncate�s

zPosixTester.test_ftruncate�truncateztest needs posix.truncate()c	CsIttjd��}|jd�|j�WdQXtjtjd�dS)N�wrWr)rrrrXrYrr[)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�}|dkrxtjtjjtj�d�t	j
|tjddgtj�n"|jtj
|d�|df�Wdtj|�XdS)Nrz-c�pass)rCr�sys�
executable�O_RDONLYr_�chdir�path�splitrr^�environr.r`r)rr�pidrrr�test_fexecve�s %&zPosixTester.test_fexecve�waitidztest needs posix.waitid()cCs�tj�}|dkr`tjtjjtj�d�tjtjtjddgtj	�n.tj
tj|tj�}|j
||j�dS)Nrz-cra)rCr_rerfrgrbrcrr^rhrk�P_PID�WEXITEDr.�si_pid)rri�resrrr�test_waitid�s (zPosixTester.test_waitid�lockfztest needs posix.lockf()cCs�tjtjtjtjB�}zVtj|d�tj|dtj�t	j
|t	jd�t	j
|t	jd�Wdtj
|�XdS)Nstestr�)rCrrr�O_WRONLY�O_CREATrX�lseek�SEEK_SETrrq�F_LOCK�F_ULOCKr)r�fdrrr�
test_lockf�szPosixTester.test_lockf�preadztest needs posix.pread()cCs�tjtjtjtjB�}zetj|d�tj|dtj�|j	dt
j|dd��|j	dt
j|d��Wdtj
|�XdS)Nstestrses�r&ste)rCrrr�O_RDWRrtrXrurvr.rr{�readr)rryrrr�
test_pread�s zPosixTester.test_pread�pwriteztest needs posix.pwrite()cCs�tjtjtjtjB�}zYtj|d�tj|dtj�t	j
|dd�|jdt	j|d��Wdtj
|�XdS)Nstestrsxxr&stxxtrr)rCrrrr}rtrXrurvrr�r.r~r)rryrrr�test_pwrite�s zPosixTester.test_pwrite�posix_fallocatez"test needs posix.posix_fallocate()cCs�tjtjtjtjB�}znytj|dd�WnPtk
r�}z0|j	t	j
ksstjj
d�ry�nWYdd}~XnXWdtj|�XdS)Nr�
�sunos)rCrrrrsrtrr�r:rJ�EINVALrb�platform�
startswithr)rryZinstrrr�test_posix_fallocate�s%z PosixTester.test_posix_fallocate�
posix_fadvisez test needs posix.posix_fadvise()cCsJtjtjtj�}ztj|ddtj�Wdtj|�XdS)Nr)	rCrrrrdrr��POSIX_FADV_WILLNEEDr)rryrrr�test_posix_fadvise�szPosixTester.test_posix_fadvisez!test needs fd support in os.utimecCs�tj�}tjtjtj�}z�tj|�tj|d�|jt	tj|d�|jt	tj||df�|jt	tj|d|f�tj|t
|�t
|�f�tj|||f�|jttj|||fd||f�|jttj||dfdd�|jttj|dd|df�tj|t
|�t
|t
|�d�f�tj|dt
|�t
|t
|�d�f�Wdtj|�XdS)N�nsrge��A)NN)NN)NN)
�timerCrrrrdr�utimer(r)�int�
ValueErrorr)r�nowryrrr�test_utime_with_fd�s 
"+%%07zPosixTester.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)N�follow_symlinksF)NN)r�rr�rrr(r)r�)rr�rrr�test_utime_nofollow_symlinkss"((+z(PosixTester.test_utime_nofollow_symlinks�writevztest needs posix.writev()cCs�tjtjtjtjB�}z�tj|d�}|j|d�tj|dtj	�|jdt
j|d��yt
j|g�}Wntk
r�YnX|j|d�Wdtj
|�XdS)N�test1�tt2�t3r�rs
test1tt2t3)r�r�r�)rCrrrr}rtr�r.rurvrr~r:r)rry�n�sizerrr�test_writevs
zPosixTester.test_writev�readvztest needs posix.readv()cCs�tjtjtjtjB�}z�tj|d�tj|dtj�dd�dddgD�}|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>5s	z*PosixTester.test_readv.<locals>.<listcomp>�r-r|r�stest1stt2st3cSsg|]}t|��qSr)�bytes)r�r�rrrr�7s	)rCrrrr}rtrXrurvr.rr�r:r)rryZbufr�rrr�
test_readv/s&
zPosixTester.test_readv�dupztest needs posix.dup()c
CsWttj�}z6tj|j��}|j|t�tj	|�Wd|j	�XdS)N)
rrrrr�rT�assertIsInstancer�rCr)rrryrrr�test_dupEszPosixTester.test_dup�confstrztest needs posix.confstr()cCs?|jttjd�|jttjd��dkd�dS)NZ
CS_garbage�CS_PATHrT)r(r�rr�r.r/)rrrr�test_confstrPszPosixTester.test_confstr�dup2ztest needs posix.dup2()c
CsZttj�}ttj�}z tj|j�|j��Wd|j�|j�XdS)N)rrrrr�rTr)r�fp1�fp2rrr�	test_dup2Vs 
zPosixTester.test_dup2�	O_CLOEXECzneeds os.O_CLOEXECr|��cCsYtjtjtjtjB�}|jtj|�|jt	j	|t	j
�t	j@�dS)N)rCrrrrdr��
addCleanuprrP�fcntlZF_GETFDZ
FD_CLOEXEC)rryrrr�test_oscloexecaszPosixTester.test_oscloexec�O_EXLOCKztest needs posix.O_EXLOCKcCs�tjtjtjtjBtjB�}|jttjtjtjtjBtj	B�tj
|�ttd�r�tjtjtjtj
BtjB�}|jttjtjtjtjBtj	B�tj
|�ndS)N�O_SHLOCK)rCrrrrsr�rtr(r:�
O_NONBLOCKr�hasattrrr�)rryrrr�
test_osexlockhs
zPosixTester.test_osexlockr�ztest needs posix.O_SHLOCKcCs�tjtjtjtjBtjB�}tjtjtjtjBtjB�}tj|�tj|�tt	d�r�tjtjtjtjBtjB�}|j
ttjtjtjtj
BtjB�tj|�ndS)Nr�)rCrrrrsr�rtrr�rr(r:rdr�r�)rZfd1Zfd2ryrrr�
test_osshlockxs

zPosixTester.test_osshlock�fstatztest needs posix.fstat()cCs�ttj�}za|jtj|j���|jtj|j���|jt	dtjt
|j���Wd|j�XdS)Nz'should be string, bytes or integer, not)rrrrPrr�rT�stat�assertRaisesRegexr)�floatr)rrrrr�
test_fstat�s	zPosixTester.test_fstatr�ztest needs posix.stat()cCs�|jtjtj��|jtjtjtj���|jtjttjtj����|jt	dtjd�|jt	dtjt
tj��|jt	dtjt
tjtj���dS)Nz$can't specify None for path argumentz'should be string, bytes or integer, not)rPrr�rrrC�fsencoder�r�r)�list)rrrr�	test_stat�s"(	
		zPosixTester.test_stat�mkfifozdon't have mkfifo()cCsVtjtj�tjtjtjtjB�|jtj	tjtj�j
��dS)N)rrrrr�r��S_IRUSR�S_IWUSRrP�S_ISFIFO�st_mode)rrrr�test_mkfifo�szPosixTester.test_mkfifo�mknod�S_IFIFOzdon't have mknod()/S_IFIFOcCs1tjtj�tjtjBtjB}ytjtj|d�WnDt	k
r�}z$|j
|jtjtj
f�WYdd}~Xn&X|jtjtjtj�j��tjtj�y)tjdtjd|dddd�WnDt	k
r,}z$|j
|jtjtj
f�WYdd}~XnXdS)Nrrf�modeZdevice�dir_fd)rrrr�r�r�r�rr�r:�assertInrJrKr�rPr�r�)rr�rMrrr�
test_mknod�s2%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�|j	tj||�|�|j
ttjt|�|�|j
ttj|t|��|j
ttj|�|j
ttj�dS)Nrr&r6r6)rr�rr�st_devr�r�r0�majorr.r(r)r�r��
OverflowError�minorr�)r�stZdevr�r�rrr�test_makedev�s.	zPosixTester.test_makedevc	s���fdd�}tj�}tj�}|�||�|||�|�d|�|||�|�|d�|||�|dkr�d
}|�||�|||�|�dd�|||�|�||�|||�n�tj�dkrtjd	��n��jt|�dd�|||��jt|�dd�|||�dtj	�kr��jt|�dd�|||�nxlt
tfD]^}�jt|�||�|�|||��jt|�|||��|||�q�Wd
S)z/Common code for chown, fchown and lchown tests.csE�dk	rA���}�j|j|��j|j|�ndS)N)r.�st_uid�st_gid)�uid�gidr�)�first_paramr�	stat_funcrr�
check_stat�sz6PosixTester._test_all_chown_common.<locals>.check_statr&rr|��HP-UX�SunOSz1Skipping because of non-standard chown() behaviorNr6r6lr6r6)r�r�r6r6)
rCr$rr��systemrHrIr(r:r �strr�r))	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()cCshtjtj�|jttjtjdd�tjtj�|j	tjtjt
tdd��dS)Nr&r�r6r6)rCrrrr(r:rr��create_empty_filer�r')rrrr�
test_chowns
zPosixTester.test_chown�fchownztest needs os.fchown()c
Csftjtj�ttjd�}z2|j�}|jtj|t	tdd��Wd|j
�XdS)Nr\r�)rCrrrrrTr�rr�r'r)rZ	test_fileryrrr�test_fchown*szPosixTester.test_fchown�lchownztest needs os.lchown()cCsLtjtj�tjttj�|jtjtjt	tdd��dS)N�lstat)
rCrrr�symlink�_DUMMY_SYMLINKr�rr�r')rrrr�test_lchown7szPosixTester.test_lchownreztest needs posix.chdir()cCs-tjtj�|jttjtj�dS)N)rrerCrQr(r:rr)rrrr�
test_chdir?szPosixTester.test_chdircCs&|jtjtjtj�k�dS)N)rPrrr�listdirrCrQ)rrrr�test_listdirDszPosixTester.test_listdircCs |jtjtj�k�dS)N)rPrrrr�)rrrr�test_listdir_defaultGsz PosixTester.test_listdir_defaultcCs,|jtjtj�tjd�k�dS)N�.)rPrCr�rrrr�)rrrr�test_listdir_bytesLszPosixTester.test_listdir_bytesz)test needs fd support for posix.listdir()cCs�tjtj�tj�}|jtj|�|jttjd��ttj|���|jttjd��ttj|���dS)N�.)	rrrrdr�rr.�sortedr�)r�frrr�test_listdir_fdQszPosixTester.test_listdir_fd�accessztest needs posix.access()cCs#|jtjtjtj��dS)N)rPrr�rrrC�R_OK)rrrr�test_access`szPosixTester.test_access�umaskztest needs posix.umask()cCs0tjd�}|j|t�tj|�dS)Nr)rr�r�r�)rZold_maskrrr�
test_umaskdszPosixTester.test_umask�strerrorztest needs posix.strerror()cCs|jtjd��dS)Nr)rPrr�)rrrr�
test_strerrorjszPosixTester.test_strerror�pipeztest needs posix.pipe()cCs0tj�\}}tj|�tj|�dS)N)rr�rCr)r�reader�writerrrr�	test_pipeos
zPosixTester.test_pipe�pipe2ztest needs os.pipe2()�cCsb|jttjd�|jttjdd�tjd�\}}tj|�tj|�tjtjtjB�\}}|jtj|�|jtj|�|jtj	|��|jtj	|��|j
tj|tj�tj@�|j
tj|tj�tj@�|jt
tj|d�ytj|dtj�Wnt
k
r]YnXdS)NZDEADBEEFrr&�x)r(r)rCrrr�r�r��assertFalse�get_inheritablerPr�ZF_GETFLr:r~rXrZ
PIPE_MAX_SIZE)r�rr\rrr�
test_pipe2us"

##
zPosixTester.test_pipe2cCsJddl}|jttj|jd�|jttj|jd�dS)Nrr&)�	_testcapir(r�rCrZINT_MAXZUINT_MAX)rr	rrr�test_pipe2_c_limits�szPosixTester.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�rrr(r)r�)rr�rrr�
test_utime�s""%zPosixTester.test_utimec&Ks8tj|�}|jt|d��|jtjB}y||||�WnPtk
r�}z0|jtjkrv�nd}|j	|�WYdd}~XnXz�tj|�}|j
|jtjB|j�yt|d�}	Wn;tk
r}
z|j
|
jtj�WYdd}
~
XnXWdt
j||j�XdS)N�st_flagsz2chflag UF_IMMUTABLE not supported by underlying fszw+)rCr�rPr�r�UF_IMMUTABLEr:rJ�
EOPNOTSUPP�skipTestr.rrKr�chflags)rZchflags_funcZtarget_file�kwargsr��flags�err�msgZnew_stryrMrrr�_test_chflags_regular_file�s$ -z&PosixTester._test_chflags_regular_filerztest needs os.chflags()cCs|jtjtj�dS)N)rrrrr)rrrr�test_chflags�szPosixTester.test_chflags�lchflagsztest needs os.lchflags()cCs6|jtjtj�|jtjtjdd�dS)Nr�F)rrrrrr)rrrr�test_lchflags_regular_file�sz&PosixTester.test_lchflags_regular_filec
Csdtjtj�}|jt|d��tjtjt�|jj	t�tj
t�}dd�}x�tj|fD]�}|j
tjB}y|t|�WnPtk
r�}z0|jtjkr��nd}|j|�WYdd}~XnXzXtjtj�}tj
t�}	|j|j
|j
�|j|j
tjB|	j
�Wd|t|j
�XqvWdS)NrcSstj||dd�S)Nr�F)rr)rfrrrr�chflags_nofollow�sz;PosixTester.test_lchflags_symlink.<locals>.chflags_nofollowz2chflag UF_IMMUTABLE not supported by underlying fs)rCr�rrrPr�r�r�r	�appendr�rrrr
r:rJrrr.)
rZ	testfn_stZdummy_symlink_str�fnrrrZ
new_testfn_stZnew_dummy_symlink_strrr�test_lchflags_symlink�s, z!PosixTester.test_lchflags_symlinkcCsntjdkrt}nt}xItjj�D]8\}}|jt|�|�|jt|�|�q.WdS)N�nt)	rCr*r�r�rrh�itemsr.�type)rZ	item_type�k�vrrr�test_environ�s	zPosixTester.test_environrztest needs posix.getcwd()cs�d}tj�}tjjtj�d}zPytj|�tj|�Wn+dSd�fdd���|�YnXWdtj|�tj|�XdS)Nz8getcwd-test-directory-0123456789abcdef-01234567890abcdefz.getcwdrcs�ytj|�Wntjd��YnXtj|�z8tj�|dkro�||t|�d�nWdtjd�tj|�XdS)Nz?mkdir cannot create directory sufficiently deep for getcwd testir&z..)rC�mkdirrHrIrerr/�rmdir)�dirnameZcurrent_path_length)�_create_and_do_getcwdrrr&�s

"
zEPosixTester.test_getcwd_long_pathnames.<locals>._create_and_do_getcwd)	rCrrf�abspathrrr#re�rmtree)rr%rQ�	base_pathr)r&r�test_getcwd_long_pathnames�s

z&PosixTester.test_getcwd_long_pathnames�getgrouplistztest needs posix.getgrouplist()rEztest needs pwd.getpwuid()r$ztest needs os.getuid()cCsRtjtj��d}tjtj��d}|j|tj||��dS)Nrr-)rDrErCr$r�rr+)r�user�grouprrr�test_getgrouplistszPosixTester.test_getgrouplistrztest needs os.getegid()cCstjd��%}|j�j�}|j�}WdQX|dk	sI|r[tjd��ntjdkr�ddl	}|j
d�p�d}tdd�|jd	�dd
�D��dkr�tjd
��q�n|j
tdd�|j�D��ttj�tj�g��dS)Nzid -G 2>/dev/nullzneed working 'id -G'�darwinr�MACOSX_DEPLOYMENT_TARGETz10.0css|]}t|�VqdS)N)r�)r�r�rrr�	<genexpr>)sz-PosixTester.test_getgroups.<locals>.<genexpr>r�r|r�r�z$getgroups(2) is broken prior to 10.6cSsg|]}t|��qSr)r�)r��xrrrr�1s	z.PosixTester.test_getgroups.<locals>.<listcomp>)r�r�)rC�popenr~�striprrHrIrbr��	sysconfig�get_config_var�tuplergr.�setrr r)rZidg�groupsZretr5Zdtrrr�test_getgroupss2zPosixTester.test_getgroupsz)test needs dir_fd support for os.access()cCsYtjtj�tj�}z)|jtjtjtj	d|��Wdtj
|�XdS)Nr�)rrrrdrPr�rrrCr�r)rr�rrr�test_access_dir_fd6s)zPosixTester.test_access_dir_fdz'test needs dir_fd support in os.chmod()cCs�tjtjtj�tjtj�tj	�}z^tjtjtjtj
Bd|�tjtj�}|j|dtj@tjtj
B�Wdtj
|�XdS)Nr�r)rC�chmodrrr�r�rrrrdr�r.�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)Nr�)
rrrr�rrrrdr�rCr$rr)rr�rrr�test_chown_dir_fdKs,zPosixTester.test_chown_dir_fdz&test needs dir_fd support in os.stat()cCs=tjtj�ttjd��}|jd�WdQXtjtj�tj�}z�tjtj�}tjtjd|�}|j	||�tjtjdd�}|j	||�|j
tdtjtjdtj��|j
tdtjtjdt|��|j
ttjtjdd�Wdtj|�XdS)Nr\z	testline
r�zshould be integer, notr��l F�x:^V)rrrrrXrrrdr�r.r�r)r�r(r�r)r�outfiler��s1�s2rrr�test_stat_dir_fdVs"	zPosixTester.test_stat_dir_fdz'test needs dir_fd support in os.utime()cCs4tjtj�tj�}ztj�}tjtjdd|�tjtjd|�|jt	tjtj|d|�|jt	tjtjdd|�|jt	tjtj|dfd|�|jt	tjtjd|fd|�|jt	tjtj|dfd|�tjtjt
|�t
|�fd|�tjtj||fd|�tjtjt
|�t
|t
|�d�fd|�tjtjd|dt
|�t
|t
|�d�f�tjtjkry tjtjddd|�Wqt
k
rYqXnWdtj|�XdS)Nr�r2ge��Arr�F)NN)rrrrdr�r�rrr(r)r�rC�supports_follow_symlinksr�r)rr�r�rrr�test_utime_dir_fdls,""(((+-' 
zPosixTester.test_utime_dir_fdz&test needs dir_fd support in os.link()c
Cs�tjtj�tj�}z^tjtjtjdd|d|�|jtjtj�dtjtjd�d�Wdtj	|�tj
tjd�XdS)N�link�
src_dir_fd�
dst_dir_fdr&)rrrrdrHrrr.r�rr)rr�rrr�test_link_dir_fd�s&
zPosixTester.test_link_dir_fdz'test needs dir_fd support in os.mkdir()cCsvtjtj�tj�}z2tjtjdd|�tjtjd�Wdtj|�tj	tjd�XdS)N�dirr�)
rrrrdr#rrr�rr()rr�rrr�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
�}z�y tjtj|dd|�WnDtk
r�}z$|j
|jtjtjf�WYdd}~Xn&X|jtjtjtj�j��Wdtj|�XdS)Nrr�)rrrr�r�r�r�rrrrdr�r:r�rJrKr�rPr�r�r)rr�r�rMrrr�test_mknod_dir_fd�s 2)zPosixTester.test_mknod_dir_fdz&test needs dir_fd support in os.open()cCs�tjtj�ttjd��}|jd�WdQXtjtj�tj�}tjtjtjd|�}z2tj|d�j	dd�}|j
d|�Wdtj|�tj|�XdS)Nr\z	testline
r��	�encodingzutf-8)rrrrrXrrrdr~�decoder.r)rrB�a�brorrr�test_open_dir_fd�s
zPosixTester.test_open_dir_fdz*test needs dir_fd support in os.readlink()cCs�tjtjtjd�tjtj�tj�}z:|jtj	tjd�tj	tjdd|��Wdtj
tjd�tj|�XdS)NrHr�)rCr�rrrrrrdr.�readlinkrr)rr�rrr�test_readlink_dir_fd�s!z PosixTester.test_readlink_dir_fdz(test needs dir_fd support in os.rename()cCs�tjtj�tjtjd�tjtj�tj�}zfy*tjtjdtjd|d|�Wn%tjtjdtj��YnXtj	tj�Wdtj
|�XdS)NZrenrIrJ)rrrr�rrrrd�renamer�r)rr�rrr�test_rename_dir_fd�s*zPosixTester.test_rename_dir_fdz)test needs dir_fd support in os.symlink()cCs�tjtj�tj�}zGtjtjtjdd|�|jtjtjd�tj�Wdtj	|�tj
tjd�XdS)NrHr�)rrrrdr�rrr.rUrr)rr�rrr�test_symlink_dir_fd�s '
zPosixTester.test_symlink_dir_fdz(test needs dir_fd support in os.unlink()cCs�tjtj�tj�}tjtjd�tjtjd�zaytjtjdd|�Wntjtjd��YnX|j	t
tjtjd�Wdtj|�XdS)N�delr�rH)rrrrdrr�rr�rr(r:r)rr�rrr�test_unlink_dir_fd�s!zPosixTester.test_unlink_dir_fdz(test needs dir_fd support in os.mkfifo()cCs�tjtj�tjtj�tj�}zLtjtjtj	tj
Bd|�|jtjtjtj�j
��Wdtj|�XdS)Nr�)rrrrrrrdr�r�r�r�rPr�r�r)rr�rrr�test_mkfifo_dir_fd�s#)zPosixTester.test_mkfifo_dir_fd�sched_yieldzdon't have scheduling support�sched_setaffinityz!don't have sched affinity supportcCstj�dS)N)rr])rrrr�test_sched_yieldszPosixTester.test_sched_yield�sched_get_priority_maxz!requires sched_get_priority_max()cCs�tj}tj|�}tj|�}|j|t�|j|t�|j||�tjdkr�|j	t
tjd�|j	t
tjd�ndS)Nr/r�i��i��)r�SCHED_RR�sched_get_priority_minr`r�r�r0rbr�r(r:)rZpol�lo�hirrr�test_sched_prioritys	zPosixTester.test_sched_priority�sched_setschedulerzcan't change schedulerc"Cs^dd�tjj�D�}tjd�}|j||�ytjtj��}Wn=tk
r�}z|jtj	kr��nWYdd}~XnX|j||�|j
ttjd
�|j
ttjd�tjd�}|j|j
t�tjjd�s�y'tjd||�tjd|�Wn=tk
rj}z|jtj	krX�nWYdd}~XnX|j
ttjd
|�n|j
ttjd||�|j
ttjd|d�|j
ttjdd�tjd�}|j
ttjd|�d}tj|�}|j
ttjd|�tjd	|�}|j
ttjd|�dS)NcSs+g|]!\}}|jd�r|�qS)ZSCHED_)r�)r�r*Zschedrrrr�s		zDPosixTester.test_get_and_set_scheduler_and_param.<locals>.<listcomp>rr&�freebsd�netbsd�+l����sched_priorityr6r6)rgrhr6r6)r�__dict__r�sched_getschedulerr�rCr#r:rJrKr(�sched_getparamr�rjr�rbr�r�rf�sched_setparamr)�sched_paramr�)rZpossible_schedulersZmine�parentrMZparamZlargerrr�$test_get_and_set_scheduler_and_params>z0PosixTester.test_get_and_set_scheduler_and_param�sched_rr_get_intervalzno functioncCs�ytjd�}WnJtk
r_}z*|jtjkr@�n|jd�WYdd}~XnX|j|t�|j|d�|j	|d�dS)Nrz only works on SCHED_RR processesgg�?)
rrrr:rJr�rr�r�r0�
assertLess)rZintervalrMrrr�test_sched_rr_get_intervalAs z&PosixTester.test_sched_rr_get_intervalcCs�tjd�}|j|t�|jt|�d�|jttjd�x>|D]6}|j|t�|j|d�|j	|d�qRWdS)Nrr&� r6l)
r�sched_getaffinityr�r8r0r/r(r:r�rs)r�maskZcpurrr�test_sched_getaffinityPs
z"PosixTester.test_sched_getaffinitycCs�tjd�}t|�dkr.|j�ntjd|�|jtjd�|�|jttjdg�|jttjddg�|jt	tjddg�|jttjd|�dS)Nrr&r��i����l	r6)
rrvr/�popr^r.r(r:r�r�)rrwrrr�test_sched_setaffinity[s
z"PosixTester.test_sched_setaffinitycCs tjtjtjtjdS)N)r�	RTLD_LAZY�RTLD_NOW�RTLD_GLOBAL�
RTLD_LOCAL)rrrr�test_rtld_constantshszPosixTester.test_rtld_constantsz-running kernel may not match kernel in chroot�	SEEK_HOLEz(test needs an OS that reports file holescCsttjd���}|jd�|j�|j�}|j�}y�xXt|�D]J}|j|t	j
||t	j��|j|t	j
||t	j
��qTW|jtt	j
||t	j�|jtt	j
||t	j
�Wn!tk
rtjd��YnXWdQXdS)Nzr+bshellozOSError raised!)rrrrXrY�tellrT�ranger.rCru�	SEEK_DATAZassertLessEqualr�r(r:rHrI)rrr�Zfnor�rrr�
test_fs_holesos


"&#
zPosixTester.test_fs_holescCs�x�d	D]�}tt|d�}|dkr1qnx�dtjfD]_}y|d|�WqAtk
r�}z%|jdj|�t|��PWYdd}~XqAXqAW|jd|�qWdS)
zf
        Test functions that call path_error2(), providing two filenames in their exceptions.
        rW�replacerHNZnoodly2Zdoesnotexistfilenamez'doesnotexistfilename' -> '{}'z#No valid path_error2() test for os.)zrenamezreplacezlink)	r'rCrrr:r��formatr�rL)rr*ZfunctionZdstrMrrr�test_path_error2�s
zPosixTester.test_path_error2cCstj}|d}|jtj|�tj|�d}z6|jt��!tj|tjtj	B�}WdQXWd|dk	r�tj
|�nX|jtjj
|��|jttj|�|jtjj
|��t|d�j
�|jttj|�dS)N��wb)rrr�rr(r)rCrrsrtrrrf�existsr#r�)rr�fn_with_NULryrrr�test_path_with_null_character�s	

&z)PosixTester.test_path_with_null_charactercCs
tjtj�}|d}|jtj|�tj|�d}z6|jt��!tj|tj	tj
B�}WdQXWd|dk	r�tj|�nX|jtj
j|��|jttj|�|jtj
j|��t|d�j�|jttj|�dS)Nsr�)rCr�rrr�rr(r�rrsrtrrrfr�r#r�)rrr�ryrrr�test_path_with_null_byte�s

&z$PosixTester.test_path_with_null_byte)w�__name__�
__module__�__qualname__rrr+rH�
skipUnlessr�rr2r4r9r;r>r?rNrRrUrZr]r'rC�supports_fdrjrprzrr�r�r�r�r�rFr�r�r�r�r�r�rZrequires_linux_versionr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrZcpython_onlyr
rrrrrr"r*rDr.r:r��supports_dir_fdr;r<r?r�r@rErGrHrKr#rMr�rNrrTrUrVrWrXr�rYrr[r�r\Zrequires_sched_hZrequires_sched_affinityr_rerqrtrxr{r�Z_skipInRpmBuildr�r�r�r�rrrrrs�
	'$-
*
'''
**''

$
'!*;''
'''''$''
'''!	'$-'**
*****
$****
**
		')'
rc@sveZdZdd�Zdd�Zejeed�d�dd��Z	ejeed	�d
�dd��Z
d
S)�PosixGroupsTestercCsytj�dkr$tjd��nttd�sEtjd��ntjdkrftjd��ntj�|_dS)Nrznot enough privilegesr zneed posix.getgroupsr/zgetgroups(2) is broken on OSX)	rr$rHrIr�rbr�r �saved_groups)rrrrr�szPosixGroupsTester.setUpcCsgttd�r"tj|j�nAttd�rctjtj��j}tj||jd�ndS)N�	setgroupsr@r)	r�rr�r�rDrEr$rFr@)rr*rrrr�s
zPosixGroupsTester.tearDownr@ztest needs posix.initgroups()cCs^t|jpdg�d}tjtj��j}tj||�|j|tj	��dS)Nrr&)
�maxr�rDrErr$rFr@r�r )r�gr*rrrrN�sz!PosixGroupsTester.test_initgroupsr�ztest needs posix.setgroups()cCsMxFdgttd��gD])}tj|�|j|tj��qWdS)Nr�)r�r�rr�ZassertListEqualr )rr9rrr�test_setgroups�s"
z PosixGroupsTester.test_setgroupsN)r�r�r�rrrHr�r�rrNr�rrrrr��s		r�c
Cs&ztjtt�Wdtj�XdS)N)rZrun_unittestrr�Z
reap_childrenrrrr�	test_main�sr��__main__)�__doc__rWr�
import_modulerrJrbr�rCr�r�rDZshutilr�ZtempfilerHrrf�joinZ
gettempdirrr�ZTestCaserr�r�r�rrrr�<module>s2�����#