Your IP : 18.191.171.72


Current Path : /lib64/python3.6/site-packages/psutil/tests/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/psutil/tests/__pycache__/test_posix.cpython-36.pyc

3

��JZ�?�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddlm
Z
ddlmZddlmZddlm
Z
ddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!dd�Z"dd�Z#dd�Z$ej%ed �Gd!d"�d"ej&��Z'ej%ed �Gd#d$�d$ej&��Z(e)d%k�r�ee*�dS)&zPOSIX specific tests.�N)�AIX)�BSD)�LINUX)�OPENBSD)�OSX)�POSIX)�SUNOS)�callable)�PY3)�APPVEYOR)�get_kernel_version)�get_test_subprocess)�mock)�
PYTHON_EXE)�
reap_children)�retry_before_failing)�run_test_module_by_name)�sh)�skip_on_access_denied)�TRAVIS)�unittest)�wait_for_pid)�whichcCspts|jdd�}tr |jdd�}tr0|jdd�}t|�}tsN|jd�dj�}yt|�Stk
rj|SXd	S)
zkExpects a ps command with a -o argument and parse the result
    returning only the value of interest.
    z --no-headers � z-o startz-o stimez-o rssz	-o rssize�
�N)	r�replacerrr�split�strip�int�
ValueError)�cmd�output�r#�"/usr/lib64/python3.6/test_posix.py�ps+sr%cCs&d}trd}td||f�jd�dS)N�commandZcommzps --no-headers -o %s -p %srr)rr%r)�pid�fieldr#r#r$�ps_nameIsr)cCs d}tstrd}td||f�S)Nr&�argszps --no-headers -o %s -p %s)rrr%)r'r(r#r#r$�ps_argsPsr+z
POSIX onlyc@s�eZdZdZedd��Zedd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Ze�e
�dd���Ze�e
�dd���Zdd�Zdd�Zdd�Zdd�Zejep�ed�dd��Zdd �Zd!d"�Zejed#�ejed$�d%d&���Zd'd(�Zd)S)*�TestProcesszBCompare psutil results against 'ps' command line utility (mainly).cCs&ttddgtjd�j|_t|j�dS)Nz-Ez-O)�stdin)r
r�
subprocess�PIPEr'r)�clsr#r#r$�
setUpClass[s
zTestProcess.setUpClasscCs
t�dS)N)r)r0r#r#r$�
tearDownClassaszTestProcess.tearDownClasscCs.td|j�}tj|j�j�}|j||�dS)Nzps --no-headers -o ppid -p %s)r%r'�psutil�ProcessZppid�assertEqual)�selfZppid_psZppid_psutilr#r#r$�	test_ppideszTestProcess.test_ppidcCs0td|j�}tj|j�j�j}|j||�dS)Nzps --no-headers -o uid -p %s)r%r'r3r4�uids�realr5)r6Zuid_psZ
uid_psutilr#r#r$�test_uidjszTestProcess.test_uidcCs0td|j�}tj|j�j�j}|j||�dS)Nzps --no-headers -o rgid -p %s)r%r'r3r4Zgidsr9r5)r6Zgid_psZ
gid_psutilr#r#r$�test_gidoszTestProcess.test_gidcCs.td|j�}tj|j�j�}|j||�dS)Nzps --no-headers -o user -p %s)r%r'r3r4�usernamer5)r6Zusername_psZusername_psutilr#r#r$�
test_usernametszTestProcess.test_usernamecCsJtj�}tjdtd��*}|j|j�t|j�j	��|j
s<t�WdQRXdS)Nzpsutil.pwd.getpwuid)�side_effect)r3r4r�patch�KeyErrorr5r<�strr8r9�called�AssertionError)r6�pZfunr#r#r$�test_username_no_resolutionysz'TestProcess.test_username_no_resolutioncCs@tjd�td|j�}tj|j�j�dd}|j||�dS)Ng�������?zps --no-headers -o rss -p %sri)�time�sleepr%r'r3r4�memory_infor5)r6Zrss_psZ
rss_psutilr#r#r$�test_rss_memory�s
zTestProcess.test_rss_memorycCs@tjd�td|j�}tj|j�j�dd}|j||�dS)Ng�������?zps --no-headers -o vsz -p %sri)rFrGr%r'r3r4rHr5)r6Zvsz_psZ
vsz_psutilr#r#r$�test_vsz_memory�s
zTestProcess.test_vsz_memorycCsZt|j�}tjj|�j�}tj|j�j�j�}t	j
dd|�}t	j
dd|�}|j||�dS)Nz\d.\d�)r)r'�os�path�basename�lowerr3r4�name�re�subr5)r6Zname_psZname_psutilr#r#r$�	test_name�s
zTestProcess.test_namecCs^d}dddg}tjd|d��8tjd|d��tj�}|j|j�d�WdQRXWdQRXdS)Nzlong-program-namezlong-program-name-extendedZfooZbarzpsutil._psplatform.Process.name)�return_valuez"psutil._psplatform.Process.cmdline)rr?r3r4r5rP)r6rP�cmdlinerDr#r#r$�test_name_long�s


zTestProcess.test_name_longcCs\d}tjd|d��@tjdtjdd�d��tj�}|j|j�d�WdQRXWdQRXdS)Nzlong-program-namezpsutil._psplatform.Process.name)rTz"psutil._psplatform.Process.cmdlinerrK)r>)rr?r3�AccessDeniedr4r5rP)r6rPrDr#r#r$�test_name_long_cmdline_ad_exc�s
z)TestProcess.test_name_long_cmdline_ad_exccCs\d}tjd|d��@tjdtjdd�d��tj�}|jtj|j�WdQRXWdQRXdS)Nzlong-program-namezpsutil._psplatform.Process.name)rTz"psutil._psplatform.Process.cmdlinerrK)r>)rr?r3Z
NoSuchProcessr4�assertRaisesrP)r6rPrDr#r#r$�test_name_long_cmdline_nsp_exc�s
z*TestProcess.test_name_long_cmdline_nsp_exczps -o start not availablecCshtd|j�jd�d}tj|j�j�}tjj|�jd�}t	|�}tjj|�jd�}|j
|||g�dS)Nzps --no-headers -o start -p %srrz%H:%M:%S)r%r'rr3r4Zcreate_time�datetimeZ
fromtimestampZstrftime�round�assertIn)r6Ztime_psZtime_psutilZtime_psutil_tstampZround_time_psutilZround_time_psutil_tstampr#r#r$�test_create_time�szTestProcess.test_create_timecCs`t|j�}tj|j�j�}y|j||�Wn0tk
rZ|dt|��}|j||�YnXdS)N)r)r'r3r4Zexer5rC�len)r6Zps_pathnameZpsutil_pathnameZadjusted_ps_pathnamer#r#r$�test_exe�s
zTestProcess.test_execCs0t|j�}djtj|j�j��}|j||�dS)Nr)r+r'�joinr3r4rUr5)r6Z
ps_cmdlineZpsutil_cmdliner#r#r$�test_cmdline�s
zTestProcess.test_cmdlineznot reliable on SUNOSznot reliable on AIXcCs*td|j�}tj�j�}|j||�dS)Nzps --no-headers -o nice -p %s)r%r'r3r4�nicer5)r6Zps_niceZpsutil_nicer#r#r$�	test_nice�szTestProcess.test_nicec	
s�fdd�}tjtj��}g}ddddddd	d
ddg
}trNt�dkrN|jd�trft�dkrf|jd�x�ttj�D]���jd�sr�|kr�qrqry0|j	�}xt
d
�D]}||��q�W|j	�}Wntjk
r�YqrXt||�dkrrd�||f}|j|�qrW|�r|j
ddj|��dS)NcsBf}t|�d�}|dk	r:t|�r:�dkr0tjf}||�n|dS)N�rlimit)�getattrr	r3Z
RLIMIT_NOFILE)rD�attrr*)rPr#r$�call�s
z&TestProcess.test_num_fds.<locals>.callZ	terminate�killZsuspendZresumercZsend_signal�waitZchildrenZas_dictZmemory_info_ex���$re�Znum_ctx_switches�_rz@failure while processing Process.%s method (before=%s, after=%s)r)rkrlrm)rkrlrn)r3r4rL�getpidrr�append�dir�
startswithZnum_fds�rangerW�abs�failra)	r6rhrDZfailuresZ
ignored_namesZnum1�xZnum2rvr#)rPr$�test_num_fds�s4



zTestProcess.test_num_fdsN)�__name__�
__module__�__qualname__�__doc__�classmethodr1r2r7r:r;r=rErrrIrJrSrVrXrZr�skipIfrrr^r`rbrrrdrxr#r#r#r$r,Ws,			



r,c@s�eZdZdZe�dd��Zejed�eje	d�eje
d�d�dd	����Zejep`e	o`e
j�d
�e�dd���Zd
d�Zdd�Zdd�Zdd�Zejed�dd��ZdS)�TestSystemAPIszTest some system APIs.cCs�tstrddddg}nddddg}t|tjd�}|j�dj�}|j�dksPt�t	rbt
|tjj
�}g}x<|jd�d	d�D]&}|rzt|j�dj��}|j|�qzW|j|j�tj�}|j�|j�ts�tr�d|kr�|jdd�|j||�dS)
Nr%z-Az-or'Zax)�stdoutrrr)rrr
r.r/ZcommunicaterZpollrCr
rA�sysr��encodingrrrq�remover'r3Zpids�sortrr�insertr5)r6r!rDr"Zpids_ps�liner'Zpids_psutilr#r#r$�	test_pids s(zTestSystemAPIs.test_pidszunreliable on SUNOSzunreliable on TRAVISZifconfigzno ifconfig cmdcCsVtd�}xHtjdd�j�D]4}x.|j�D]}|j|�r(Pq(W|jd||f�qWdS)Nzifconfig -aT)Zpernicz/couldn't find %s nic in 'ifconfig -a' output
%s)rr3Znet_io_counters�keysrrsrv)r6r"Znicr�r#r#r$�test_nic_names?s
zTestSystemAPIs.test_nic_namesz unreliable on APPVEYOR or TRAVIScCsxtd�}|jd�}dd�|D�}dd�|D�}|jt|�ttj���x,tj�D] }|j|j|�|j|j|�qPWdS)NZwhorcSsg|]}|j�d�qS)r)r)�.0rwr#r#r$�
<listcomp>Tsz-TestSystemAPIs.test_users.<locals>.<listcomp>cSsg|]}|j�d�qS)r)r)r�rwr#r#r$r�Us)	rrr5r_r3�usersr]rPZterminal)r6�out�linesr�Z	terminals�ur#r#r$�
test_usersNs
zTestSystemAPIs.test_userscCsFtjdttjd�d��&}|jttjjt	j
��|js8t�WdQRXdS)Nzpsutil._psposix.os.killrK)r>)
rr?�OSError�errno�EBADFrYr3�_psposixZ
pid_existsrLrprBrC)r6�mr#r#r$�test_pid_exists_let_raise[sz(TestSystemAPIs.test_pid_exists_let_raisecCsFtjdttjd�d��&}|jttjjt	j
��|js8t�WdQRXdS)Nzpsutil._psposix.os.waitpidrK)r>)
rr?r�r�r�rYr3r��wait_pidrLrprBrC)r6r�r#r#r$�test_os_waitpid_let_raisedsz(TestSystemAPIs.test_os_waitpid_let_raisec
CsNtjdttjd�d��.}|jtjjtjj	t
j�dd�|js@t
�WdQRXdS)Nzpsutil._psposix.os.waitpidrK)r>g{�G�z�?)Ztimeout)rr?r�r�ZEINTRrYr3r�ZTimeoutExpiredr�rLrprBrC)r6r�r#r#r$�test_os_waitpid_eintrlsz$TestSystemAPIs.test_os_waitpid_eintrcCs>tjddd��&}|jttjjtj��|j	s0t
�WdQRXdS)Nzpsutil._psposix.os.waitpidr)rT���)rr�)rr?rYr r3r�r�rLrprBrC)r6r�r#r#r$�test_os_waitpid_bad_ret_statusus

z-TestSystemAPIs.test_os_waitpid_bad_ret_statuszunreliable on AIXc
Cs�dd�}d
}x�tjdd�D]�}tj|j�}y||j�\}}}}WnLtk
r�}	z0t|	�j�}	d|	ksvd|	ksvd	|	krzwn�WYdd}	~	XqX|j|j	||d
�|j|j
||d
�|j|j||d
�|j|j|dd
�qWdS)NcSsvtd|�j�}|jd�d}|j�}t|d�d}t|d�d}t|d�d}t|djdd	��}||||fS)
Nzdf -k %srrirk���%rK)rrrr�floatr)�devicer�r�Zfields�total�used�free�percentr#r#r$�df�sz*TestSystemAPIs.test_disk_usage.<locals>.dfr�iF)�allzno such file or directoryzraw devices not supportedzpermission denied)Zdeltarii@)
r3Zdisk_partitionsZ
disk_usageZ
mountpointr��RuntimeErrorrArOZassertAlmostEqualr�r�r�r�)
r6r�Z	tolerance�partZusager�r�r�r��errr#r#r$�test_disk_usage~s"
zTestSystemAPIs.test_disk_usageN)ryrzr{r|rr�rr~rrrr�rr3r�r�r�r�r�r�rr�r#r#r#r$rs


			r�__main__)+r|r[r�rLrQr.r�rFr3rrrrrrrZpsutil._compatr	r
Zpsutil.testsrrr
rrrrrrrrrrrr%r)r+r~ZTestCaser,rry�__file__r#r#r#r$�<module>sT
E



?>