Your IP : 18.118.10.75


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

3

��JZ�%�@s<dZddlZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZdd	lmZdd
lm
Z
ddlmZddlmZer�ejd
�ndZdd�Zdd�Zdd�Zejed�Gdd�dej��Zejed�Gdd�dej��Zejed�Gdd�dej��Zedk�r8e
e�dS)zOSX specific tests.�N)�OSX)�create_zombie_proc)�get_test_subprocess)�HAS_BATTERY)�MEMORY_TOLERANCE)�
reap_children)�retry_before_failing)�run_test_module_by_name)�sh)�unittest�SC_PAGE_SIZEcCs6t|�}|j�d}yt|�Stk
r0|SXdS)zmExpects a sysctl command with an argument and parse the result
    returning only the value of interest.
    �N)r
�split�int�
ValueError)�cmdline�out�result�r� /usr/lib64/python3.6/test_osx.py�sysctlsrcCsHtd�}x$|jd�D]}||krPqWtd��ttjd|�jd��tS)z)Wrapper around 'vm_stat' cmdline utility.�vm_stat�
zline not foundz\d+r)r
rrr�re�search�group�PAGESIZE)Zfieldr�linerrrr(src	
Cs�ddi}|}d}x@|r&|dd
�j�s6|dd
�dkrP||d7}|d
d�}qWt|�}|j�}xD|j�D]\}}||krlPqlW|dkr�|d}|j�}ntd|��|dd
i}x0t|d
d��D]\}}d
|d
d>||<q�Wt|||�S)NZ	customary�B�K�M�G�T�P�E�Z�Y�rr
�.�kzcan't interpret %r�
)	rrr r!r"r#r$r%r&)�isdigit�float�strip�items�upperr�	enumerater)	�sZSYMBOLSZinit�numZletter�nameZsset�prefix�irrr�human2bytes4s&&
r6zOSX onlyc@s,eZdZedd��Zedd��Zdd�ZdS)�TestProcesscCst�j|_dS)N)r�pid)�clsrrr�
setUpClassQszTestProcess.setUpClasscCs
t�dS)N)r)r9rrr�
tearDownClassUszTestProcess.tearDownClasscCs�td|j�}|jdd�j�}|jd�d	}|jd�d
}tj|j�j�}|j|t	j
dt	j|���|j|t	j
dt	j|���dS)Nzps -o lstart -p %sZSTARTEDr'� �r
z%H:%M:%Sz%Y������)r
r8�replacer-r�psutil�Process�create_time�assertEqual�timeZstrftimeZ	localtime)�self�outputZstart_psZhhmmssZyearZstart_psutilrrr�test_process_create_timeYsz$TestProcess.test_process_create_timeN)�__name__�
__module__�__qualname__�classmethodr:r;rHrrrrr7Nsr7c@s�eZdZedd��Zedd��Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!S)"�TestZombieProcessAPIscCst�}tj|�|_dS)N)rrArB�p)r9Zzpidrrrr:jsz TestZombieProcessAPIs.setUpClasscCstdd�dS)NT)�	recursive)r)r9rrrr;osz#TestZombieProcessAPIs.tearDownClasscCsJ|j|jj�tj�|jj�|jj�|jj�|jj�|jj	�dS)N)
rDrNZstatusrAZ
STATUS_ZOMBIEZppidZuidsZgidsZterminalrC)rFrrr�test_pidtask_infoss



z'TestZombieProcessAPIs.test_pidtask_infocCs|jtj|jj�dS)N)�assertRaisesrA�
ZombieProcessrNZexe)rFrrr�test_exe{szTestZombieProcessAPIs.test_execCs|jtj|jj�dS)N)rQrArRrNr)rFrrr�test_cmdline~sz"TestZombieProcessAPIs.test_cmdlinecCs|jtj|jj�dS)N)rQrArRrN�environ)rFrrr�test_environ�sz"TestZombieProcessAPIs.test_environcCs|jtj|jj�dS)N)rQrArRrN�cwd)rFrrr�test_cwd�szTestZombieProcessAPIs.test_cwdcCs|jtj|jj�dS)N)rQrArRrNZmemory_full_info)rFrrr�test_memory_full_info�sz+TestZombieProcessAPIs.test_memory_full_infocCs|jtj|jj�dS)N)rQrArRrNZ	cpu_times)rFrrr�test_cpu_times�sz$TestZombieProcessAPIs.test_cpu_timescCs|jtj|jj�dS)N)rQrArRrNZnum_ctx_switches)rFrrr�test_num_ctx_switches�sz+TestZombieProcessAPIs.test_num_ctx_switchescCs|jtj|jj�dS)N)rQrArRrNZnum_threads)rFrrr�test_num_threads�sz&TestZombieProcessAPIs.test_num_threadscCs|jtj|jj�dS)N)rQrArRrNZ
open_files)rFrrr�test_open_files�sz%TestZombieProcessAPIs.test_open_filescCs|jtj|jj�dS)N)rQrArRrNZconnections)rFrrr�test_connections�sz&TestZombieProcessAPIs.test_connectionscCs|jtj|jj�dS)N)rQrArRrNZnum_fds)rFrrr�test_num_fds�sz"TestZombieProcessAPIs.test_num_fdscCs|jtjtjf|jj�dS)N)rQrArRZAccessDeniedrNZthreads)rFrrr�test_threads�sz"TestZombieProcessAPIs.test_threadscCs|jtj|jj�dS)N)rQrArRrNZmemory_maps)rFrrr�test_memory_maps�sz&TestZombieProcessAPIs.test_memory_mapsN)rIrJrKrLr:r;rPrSrTrVrXrYrZr[r\r]r^r_r`rarrrrrMgs rMc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�dd��Z	e�d
d��Z
e�dd��Ze�dd��Ze�dd��Z
e�dd��Ze�dd��Zdd�Zejed�dd��ZdS)�TestSystemAPIscCs�dd�}x�tjdd�D]�}tj|j�}||j�\}}}}|j|j|�|j|j|�t|j|�d	krx|j	d|j|�t|j
|�dkr|j	d|j
|�qWdS)NcSs�td|�j�}|jd�}|jd�|jd�}|j�dd�\}}}}|dkrRd}t|�d}t|�d}t|�d}||||fS)Nz
df -k "%s"rr�Znoner'i)r
r-r�popr)�pathr�linesr�dev�total�used�freerrr�df�s


z%TestSystemAPIs.test_disks.<locals>.dfF)�allr*izpsutil=%s, df=%si(i�i(i�)rAZdisk_partitionsZ
disk_usageZ
mountpointrDZdevicerh�absrjZfailri)rFrk�partZusagergrhrirjrrr�
test_disks�s
zTestSystemAPIs.test_diskscCs td�}|j|tjdd��dS)Nzsysctl hw.logicalcpuT)�logical)rrDrA�	cpu_count)rFr2rrr�test_cpu_count_logical�sz%TestSystemAPIs.test_cpu_count_logicalcCs td�}|j|tjdd��dS)Nzsysctl hw.physicalcpuF)rp)rrDrArq)rFr2rrr�test_cpu_count_physical�sz&TestSystemAPIs.test_cpu_count_physicalcCsZtj�}|j|jddtd��|j|jddtd��|j|jddtd��dS)Ni�zsysctl hw.cpufrequencyzsysctl hw.cpufrequency_minzsysctl hw.cpufrequency_max)rAZcpu_freqrDZcurrentr�min�max)rFZfreqrrr�
test_cpu_freq�szTestSystemAPIs.test_cpu_freqcCstd�}|j|tj�j�dS)Nzsysctl hw.memsize)rrDrA�virtual_memoryrh)rFZsysctl_hwphymemrrr�test_vmem_total�szTestSystemAPIs.test_vmem_totalcCs&td�}tj�j}|j||td�dS)Nrj)�delta)rrArwrj�assertAlmostEqualr)rF�
vmstat_val�
psutil_valrrr�test_vmem_free�s
zTestSystemAPIs.test_vmem_freecCs.td�td�}tj�j}|j||td�dS)N�inactiverj)ry)rrArwZ	availablerzr)rFr{r|rrr�test_vmem_available�s
z"TestSystemAPIs.test_vmem_availablecCs&td�}tj�j}|j||td�dS)N�active)ry)rrArwr�rzr)rFr{r|rrr�test_vmem_active�s
zTestSystemAPIs.test_vmem_activecCs&td�}tj�j}|j||td�dS)Nr~)ry)rrArwr~rzr)rFr{r|rrr�test_vmem_inactive�s
z!TestSystemAPIs.test_vmem_inactivecCs&td�}tj�j}|j||td�dS)N�wired)ry)rrArwr�rzr)rFr{r|rrr�test_vmem_wired�s
zTestSystemAPIs.test_vmem_wiredcCs"td�}tj�j}|j||�dS)NZPageins)rrA�swap_memoryZsinrD)rFr{r|rrr�test_swapmem_sin�s
zTestSystemAPIs.test_swapmem_sincCs"td�}tj�j}|j||�dS)NZPageout)rrAr�ZsoutrD)rFr{r|rrr�test_swapmem_souts
z TestSystemAPIs.test_swapmem_soutcCsxxrtj�j�D]b\}}ytd|�}Wntk
r:YqX|j|jd|k|d�|j|jtt	j
d|�d��qWdS)Nzifconfig %sZRUNNING)�msgz	mtu (\d+)r)rAZnet_if_statsr.r
�RuntimeErrorrDZisupZmturr�findall)rFr3Zstatsrrrr�test_net_if_statssz TestSystemAPIs.test_net_if_statsz
no batterycCs`td�}tjd|�jd�}tjd|�jd�}|dk}tj�}|j|j|�|j|jt	|��dS)Nz
pmset -g battz(\d+)%r
zNow drawing from '([^']+)'zAC Power)
r
rrrrAZsensors_batteryrD�
power_plugged�percentr)rFrr�Zdrawing_fromr�Z
psutil_resultrrr�test_sensors_battery"sz#TestSystemAPIs.test_sensors_batteryN)rIrJrKrorrrsrvrxrr}rr�r�r�r�r�r�r�skipIfrr�rrrrrb�s
rb�__main__)�__doc__�osrrErArZpsutil.testsrrrrrrr	r
r�sysconfrrrr6r�ZTestCaser7rMrbrI�__file__rrrr�<module>s6

<
	


?>