[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@3.149.241.62: ~ $
U

�=�_�^�@sdZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&ddlm'Z'ddlm(Z(ddlm)Z)ddlm*Z*ej+�,ej+�-e.��Z/dZ0dZ1dZ2dZ3d Z4e�r�d!Z5e�d"�Z6d#d$�Z7d%d&�Z8d'd(�Z9d)d*�Z:d+d,�Z;d-d.�Z<d/d0�Z=d1d2�Z>d3d4�Z?ej@d5d6��ZAej@d7d8��ZBe)�Ced9�Gd:d;�d;e��ZDe)�Ced9�Gd<d=�d=e��ZEe)�Ced9�Gd>d?�d?e��ZFe)�Ced9�Gd@dA�dAe��ZGe)�Ced9�GdBdC�dCe��ZHe)�Ced9�GdDdE�dEe��ZIe)�Ced9�GdFdG�dGe��ZJe)�Ced9�GdHdI�dIe��ZKe)�Ced9�GdJdK�dKe��ZLe)�Ced9�GdLdM�dMe��ZMe)�Ced9�GdNdO�dOe��ZNe)�Ced9�GdPdQ�dQe��ZOe)�Ced9�GdRdS�dSe��ZPe)�Ced9�GdTdU�dUe��ZQe)�Ced9�GdVdW�dWe��ZRe)�Ced9�e)�CedX�GdYdZ�dZe���ZSe)�Ced9�Gd[d\�d\e��ZTe)�Ced9�Gd]d^�d^e��ZUe)�Ced9�Gd_d`�d`e��ZVe)�Ced9�Gdadb�dbe��ZWe)�Ced9�Gdcdd�dde��ZXe)�Ced9�Gdedf�dfe��ZYeZdgk�rddhl[m\Z\e\e.�dS)izLinux specific tests.�)�divisionN)�LINUX)�
basestring)�FileNotFoundError)�PY3)�u)�
call_until)�GLOBAL_TIMEOUT)�HAS_BATTERY)�HAS_CPU_FREQ)�HAS_GETLOADAVG)�
HAS_RLIMIT)�mock)�PsutilTestCase)�PYPY)�
reload_module)�retry_on_failure)�safe_rmpath)�sh)�skip_on_not_implemented)�
ThreadTask)�TOLERANCE_DISK_USAGE)�TOLERANCE_SYS_MEM)�unittest)�whichi�i�i'�i�i�iz/sys/class/hwmon/hwmon*cCs|ddl}|dd�}tr"t|d�}t�tjtj�}t�|��6t�|�	|�
�tt�
d|��dd��W5QR�SQRXdS�Nr��ascii�256s��)�fcntlr�bytes�socket�AF_INET�
SOCK_DGRAM�
contextlib�closing�	inet_ntoa�ioctl�fileno�SIOCGIFADDR�struct�pack��ifnamer!�s�r1�J/opt/alt/python38/lib64/python3.8/site-packages/psutil/tests/test_linux.py�get_ipv4_addressBs


���r3cCs|ddl}|dd�}tr"t|d�}t�tjtj�}t�|��6t�|�	|�
�tt�
d|��dd��W5QR�SQRXdSr)r!rr"r#r$r%r&r'r(r)r*�SIOCGIFNETMASKr,r-r.r1r1r2�get_ipv4_netmaskOs


���r5cCs|ddl}|dd�}tr"t|d�}t�tjtj�}t�|��6t�|�	|�
�tt�
d|��dd��W5QR�SQRXdSr)r!rr"r#r$r%r&r'r(r)r*�SIOCGIFBRDADDRr,r-r.r1r1r2�get_ipv4_broadcast\s


���r7c		Cs�tdd��8}|��D]}|��}|d|krq>qtd|��W5QRX|d}g}tdt|�d�D]}|�|||d��qdd�|�}t�	tj
|�}t�tj
|�S)Nz/proc/net/if_inet6�rt���zcould not find interface %rr��:)�open�	readlines�split�
ValueError�range�len�append�joinr#Z	inet_pton�AF_INET6�	inet_ntop)	r/�f�line�fieldsZunformatted�groups�iZ	formattedZpackedr1r1r2�get_ipv6_addressis
rKc
s�ddl}|dd�}tr"t|d�}t�tjtj�}t�|��l|�|�	�t
t�d|��}trfdd��nddl
}|j�d��fdd	�|d
d�D��dd�W5QR�SQRXdS)
NrrrrcSs|S�Nr1��xr1r1r2�ord�szget_mac_address.<locals>.ord�csg|]}d�|��qS)z%02x:r1)�.0�char�rOr1r2�
<listcomp>�sz#get_mac_address.<locals>.<listcomp>�r r9)r!rr"r#r$r%r&r'r)r*�
SIOCGIFHWADDRr,r-�__builtin__rOrC)r/r!r0�inforWr1rSr2�get_mac_addresszs 

�
rYcCs|tdddid�}|�d�}|D]F}|�d�r|��\}}}}t�dd�}|t|�t|�t|��Sqtd	d�|���d
S)zQParse 'free' cmd and return swap memory's s total, used and free
    values.
    �free -b�LANG�C.UTF-8��env�
ZSwap�freeztotal used freez&can't find 'Swap' in 'free' output:
%sN)rr>�
startswith�collections�
namedtuple�intr?rC)�out�linesrG�_�total�usedr`�ntr1r1r2�	free_swap�s

�rkcCs�tdddid�}|�d�}|D]P}|�d�rdd�|��d	d
�D�\}}}}t�dd�}||||||�Sqtd
d�|���dS)zSParse 'free' cmd and return physical memory's total, used
    and free values.
    rZr[r\r]r_ZMemcSsg|]}t|��qSr1)rd�rQrNr1r1r2rT�sz free_physmem.<locals>.<listcomp>��r`ztotal used free shared outputz%can't find 'Mem' in 'free' output:
%sN)rr>rarbrcr?rC)rerfrGrhrir`�sharedrjr1r1r2�free_physmem�s

�
��rpcCsVtdddid�}|�d�D]*}|��}||krt|�d�d�Sqtd|��dS)	Nz	vmstat -sr[r\r]r_� rz can't find %r in 'vmstat' output)rr>�striprdr?)�statrerGr1r1r2�vmstat�srtcCs:td���}d|krt�d��ttt|��d�d���S)Nzfree -VZUNKNOWNzcan't determine free versionr9�.)rrrr�SkipTest�tuple�maprdr>)rer1r1r2�get_free_version_info�s
ryc	#sF���fdd�}t�trdnd}tj|d|d��}|VW5QRXdS)zMock open() builtin and forces it to return a certain `content`
    on read() if the path being opened matches `for_path`.
    csL|�kr8tr,t�t�r t���St���SqHt���Sn�|f|�|�SdSrL)r�
isinstancer�io�StringIO�BytesIO��name�args�kwargs��content�for_path�	orig_openr1r2�	open_mock�s

z$mock_open_content.<locals>.open_mock�
builtins.open�__builtin__.openT��create�side_effectN�r<rr�patch)r�r�r��patch_point�mr1r�r2�mock_open_content�s
r�c	#sF���fdd�}t�trdnd}tj|d|d��}|VW5QRXdS)zZMock open() builtin and raises `exc` if the path being opened
    matches `for_path`.
    cs"|�kr��n�|f|�|�SdSrLr1r~��excr�r�r1r2r��sz&mock_open_exception.<locals>.open_mockr�r�Tr�Nr�)r�r�r�r�r�r1r�r2�mock_open_exception�s
r�z
LINUX onlyc@s�eZdZdd�Ze�dd��Ze�dd��Ze�dd��Ze�d	d
��Ze�dd��Z	e�d
d��Z
e�dd��Zdd�Ze�dd��Z
dd�Zdd�Zdd�Zdd�ZdS)�TestSystemVirtualMemorycCs&td�d}t��j}|�||�dS)Nztotal memory�)rt�psutil�virtual_memoryrh�assertAlmostEqual��selfZvmstat_value�psutil_valuer1r1r2�
test_total�s
z"TestSystemVirtualMemory.test_totalcCsLt�dkr|�d��t�}|j}t��j}|j||td|||jfd�dS)N)�r��zold free version�	%s %s 
%s��delta�msg)	ryZskipTestrprir�r�r�r�output�r�r`�
free_valuer�r1r1r2�	test_used�s


�z!TestSystemVirtualMemory.test_usedcCs*td�d}t��j}|j||td�dS)Nzfree memoryr��r�)rtr�r�r`r�rr�r1r1r2�	test_frees
�z!TestSystemVirtualMemory.test_freecCs*td�d}t��j}|j||td�dS)Nz
buffer memoryr�r�)rtr�r��buffersr�rr�r1r1r2�test_bufferss
�z$TestSystemVirtualMemory.test_bufferscCs*td�d}t��j}|j||td�dS)Nz
active memoryr�r�)rtr�r��activer�rr�r1r1r2�test_actives
�z#TestSystemVirtualMemory.test_activecCs*td�d}t��j}|j||td�dS)Nzinactive memoryr�r�)rtr�r��inactiver�rr�r1r1r2�
test_inactives
�z%TestSystemVirtualMemory.test_inactivecCsJt�}|j}|dkrt�d��t��j}|j||td|||jfd�dS)Nrz%free does not support 'shared' columnr�r�)	rprorrvr�r�r�rr�r�r1r1r2�test_shared#s

�z#TestSystemVirtualMemory.test_sharedcCshtd�}|�d�}d|dkr*t�d��n:t|d��d�}t��j}|j||t	d|||fd	�dS)
NrZr_�	availablerz(free does not support 'available' columnrmr9r�r�)
rr>rrvrdr�r�r�r�r)r�rerfr�r�r1r1r2�test_available.s

�z&TestSystemVirtualMemory.test_availablec
Csdtdt�d������D}tjdd���*}t�d�t��}|j	sDt
�|�t|�d�|d}|j
�d�slt
�|�d	t|j��|�d
t|j��|�dt|j��|�dt|j��|�d
t|j��|�dt|j��|�dt|j��|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�W5QRXW5QRXdS)N�
/proc/meminfoap                Active(anon):    6145416 kB
                Active(file):    2950064 kB
                Inactive(anon):   574764 kB
                Inactive(file):  1567648 kB
                MemAvailable:         -1 kB
                MemFree:         2057400 kB
                MemTotal:       16325648 kB
                SReclaimable:     346648 kB
                T��record�alwaysrmr�psutil/_pslinux.pyz#memory stats couldn't be determined�cachedror�r�r�r�)r��textwrap�dedent�encode�warnings�catch_warnings�simplefilterr�r��called�AssertionError�assertEqualrA�filename�endswith�assertIn�str�messager�r�r�ror�r��slab�r�r��ws�ret�wr1r1r2�test_warnings_on_misses=s:�

�z/TestSystemVirtualMemory.test_warnings_on_missesc
	Cs�ddlm}ddlm}i}|d��0}|D]$}|��}t|d�d||d<q*W5QRX||�}d|kr�|d}t||�|d}	|�|	d	�dS)
Nr)�calculate_avail_vmem)�open_binaryr�rmr�s
MemAvailable:�dr)�psutil._pslinuxr�r�r>rd�absZ
assertLess)
r�r�r�ZmemsrFrGrH�a�bZdiff_percentr1r1r2�test_avail_old_percentds
$z.TestSystemVirtualMemory.test_avail_old_percentc
Csvtdt�d�����X}tjdd��}t��}W5QRX|js@t	�|�
|jd�|d}|�dt
|j��W5QRXdS)Nr�aL                Active:          9444728 kB
                Active(anon):    6145416 kB
                Active(file):    2950064 kB
                Buffers:          287952 kB
                Cached:          4818144 kB
                Inactive(file):  1578132 kB
                Inactive(anon):   574764 kB
                Inactive(file):  1567648 kB
                MemAvailable:    6574984 kB
                MemFree:         2057400 kB
                MemTotal:       16325648 kB
                Shmem:            577588 kB
                SReclaimable:     346648 kB
                Tr�l �"r�,inactive memory stats couldn't be determined�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r1r1r2� test_avail_old_comes_from_kernelws�
�z8TestSystemVirtualMemory.test_avail_old_comes_from_kernelc
Csvtdt�d�����X}tjdd��}t��}W5QRX|js@t	�|�
|jd�|d}|�dt
|j��W5QRXdS)Nr�a�                    Active:          9444728 kB
                    Active(anon):    6145416 kB
                    Buffers:          287952 kB
                    Cached:          4818144 kB
                    Inactive(file):  1578132 kB
                    Inactive(anon):   574764 kB
                    MemFree:         2057400 kB
                    MemTotal:       16325648 kB
                    Shmem:            577588 kB
                    Tr��`LGrr�r�r�r1r1r2�test_avail_old_missing_fields�s�
�z5TestSystemVirtualMemory.test_avail_old_missing_fieldscCs�tdt�d�����ltdttjd���Ntj	dd��6}t
��}|�|j
d�|d}|�d	t|j��W5QRXW5QRXW5QRXdS)
Nr�aT                    Active:          9444728 kB
                    Active(anon):    6145416 kB
                    Active(file):    2950064 kB
                    Buffers:          287952 kB
                    Cached:          4818144 kB
                    Inactive(file):  1578132 kB
                    Inactive(anon):   574764 kB
                    Inactive(file):  1567648 kB
                    MemFree:         2057400 kB
                    MemTotal:       16325648 kB
                    Shmem:            577588 kB
                    SReclaimable:     346648 kB
                    z/proc/zoneinfo�no such file or directoryTr�r�rr�)r�r�r�r�r��IOError�errno�ENOENTr�r�r�r�r�r�r�r�r�)r�r�r�r�r1r1r2�test_avail_old_missing_zoneinfo�s&�
���z7TestSystemVirtualMemory.test_avail_old_missing_zoneinfoc	s��fdd�}t�trdnd}tj|d|d���}t��}|js@t�|�|j	d�|�|j
d�|�|jd	�|�|jd
�|�|j
d�|�|jd�|�|jd
�|�|jd�|�|jd�W5QRXdS)Ncs0|dkrt�t�d����S�|f|�|�SdS)Nr�a=	                    MemTotal:              100 kB
                    MemFree:               2 kB
                    MemAvailable:          3 kB
                    Buffers:               4 kB
                    Cached:                5 kB
                    SwapCached:            6 kB
                    Active:                7 kB
                    Inactive:              8 kB
                    Active(anon):          9 kB
                    Inactive(anon):        10 kB
                    Active(file):          11 kB
                    Inactive(file):        12 kB
                    Unevictable:           13 kB
                    Mlocked:               14 kB
                    SwapTotal:             15 kB
                    SwapFree:              16 kB
                    Dirty:                 17 kB
                    Writeback:             18 kB
                    AnonPages:             19 kB
                    Mapped:                20 kB
                    Shmem:                 21 kB
                    Slab:                  22 kB
                    SReclaimable:          23 kB
                    SUnreclaim:            24 kB
                    KernelStack:           25 kB
                    PageTables:            26 kB
                    NFS_Unstable:          27 kB
                    Bounce:                28 kB
                    WritebackTmp:          29 kB
                    CommitLimit:           30 kB
                    Committed_AS:          31 kB
                    VmallocTotal:          32 kB
                    VmallocUsed:           33 kB
                    VmallocChunk:          34 kB
                    HardwareCorrupted:     35 kB
                    AnonHugePages:         36 kB
                    ShmemHugePages:        37 kB
                    ShmemPmdMapped:        38 kB
                    CmaTotal:              39 kB
                    CmaFree:               40 kB
                    HugePages_Total:       41 kB
                    HugePages_Free:        42 kB
                    HugePages_Rsvd:        43 kB
                    HugePages_Surp:        44 kB
                    Hugepagesize:          45 kB
                    DirectMap46k:          46 kB
                    DirectMap47M:          47 kB
                    DirectMap48G:          48 kB
                    )r{r}r�r�r�r~�r�r1r2r��s3zETestSystemVirtualMemory.test_virtual_memory_mocked.<locals>.open_mockr�r�Tr�i�i�ipiTii iX�)r<rrr�r�r�r�r�r�rhr`r�r�ror�r�r�r�)r�r�r�r��memr1r�r2�test_virtual_memory_mocked�s7
z2TestSystemVirtualMemory.test_virtual_memory_mockedN)�__name__�
__module__�__qualname__r�rr�r�r�r�r�r�r�r�r�r�r�r�r�r1r1r1r2r��s,







'
r�c@s\eZdZedd��Zdd�Ze�dd��Ze�dd��Zd	d
�Z	dd�Z
d
d�Zdd�ZdS)�TestSystemSwapMemoryc	Cs,td��}|��}W5QRXd|ko*d|kS)z3Return True if /proc/meminfo provides swap metrics.r�z
SwapTotal:z	SwapFree:)r<�read)rF�datar1r1r2�meminfo_has_swap_infos
z*TestSystemSwapMemory.meminfo_has_swap_infocCs"t�j}t��j}|j||td�S�Nr�)rkrhr��swap_memoryr�r�r�r�r�r1r1r2r�$s
�zTestSystemSwapMemory.test_totalcCs"t�j}t��j}|j||td�Sr�)rkrir�r�r�rr�r1r1r2r�*s
�zTestSystemSwapMemory.test_usedcCs"t�j}t��j}|j||td�Sr�)rkr`r�r�r�rr�r1r1r2r�1s
�zTestSystemSwapMemory.test_freec
Cs�tjddd���}tjdd��x}t�d�t��}|js:t�|�	t
|�d�|d}|j�d�sbt�|�
d	t|j��|�	|jd�|�	|jd�W5QRXW5QRXdS)
N�psutil._common.openT�r�r�r�rmrr�z9'sin' and 'sout' swap memory stats couldn't be determined)rr�r�r�r�r�r�r�r�r�rAr�r�r�r�r��sin�soutr�r1r1r2�test_missing_sin_sout8s

�z*TestSystemSwapMemory.test_missing_sin_soutc
Cs�tdttjd����}tjdd��x}t�d�t��}|j	s>t
�|�t|�d�|d}|j
�d�sft
�|�d	t|j��|�|jd�|�|jd�W5QRXW5QRXdS)
Nz/proc/vmstatr�Tr�r�rmrr�zK'sin' and 'sout' swap memory stats couldn't be determined and were set to 0)r�r�r�r�r�r�r�r�r�r�r�r�rAr�r�r�r�r�r�r�r�r1r1r2�test_no_vmstat_mockedGs$
�

�z*TestSystemSwapMemory.test_no_vmstat_mockedc	Cs�|��st�d�St�d��}t��}W5QRX|jr:t�ddl	m
}|��\}}}}}}}||9}||9}|�|j
|�|j|j|td�dS)Nz!/proc/meminfo has no swap metricsz"psutil._pslinux.cext.linux_sysinforr�)r�r�skiprr�r�r�r�r�Zpsutil._psutil_linuxZ
_psutil_linuxZ
linux_sysinfor�rhr�r`r)r�r��swapZcextrgrhr`Zunit_multiplierr1r1r2�test_meminfo_against_sysinfoZs

z1TestSystemSwapMemory.test_meminfo_against_sysinfoc	Cs,tdd��}t��|jst�W5QRXdS)Nr��)r�r�r�r�r��r�r�r1r1r2�#test_emulate_meminfo_has_no_metricsjsz8TestSystemSwapMemory.test_emulate_meminfo_has_no_metricsN)
r�r�r��staticmethodr�r�rr�r�r�r�r�r�r1r1r1r2r�s


r�c@seZdZdd�ZdS)�TestSystemCPUTimescCs�t��j}t�dt��d�d}ttt	|�
d���}|dkrL|�d|�n|�d|�|dkrn|�d|�n|�d|�|d	kr�|�d
|�n|�d
|�dS)Nz
\d+\.\d+\.\d+�rru)r����steal)r�r�r Zguest)r�r�rZ
guest_nice)
r��	cpu_times�_fields�re�findall�os�unamerwrxrdr>r��assertNotIn)r�rHZ
kernel_verZkernel_ver_infor1r1r2�test_fields{s
zTestSystemCPUTimes.test_fieldsN)r�r�r�rr1r1r1r2r�xsr�c@s�eZdZe�ej�d�d�dd��Ze�ej�d�d�dd��Z	e�e
d	�d
�dd��Ze�e
d
�d�dd��Zdd�Z
dS)�TestSystemCPUCountLogical�/sys/devices/system/cpu/onlinez-/sys/devices/system/cpu/online does not existc	CsVtd��}|����}W5QRXdt|�krRt|�d�d�d}|�t��|�dS)Nr�-rm)	r<r�rrr�rdr>r�r��	cpu_count)r�rF�valuer1r1r2�test_against_sysdev_cpu_online�s

z8TestSystemCPUCountLogical.test_against_sysdev_cpu_online�/sys/devices/system/cpuz&/sys/devices/system/cpu does not existcCs0t�d�}tdd�|D��}|�t��|�dS)Nr
cSs g|]}t�d|�dk	r|�qS)zcpu\d+$N)r�searchrlr1r1r2rT�szITestSystemCPUCountLogical.test_against_sysdev_cpu_num.<locals>.<listcomp>)r�listdirrAr�r�r
)r�Zls�countr1r1r2�test_against_sysdev_cpu_num�s
z5TestSystemCPUCountLogical.test_against_sysdev_cpu_numZnprocznproc utility not availablecCs$ttd��}|�tjdd�|�dS)Nznproc --allT�Zlogical)rdrr�r�r
)r��numr1r1r2�test_against_nproc�sz,TestSystemCPUCountLogical.test_against_nproc�lscpu�lscpu utility not availablecCs8td�}tdd�|�d�D��}|�tjdd�|�dS)N�lscpu -pcSsg|]}|�d�s|�qS)�#�rarlr1r1r2rT�s
z@TestSystemCPUCountLogical.test_against_lscpu.<locals>.<listcomp>r_Tr)rrAr>r�r�r
)r�rerr1r1r2�test_against_lscpu�sz,TestSystemCPUCountLogical.test_against_lscpuc
Csddl}|j��}tjdtd���}|�|j��|�|js>t�tjddd��:}|�	|j���|�|j
d�|�|jddd�W5QRXtd	d
��}|�
�}W5QRXt�|�}tjd|dd��}|�|j��|�W5QRXtd	d��}|�|j��|�|jW5QRXW5QRXdS)
Nrzpsutil._pslinux.os.sysconf�r�r�Tr�r��
/proc/stat�
/proc/cpuinfo�rb��return_valuer�r�)r��_pslinuxZcpu_count_logicalrr�r?r�r�r��assertIsNoneZ
call_countZ	call_argsr<r�r{r}r�)r�r�Zoriginalr�rFZcpuinfo_data�	fake_filer1r1r2�test_emulate_fallbacks�s2
�
 
�z0TestSystemCPUCountLogical.test_emulate_fallbacksN)r�r�r�r�skipIfr�path�existsrrrrrr$r1r1r1r2r�s�
�


rc@s6eZdZe�ed�d�dd��Zdd�Zdd�Zd	S)
�TestSystemCPUCountPhysicalrrcCs\td�}t�}|�d�D]&}|�d�s|�d�}|�|d�q|�tjdd�t|��dS)Nrr_r�,rmFr)	r�setr>ra�addr�r�r
rA)r�reZcore_idsrGrHr1r1r2r�s

z-TestSystemCPUCountPhysical.test_against_lscpuc	CsPtj��}tjdgd��}tj��}|js.t�W5QRX|dk	rL|�||�dS)N�	glob.glob�r )r�r!�cpu_count_physicalrr�r�r�r�)r�Zmeth_1r�Zmeth_2r1r1r2�
test_method_2�s

z(TestSystemCPUCountPhysical.test_method_2c
Cs\tjdgd��0}tjddd��}|�tj���W5QRXW5QRX|jsNt�|jsXt�dS)Nr,r-r�Tr�)rr�r"r�r!r.r�r�)r��m1�m2r1r1r2�test_emulate_none�s
$
z,TestSystemCPUCountPhysical.test_emulate_noneN)	r�r�r�rr%rrr/r2r1r1r1r2r(�s
	r(c@szeZdZe�ed�dd��Ze�ed�dd��Ze�ed�dd��Ze�ed�dd	��Z	e�ed�d
d��Z
dS)
�TestSystemCPUFrequency�
not supportedc	s@�fdd�}tjj�tjd|dd��t��s2t�W5QRXdS)Ncs|�d�rdS�|�SdS)N�&/sys/devices/system/cpu/cpufreq/policyFr�r&�Zorig_existsr1r2�path_exists_mock�s
zMTestSystemCPUFrequency.test_emulate_use_second_file.<locals>.path_exists_mock�os.path.existsT)r�r�)rr&r'rr�r��cpu_freqr�)r�r8r1r7r2�test_emulate_use_second_file�s�z3TestSystemCPUFrequency.test_emulate_use_second_filec	s���fdd�}g�tjj�z�tjd|d��rttj�t��}|sFt	��sNt	�|�
|jd�|�
|jd�tjdd�D] }|�
|jd�|�
|jd�qvW5QRXW5ttj�tt�XdS)Ncs,|�d�rdS|dkr ��d��|�SdS)Nz/sys/devices/system/cpu/Fr)rarBr6��flagsZos_path_existsr1r2r8�s


zITestSystemCPUFrequency.test_emulate_use_cpuinfo.<locals>.path_exists_mockr9r�T�Zpercpu)
rr&r'rr�r!rr�r:r�r��max�min)r�r8r��freqr1r<r2�test_emulate_use_cpuinfo�s 

z/TestSystemCPUFrequency.test_emulate_use_cpuinfoc
s��fdd�}t�trdnd}tj||d��ftjddd��Lt��}|�|jd	�|jd
krj|�|jd�|j	d
kr�|�|j	d�W5QRXW5QRXdS)
Ncs�|�d�r|�d�rt�d�S|�d�r<|�d�r<t�d�S|�d�rZ|�d�rZt�d�S|dkrlt�d	�S�|f|�|�SdS)
N�/scaling_cur_freqr5�500000�/scaling_min_freq�600000�/scaling_max_freqs700000rscpu MHz		: 500�r�rar{r}r~r�r1r2r�s
�

�

�

z;TestSystemCPUFrequency.test_emulate_data.<locals>.open_mockr�r�rr9Tr-�@@r>���@g�@�
r<rrr�r�r:r��currentrAr@�r�r�r�rBr1r�r2�test_emulate_datas�

z(TestSystemCPUFrequency.test_emulate_datacs�fdd�}t�trdnd}tj||d���tjddd���tjd	d
d���tjdd�}|�|djd
�|djdkr�|�|djd�|dj	dkr�|�|dj	d�|�|djd�|djdkr�|�|djd�|dj	dkr�|�|dj	d�W5QRXW5QRXW5QRXdS)Ncs�|}|�d�r"|�d�r"t�d�S|�d�r@|�d�r@t�d�S|�d�r^|�d�r^t�d�S|�d�r||�d�r|t�d	�S|�d�r�|�d�r�t�d
�S|�d�r�|�d�r�t�d�S|dkr�t�d
�S�|f|�|�SdS)NrDz'/sys/devices/system/cpu/cpufreq/policy0s100000rF�200000rHs300000z'/sys/devices/system/cpu/cpufreq/policy1s400000rErGrscpu MHz		: 100
cpu MHz		: 400rI)rr�r��nr�r1r2r�9s8
�

�

�

�

�

�

z@TestSystemCPUFrequency.test_emulate_multi_cpu.<locals>.open_mockr�r�rr9Tr-�!psutil._pslinux.cpu_count_logicalr�r?r�Y@r>gi@g�r@rmgy@rJrKrLrNr1r�r2�test_emulate_multi_cpu7s&�z-TestSystemCPUFrequency.test_emulate_multi_cpucs��fdd�}t�trdnd}tj||d��Ptjddd��6tjd	d
d��t��}|�|jd�W5QRXW5QRXW5QRXdS)NcsR|�d�rttjd��n6|�d�r,t�d�S|dkr>t�d�S�|f|�|�SdS)NrDrPz/cpuinfo_cur_freqrPrscpu MHz		: 200)r�r�r�r�r{r}r~r�r1r2r�hs



zOTestSystemCPUFrequency.test_emulate_no_scaling_cur_freq_file.<locals>.open_mockr�r�rr9Tr-rRrm��)r<rrr�r�r:r�rMrNr1r�r2�%test_emulate_no_scaling_cur_freq_filees
�z<TestSystemCPUFrequency.test_emulate_no_scaling_cur_freq_fileN)r�r�r�rr%rr;rCrOrTrVr1r1r1r2r3�s




-r3c@seZdZdd�Zdd�ZdS)�TestSystemCPUStatscCs&td�}t��j}|j||dd�dS)Nzcontext switches��r�)rtr��	cpu_statsZctx_switchesr�r�r1r1r2�test_ctx_switchess
z$TestSystemCPUStats.test_ctx_switchescCs&td�}t��j}|j||dd�dS)N�
interruptsrXr�)rtr�rYr[r�r�r1r1r2�test_interrupts�s
z"TestSystemCPUStats.test_interruptsN)r�r�r�rZr\r1r1r1r2rW|srWc@s"eZdZe�ed�dd��ZdS)�TestLoadAvgr4c	Cs�t��}tdd��}|����}W5QRX|jt|d�|ddd�|jt|d�|ddd�|jt|d�|ddd�dS)Nz
/proc/loadavg�rrrmr�r�)r��
getloadavgr<r�r>r��float)r�r�rFZ
proc_valuer1r1r2�test_getloadavg�szTestLoadAvg.test_getloadavgN)r�r�r�rr%rrar1r1r1r2r]�sr]c@seZdZdd�ZdS)�TestSystemNetIfAddrscCs�t����D]�\}}|D]�}|jtjkr<|�|jt|��q|jtj	kr�|�|jt
|��|�|jt|��|j
dk	r�|�|j
t|��q�|�t|�d�q|jtjkr|j�d�d}|�|t|��qqdS)Nz0.0.0.0�%r)r�Znet_if_addrs�itemsZfamilyZAF_LINKr��addressrYr#r$r3Znetmaskr5Z	broadcastr7rDr>rK)r�rZaddrsZaddrrer1r1r2�test_ips�s
�zTestSystemNetIfAddrs.test_ipsN)r�r�r�rfr1r1r1r2rb�srbc@seZdZdd�Zdd�ZdS)�TestSystemNetIfStatsc	Cstt����D]b\}}ztd|�}Wntk
r8YqX|j|jd|k|d�|�|jtt	�
d|�d��qdS)N�ifconfig %sZRUNNING)r�z(?i)MTU[: ](\d+)r)r��net_if_statsrdr�RuntimeErrorr�Zisup�mturdrr)r�r�statsrer1r1r2�test_against_ifconfig�s�z*TestSystemNetIfStats.test_against_ifconfigc
CsNt����D]<\}}td|d�� }|�|jt|������W5QRXqdS)Nz/sys/class/net/%s/mtur8)	r�rirdr<r�rkrdr�rr)r�rrlrFr1r1r2�test_mtu�szTestSystemNetIfStats.test_mtuN)r�r�r�rmrnr1r1r1r2rg�srgc@seZdZe�dd��ZdS)�TestSystemNetIOCountersc	s�fdd�}tjddd�}|��D]�\�}z|��}Wntk
rNYq"YnX|j|j|ddd�|j|j|d	dd�|j|j|d
dd�|j|j|ddd�|j|j	|d
dd�|j|j
|ddd�|j|j|ddd�|j|j|ddd�q"dS)Ncs�i}td��}tt�d|�d�|d<tt�d|�d�|d<tt�d|�d�|d<tt�d|�d	�|d
<tt�d|�d�|d<tt�d|�d	�|d
<tt�d|�d�|d<tt�d|�d�|d<|S)NrhzRX packets[: ](\d+)r�packets_recvzTX packets[: ](\d+)�packets_sentzerrors[: ](\d+)�errinrm�erroutzdropped[: ](\d+)�dropin�dropoutz#RX (?:packets \d+ +)?bytes[: ](\d+)�
bytes_recvz#TX (?:packets \d+ +)?bytes[: ](\d+)�
bytes_sent)rrdrr)Znicr�re�rr1r2�ifconfig�s&����z?TestSystemNetIOCounters.test_against_ifconfig.<locals>.ifconfigTF)Zpernic�nowraprvir�rwrpr�rqrr�
rsrtru)
r��net_io_countersrdrjr�rvrwrprqrrrsrtru)r�ryZniorlZifconfig_retr1rxr2rm�s^
��������z-TestSystemNetIOCounters.test_against_ifconfigN)r�r�r�rrmr1r1r1r2ro�sroc@s8eZdZejded�ejddd�dd���Zdd	�Zd
S)�TestSystemNetConnectionsz psutil._pslinux.socket.inet_ntoprzpsutil._pslinux.supports_ipv6Fr-cCsRz*t�tjtj�}|�|j�|�d�Wntjk
r@YnXtjdd�dS)N)z::1rZinet6�Zkind)	r#rDZSOCK_STREAMZ
addCleanup�closeZbind�errorr��net_connections)r�Z
supports_ipv6rEr0r1r1r2�test_emulate_ipv6_unsupportedsz6TestSystemNetConnections.test_emulate_ipv6_unsupportedc	Cs6tdt�d���}tjdd�|js(t�W5QRXdS)Nz/proc/net/unixa.                0: 00000003 000 000 0001 03 462170 @/tmp/dbus-Qw2hMPIU3n
                0: 00000003 000 000 0001 03 35010 @/tmp/dbus-tB2X8h69BQ
                0: 00000003 000 000 0001 03 34424 @/tmp/dbus-cHy80Y8O
                000000000000000000000000000000000000000000000000000000
                Zunixr~)r�r�r�r�r�r�r�r�r1r1r2�test_emulate_unixs�z*TestSystemNetConnections.test_emulate_unixN)r�r�r�rr�r?r�r�r1r1r1r2r}	s
r}c@s>eZdZe�eed�d�e�dd���Zdd�Z	dd�Z
d	S)
�TestSystemDiskPartitions�statvfszos.statvfs() not availablecCsndd�}tjdd�D]T}t�|j�}||j�\}}}}|�|j|�|j|j|td�|j|j	|td�qdS)NcSsztd|���}|�d�}|�d�|�d�}|��dd�\}}}}|dkrRd}t|�t|�t|�}}}||||fS)Nzdf -P -B 1 "%s"r_rr:ZnonerP)rrrr>�poprd)r&rerfrG�devrhrir`r1r1r2�df2s


z4TestSystemDiskPartitions.test_against_df.<locals>.dfF)�allr�)
r��disk_partitionsZ
disk_usageZ
mountpointr�rhr�r`rri)r�r��partZusager�rhrir`r1r1r2�test_against_df-s
�
�z(TestSystemDiskPartitions.test_against_dfc
Cs�tdd��}|��}W5QRXd|krNt��D]}|jdkr.q�q.|�d�n|t�td��}t	j
d|dd��X}t	j
d	d
gd��<}t��}|js�t�|js�t�|s�t�|�
|djd�W5QRXW5QRXdS)
Nz/proc/filesystemsr^�zfszcouldn't find any ZFS partitionz
nodev	zfs
r�Trz$psutil._pslinux.cext.disk_partitions)z	/dev/sdb3�/r�Zrwr-r)r<r�r�r�ZfstypeZfailr{r|rrr�r�r�r�)r�rFr�r�r#r0r1r�r1r1r2�test_zfs_fsFs.
��

z$TestSystemDiskPartitions.test_zfs_fsc
CsTzFtjddd��.}|�t��t��W5QRX|js:t�W5QRXW5dt_XdS)N�/proczos.path.realpathz
/non/existentr-)	r��PROCFS_PATHrr��assertRaisesrr�r�r�r�r1r1r2�test_emulate_realpath_fail^s�z3TestSystemDiskPartitions.test_emulate_realpath_failN)r�r�r�rr%�hasattrrrr�r�r�r1r1r1r2r�*s
r�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�TestSystemDiskIoCountersc
Cs�tdd���tjddd���tjdd�}|�|jd�|�|jd	�|�|jd
t	�|�|j
d�|�|jd�|�|jd
�|�|j
dt	�|�|jd�|�|jd�W5QRXW5QRXdS)N�/proc/diskstatsz+   3     0   1 hda 2 3 4 5 6 7 8 9 10 11 12�!psutil._pslinux.is_storage_deviceTr-F�rzrmr�r�r:rnr���r{�r�rr�r��disk_io_countersr��
read_count�read_merged_count�
read_bytes�SECTOR_SIZE�	read_time�write_count�write_merged_count�write_bytes�
write_time�	busy_time�r�r�r1r1r2�test_emulate_kernel_2_4ms"��z0TestSystemDiskIoCounters.test_emulate_kernel_2_4c
Cs�tdd���tjddd���tjdd�}|�|jd�|�|jd	�|�|jd
t	�|�|j
d�|�|jd�|�|jd
�|�|j
dt	�|�|jd�|�|jd�W5QRXW5QRXdS)Nr�z'   3    0   hda 1 2 3 4 5 6 7 8 9 10 11r�Tr-Fr�rmr�r�r:rnr�r�r�r{r�r�r1r1r2�test_emulate_kernel_2_6_full�s"��z5TestSystemDiskIoCounters.test_emulate_kernel_2_6_fullc
Cs�tdd���tjddd���tjdd�}|�|jd�|�|jd	t�|�|j	d
�|�|j
dt�|�|jd�|�|jd�|�|j
d�|�|jd�|�|jd�W5QRXW5QRXdS)
Nr�z   3    1   hda 1 2 3 4r�Tr-Fr�rmr�r�r:r)r�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r1r1r2�test_emulate_kernel_2_6_limited�s"��z8TestSystemDiskIoCounters.test_emulate_kernel_2_6_limitedc
Cs�tdt�d����tjddd��ltjddd�}|�t|�d�|�|d	j	d
�|�|dj	d
�|�|d	j
d�|�|dj
d�W5QRXW5QRXdS)
Nr���                    3    0   nvme0n1 1 2 3 4 5 6 7 8 9 10 11
                    3    0   nvme0n1p1 1 2 3 4 5 6 7 8 9 10 11
                    r�Fr-T��perdiskrzr��nvme0n1rmZ	nvme0n1p1rn)r�r�r�rr�r�r�r�rAr�r�r�r1r1r2�test_emulate_include_partitions�s��z8TestSystemDiskIoCounters.test_emulate_include_partitionsc
Cs�tdt�d���8tjddd��tjddd�}|�|�W5QRXW5QRXdd�}tdt�d���Ltjdd	|d
��0tjddd�}|�|j	d�|�|j
d�W5QRXW5QRXdS)
Nr�r�r�Fr-r�cSs|dkS)Nr�r1rxr1r1r2�is_storage_device�szSTestSystemDiskIoCounters.test_emulate_exclude_partitions.<locals>.is_storage_deviceTr�rmrn)r�r�r�rr�r�r�r"r�r�r�)r�r�r�r1r1r2�test_emulate_exclude_partitions�s*����z8TestSystemDiskIoCounters.test_emulate_exclude_partitionsc	CsTdd�}tjdd�}tjdd|d��tjdd�}W5QRX|�t|�t|��dS)NcSs|dkrdSdS)Nr�FTr1r6r1r1r2r'�sz?TestSystemDiskIoCounters.test_emulate_use_sysfs.<locals>.existsT)r��psutil._pslinux.os.path.existsr�)r�r�rr�r�rA)r�r'ZwprocfsZwsysfsr1r1r2�test_emulate_use_sysfs�s�z/TestSystemDiskIoCounters.test_emulate_use_sysfsc	Cs6dd�}tjdd|d��|�ttj�W5QRXdS)NcSsdS)NFr1r6r1r1r2r'�sz>TestSystemDiskIoCounters.test_emulate_not_impl.<locals>.existsr�Tr�)rr�r��NotImplementedErrorr�r�)r�r'r1r1r2�test_emulate_not_impl�s�z.TestSystemDiskIoCounters.test_emulate_not_implN)
r�r�r�r�r�r�r�r�r�r�r1r1r1r2r�jsr�c@sReZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	�d
d��Z
dd�ZdS)�TestMisccCs(td�}t��}|�t|�t|��dS)Nz	boot time)rtr��	boot_timer�rdr�r1r1r2�test_boot_time�szTestMisc.test_boot_timec
s|��}t�|�ttj�|d�d��$}|�d�|�d�|�d�W5QRX�z�t��fdd�}trldnd	}tj
||d
���nt	t
�|�tt
j�|jtt
jdd�|�tt
j�|jtt
jdd�|�tt
j�|jtt
jdd�|t
_|�t
��d
�|�tt
���d
�t
jdd�}|�t|�d
�t
jdd�}|�ttt|��d
�ttj�|d�d��$}|�d�|�d�|�d�W5QRX|�t
��d
�|�tt
jdd��d
�|�tt
���d
�|�tttt
jdd���d
�W5QRXW5t�|�t	t
�X|�t
jd�dS)Nrsr�zcpu   0 0 0 0 0 0 0 0 0 0
zcpu0  0 0 0 0 0 0 0 0 0 0
zcpu1  0 0 0 0 0 0 0 0 0 0
cs&|�d�rttjd���|f|�|�S)Nr�zrejecting access for test)rar�r�r�r~r�r1r2r�s
z4TestMisc.test_no_procfs_on_import.<locals>.open_mockr�r�rTr?rzcpu   1 0 0 0 0 0 0 0 0 0
zcpu0  1 0 0 0 0 0 0 0 0 0
zcpu1  1 0 0 0 0 0 0 0 0 0
r�)�
get_testfnr�mkdirr<r&rC�write�shutilZrmtreerr�rrr�r�r�r��cpu_percent�cpu_times_percentr�r��sumrx�assertNotEqual)r�Z	my_procfsrFr�r�Zper_cpu_percentZper_cpu_times_percentr1r�r2�test_no_procfs_on_import�s\


�

��

z!TestMisc.test_no_procfs_on_importc	Cs,tdt�d�����8}t��|js(t�tjdd�t��tjdd�W5QRXtdt�d������}t��}|jszt�tjdd�}t��}tjdd�}|�	|d�|�	t
|�d�|�	t
|�d�|�	t
|�d�|�	t
tt
|��d�|�	t
tt
|��d�|�|j
d�|�	|jd�W5QRXdS)Nrz�                cpu   0 0 0 0 0 0 0 1 0 0
                cpu0  0 0 0 0 0 0 0 1 0 0
                cpu1  0 0 0 0 0 0 0 1 0 0
                Tr?z�                cpu   1 0 0 0 0 0 0 0 0 0
                cpu0  1 0 0 0 0 0 0 0 0 0
                cpu1  1 0 0 0 0 0 0 0 0 0
                rrS)r�r�r�r�r�r�r�r�r�r�r�rxr�r��user)r�r�r�Zcpu_percent_percpur�Zcpu_times_percent_percpur1r1r2�test_cpu_steal_decrease<s8�
�
z TestMisc.test_cpu_steal_decreasec	Cs8tjddd�� }|�ttjj�|js*t�W5QRXdS)Nr�Tr�)	rr�r�rjr�r!r�r�r�r�r1r1r2�test_boot_time_mockedes�zTestMisc.test_boot_time_mockedc	Cs�tjddgd��&}|�t��djd�|js2t�W5QRXtjddgd��&}|�t��djd�|jsnt�W5QRXtjddgd��&}|�t��djd�|js�t�W5QRXdS)	Nzpsutil._pslinux.cext.users)�	giampaolo�pts/2z:0��h�ATr�r-rZ	localhost)r�r�z:0.0r�Tr�)r�r��foor�Tr�r�)rr�r�r�ZusersZhostr�r�r�r1r1r2�test_users_mockedls$���zTestMisc.test_users_mockedcCs�|��}t�|�z�|t_|�ttj�|�ttj�|jttjdd�|�ttj	�|�ttj
�|�ttj�|�ttj�|�ttj
�|�tjtj�W5dt_XdS)Nr�Tr?)r�rr�r�r�r�r�r�r�r�r�r|rir�Z
NoSuchProcess�Process)r�Ztdirr1r1r2�test_procfs_path�s
zTestMisc.test_procfs_pathcCs�t�}|��zjt��}|��}|�t|�d�t|dd�d�dj	}|�
|j|�t�|�}|��|�
|t���W5|��XdS)Nr�cSs|jSrL)�idrMr1r1r2�<lambda>�r�z)TestMisc.test_issue_687.<locals>.<lambda>)�keyrm)r�start�stopr�r��threadsr�rA�sortedr�r��pidZas_dictrZpids)r��t�pr��tidZptr1r1r2�test_issue_687�s
zTestMisc.test_issue_687c	Cs6tdd��"}t�t���st�|js(t�W5QRXdS)N�/proc/%s/statusrP)r�r�Z
pid_existsr�getpidr�r�r�r1r1r2�test_pid_exists_no_proc_status�sz'TestMisc.test_pid_exists_no_proc_statusN)r�r�r�r�r�r�r�r�r�rr�r�r1r1r1r2r��s=)
r�z
no batteryc@sfeZdZe�ed�d�dd��Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�ZdS)�TestSensorsBatteryZacpizacpi utility not availablecCsDtd�}t|�d�d���dd��}t��j}|j||dd�dS)Nzacpi -br)rmrcrPr�)	rrdr>rr�replacer��sensors_battery�percentr�)r�reZ
acpi_valuer�r1r1r2�test_percent�s
zTestSensorsBattery.test_percentc	sj�fdd�}t�trdnd}tj||d��6}|�t��jd�|�t��jtj	�|j
s\t�W5QRXdS)Ncs2|�d�s|�d�rt�d�S�|f|�|�SdS)N�
AC0/online�	AC/online�1�r�r{r}r~r�r1r2r��s
z@TestSensorsBattery.test_emulate_power_plugged.<locals>.open_mockr�r�rT)r<rrr�r�r�r��
power_pluggedZsecsleftZPOWER_TIME_UNLIMITEDr�r��r�r�r�r�r1r�r2�test_emulate_power_plugged�s�z-TestSensorsBattery.test_emulate_power_pluggedc	sV�fdd�}t�trdnd}tj||d��"}|�t��jd�|jsHt	�W5QRXdS)NcsN|�d�s|�d�r"ttjd��n(|�d�r:t�td��S�|f|�|�SdS)Nr�r�rP�/statusZcharging�r�r�r�r�r{r|rr~r�r1r2r��s

zBTestSensorsBattery.test_emulate_power_plugged_2.<locals>.open_mockr�r�rT�
r<rrr�r�r�r�r�r�r�r�r1r�r2�test_emulate_power_plugged_2�sz/TestSensorsBattery.test_emulate_power_plugged_2c	sV�fdd�}t�trdnd}tj||d��"}|�t��jd�|jsHt	�W5QRXdS)Ncs2|�d�s|�d�rt�d�S�|f|�|�SdS)Nr�r��0r�r~r�r1r2r��s
zDTestSensorsBattery.test_emulate_power_not_plugged.<locals>.open_mockr�r�rFr�r�r1r�r2�test_emulate_power_not_plugged�sz1TestSensorsBattery.test_emulate_power_not_pluggedc	sV�fdd�}t�trdnd}tj||d��"}|�t��jd�|jsHt	�W5QRXdS)NcsN|�d�s|�d�r"ttjd��n(|�d�r:t�td��S�|f|�|�SdS)Nr�r�rPr�Zdischargingr�r~r�r1r2r��s

zFTestSensorsBattery.test_emulate_power_not_plugged_2.<locals>.open_mockr�r�rFr�r�r1r�r2� test_emulate_power_not_plugged_2�sz3TestSensorsBattery.test_emulate_power_not_plugged_2c	sT�fdd�}t�trdnd}tj||d�� }|�t��j�|jsFt	�W5QRXdS)NcsJ|�d�s|�d�r"ttjd��n$|�d�r6t�d�S�|f|�|�SdS)N�"/sys/class/power_supply/AC0/online�!/sys/class/power_supply/AC/onlinerP�#/sys/class/power_supply/BAT0/statuss???)rar�r�r�r{r}r~r�r1r2r�s
�

zETestSensorsBattery.test_emulate_power_undetermined.<locals>.open_mockr�r�r)
r<rrr�r"r�r�r�r�r�r�r1r�r2�test_emulate_power_undetermineds	z2TestSensorsBattery.test_emulate_power_undeterminedc	Cs6tdd��"}|�t��jd�|js(t�W5QRXdS)N�(/sys/class/power_supply/BAT0/energy_fullr�r)r�r�r�r�r�r�r�r�r1r1r2�test_emulate_energy_full_0s�z-TestSensorsBattery.test_emulate_energy_full_0cCshtdttjd���Ltdttjd���.tdd��|�t��jd�W5QRXW5QRXW5QRXdS)Nr�rPz(/sys/class/power_supply/BAT0/charge_fullz%/sys/class/power_supply/BAT0/capacitys88�X)	r�r�r�r�r�r�r�r�r��r�r1r1r2�"test_emulate_energy_full_not_avails
�
��z5TestSensorsBattery.test_emulate_energy_full_not_availcCsntdttjd���Rtdttjd���4tdttjd���|�t��j�W5QRXW5QRXW5QRXdS)Nr�rPr�r�)r�r�r�r�r"r�r�r�r�r1r1r2�test_emulate_no_power's
�
�
�z(TestSensorsBattery.test_emulate_no_powerN)r�r�r�rr%rr�r�r�r�r�r�r�r�r�r1r1r1r2r��s

r�c@seZdZdd�ZdS)�TestSensorsBatteryEmulatedc
sx�fdd�}t�trdnd}tjddgd��.}tj||d��}|�t���W5QRXW5QRX|jsjt�|jstt�dS)	Ncs\|�d�rt�td��S|�d�r0t�td��S|�d�rHt�td��S�|f|�|�SdS)Nz/energy_nowZ60000000z
/power_now�0z/energy_fullZ60000001�r�r{r|rr~r�r1r2r�9s


z5TestSensorsBatteryEmulated.test_it.<locals>.open_mockr�r�z
os.listdirZBAT0r-r)	r<rrr�ZassertIsNotNoner�r�r�r�)r�r�r�ZmlistdirZmopenr1r�r2�test_it8s
"
z"TestSensorsBatteryEmulated.test_itN)r�r�r�r�r1r1r1r2r�5sr�c@seZdZdd�Zdd�ZdS)�TestSensorsTemperaturesc
s��fdd�}t�trdnd}tj||d��jtjddgd��Nt��d	d
}|�|jd�|�|jd�|�|j	d
�|�|j
d�W5QRXW5QRXdS)Ncs�|�d�rt�td��S|�d�r0t�td��S|�d�rDt�d�S|�d�rXt�d�S|�d	�rlt�d
�S�|f|�|�SdS)N�/namerz/temp1_label�labelz/temp1_input�30000z
/temp1_maxs40000z/temp1_crit�50000)r�r{r|rr}r~r�r1r2r�Ps







zCTestSensorsTemperatures.test_emulate_class_hwmon.<locals>.open_mockr�r�rr,z/sys/class/hwmon/hwmon0/temp1r-rrr��>@gD@�I@�r<rrr�r�Zsensors_temperaturesr�r�rMZhigh�critical)r�r�r��tempr1r�r2�test_emulate_class_hwmonOs�z0TestSensorsTemperatures.test_emulate_class_hwmonc
s��fdd�}dd�}t�tr dnd}tj||d��jtjdd	|d
��Nt��dd}|�|jd
�|�|jd�|�|j	d�|�|j
d�W5QRXW5QRXdS)Ncsl|�d�rt�d�S|�d�r(t�d�S|�d�r@t�td��S|�d�rXt�td��S�|f|�|�SdS)	NZ0_temprrr�Z0_typer�typer)r�r{r}r|rr~r�r1r2r�ks





zETestSensorsTemperatures.test_emulate_class_thermal.<locals>.open_mockcSs:|dkrgS|dkrgS|dkr&dgS|dkr6ddgSgS)Nz/sys/class/hwmon/hwmon*/temp*_*z&/sys/class/hwmon/hwmon*/device/temp*_*z /sys/class/thermal/thermal_zone*z /sys/class/thermal/thermal_zone0z,/sys/class/thermal/thermal_zone0/trip_point*z2/sys/class/thermal/thermal_zone1/trip_point_0_typez2/sys/class/thermal/thermal_zone1/trip_point_0_tempr1r6r1r1r2�	glob_mockws�zETestSensorsTemperatures.test_emulate_class_thermal.<locals>.glob_mockr�r�rr,Tr�rrrPrrr)r�r�rr�rr1r�r2�test_emulate_class_thermaljsz2TestSensorsTemperatures.test_emulate_class_thermalN)r�r�r�rr	r1r1r1r2r�Lsr�c@seZdZdd�ZdS)�TestSensorsFansc
s��fdd�}t�trdnd}tj||d��Ntjddgd��2t��d	d
}|�|jd�|�|jd�W5QRXW5QRXdS)
Ncs\|�d�rt�td��S|�d�r0t�td��S|�d�rHt�td��S�|f|�|�SdS)Nr�rz/fan1_labelr�z/fan1_inputZ2000r�r~r�r1r2r��s


z4TestSensorsFans.test_emulate_data.<locals>.open_mockr�r�rr,z/sys/class/hwmon/hwmon2/fan1r-rrr�i�)	r<rrr�r�Zsensors_fansr�r�rM)r�r�r�Zfanr1r�r2rO�s
�z!TestSensorsFans.test_emulate_dataN)r�r�r�rOr1r1r1r2r
�sr
c@s�eZdZe�dd��Zdd�Ze�ed�dd��Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Ze�ed�dd��Zdd �Zd!d"�Zd#d$�Zd%S)&�TestProcesscCs�|��}t�d|�}|�|�}tdd�d|�t�|j�}t�	d�|�
�}|jdd�}|j|j
tdd	�|D��d
d�|j|jtdd	�|D��d
d�|j|jtd
d	�|D��d
d�dS)Nzk
            import time
            with open("%s", "w") as f:
                time.sleep(10)
            cSs
t�d�S)Nru)rrr1r1r1r2r��r�z3TestProcess.test_memory_full_info.<locals>.<lambda>z'%s' not in retg�������?F)ZgroupedcSsg|]}|j|j�qSr1)Z
private_dirtyZ
private_cleanrlr1r1r2rT�sz5TestProcess.test_memory_full_info.<locals>.<listcomp>r�r�cSsg|]
}|j�qSr1)�pssrlr1r1r2rT�scSsg|]
}|j�qSr1)r�rlr1r1r2rT�s)r�r�r�Zpyrunrr�r�r��time�sleep�memory_full_info�memory_mapsr��ussr�rr�)r��testfn�srcZsprocr�r��mapsr1r1r2�test_memory_full_info�s2�

���z!TestProcess.test_memory_full_infoc	Csptdt��t�d�����J}t��}|��}|j	s8t
�|�|jd�|�|j
d�|�|jd�W5QRXdS)N�/proc/%s/smapsa�                fffff0 r-xp 00000000 00:00 0                  [vsyscall]
                Size:                  1 kB
                Rss:                   2 kB
                Pss:                   3 kB
                Shared_Clean:          4 kB
                Shared_Dirty:          5 kB
                Private_Clean:         6 kB
                Private_Dirty:         7 kB
                Referenced:            8 kB
                Anonymous:             9 kB
                LazyFree:              10 kB
                AnonHugePages:         11 kB
                ShmemPmdMapped:        12 kB
                Shared_Hugetlb:        13 kB
                Private_Hugetlb:       14 kB
                Swap:                  15 kB
                SwapPss:               16 kB
                KernelPageSize:        17 kB
                MMUPageSize:           18 kB
                Locked:                19 kB
                VmFlags: rd ex
                ilr�i<)r�rr�r�r�r�r�r�rr�r�r�rrr�)r�r�r�r�r1r1r2�test_memory_full_info_mocked�s
�
z(TestProcess.test_memory_full_info_mockedzunreliable on PYPYc	Csjdd�}|��}t|d��|�||�jd�W5QRXt|d��|�||�jd�W5QRXt|d��|�||�jd�W5QRXt|d��|�||�jd�W5QRXt|d��|�||�jd�W5QRXt|d��|�||�jd�W5QRXt�rft|�t|d	��|�||�jd�W5QRXt|�t|d
��|�||�jd�W5QRXdS)NcSsZt��}t��t}|��D].}|jtj�|�kr:|St��|krqqqtd��dS)Nztimeout looking for test file)	r�r�r
r	�
open_filesr&r�abspathrj)Zfnamer�Z	giveup_at�filer1r1r2�
get_test_file�sz7TestProcess.test_open_files_mode.<locals>.get_test_filer�r^r�zr+zw+za+rNzx+)r�r<r��moderr)r�rrr1r1r2�test_open_files_mode�s*z TestProcess.test_open_files_modec
Cs�t��}|��}t|��d���t|jdt|��tjdt	t
jd�d�� }|��}|r\t�|j
sft�W5QRXtjdt	t
jd�d�� }|�|��g�|j
s�t�W5QRXW5QRXdS)Nr��len(ret) != %i�psutil._pslinux.os.readlinkrPr)r�r�rr<r�rrArr��OSErrorr�r�r�r�ZEINVALr�)r�r��filesr�r1r1r2�test_open_files_file_gones"
�
�z%TestProcess.test_open_files_file_gonec
Cs�t��}|��}t|��d��bt|jdt|��tr<dnd}tj	|t
tjd�d�� }|��}|rht
�|jsrt
�W5QRXW5QRXdS)Nr�rr�r�rPr)r�r�rr<r�rrArrr�r�r�r�r�r�)r�r�r!r�r�r1r1r2�test_open_files_fd_gone s
�z#TestProcess.test_open_files_fd_gonec	CsBtjdid��*}|�tj�t������|j	s4t
�W5QRXdS)Nz)psutil._pslinux._psposix.get_terminal_mapr-)rr�r"r�r!r�rr�Zterminalr�r�r�r1r1r2�test_terminal_mocked2s�z TestProcess.test_terminal_mockedc	Cs�t��}t�td��}tjd|dd��$}|�|��ddg�|j	sFt
�W5QRXt�td��}tjd|dd��&}|�|��dddg�|j	s�t
�W5QRXdS)	Nzfoobarr�Trr��barz	foobarrP�r�r�r{r|rrr�r�Zcmdliner�r��r�r�r#r�r1r1r2�test_cmdline_mocked@s"��zTestProcess.test_cmdline_mockedc	Cs�t��}t�td��}tjd|dd��$}|�|��ddg�|j	sFt
�W5QRXt�td��}tjd|dd��&}|�|��dddg�|j	s�t
�W5QRXdS)	Nzfoo bar r�Trr�r%z	foo bar  rPr&r'r1r1r2�test_cmdline_spaces_mockedNs"��z&TestProcess.test_cmdline_spaces_mockedc	CsTt��}t�td��}tjd|dd��$}|�|��ddg�|j	sFt
�W5QRXdS)Nzfoo barr�Trr�r%r&r'r1r1r2�test_cmdline_mixed_separators\s�z)TestProcess.test_cmdline_mixed_separatorsc	CsFtjddd��.|�t����d�|�t����d�W5QRXdS)Nrz/home/foo (deleted)r-z	/home/foo)rr�r�r�r��exe�cwdr�r1r1r2�!test_readlink_path_deleted_mockedfs
�z-TestProcess.test_readlink_path_deleted_mockedc	s��fdd�}t�trdnd}tj||d��(}t����}|jsBt�|�	|g�W5QRX�fdd�}tj||d��|�
tjt��j�W5QRXdS)Ncs4|�dt���r ttjd��n�|f|�|�SdS�Nz
/proc/%s/taskrP)rarr�r�r�r�r~r�r1r2r�qsz2TestProcess.test_threads_mocked.<locals>.open_mockr�r�rcs4|�dt���r ttjd��n�|f|�|�SdSr.)rarr�r�r�ZEPERMr~r�r1r2r��s)r<rrr�r�r�r�r�r�r�r��AccessDenied)r�r�r�r�r�r1r�r2�test_threads_mockedls
zTestProcess.test_threads_mockedcCs�tjdttjd�d���}tjdt�dd�d��`}t����}|j	sFt
�|j	sPt
�|�|d�tjddd��|�tj
t��j�W5QRXW5QRXW5QRXdS)	Nzpsutil._pslinux.readlinkrPrzpsutil.Process.cmdlinerzpsutil._pslinux.os.path.lexistsFr-)rr�r r�r�r�r/r�r+r�r�r�r��
ZombieProcess)r�r0r1r�r1r1r2�test_exe_mocked�s&
�
�

��zTestProcess.test_exe_mockedc
CsZtdt��ttjd���6}t��}|�t	��|�
�W5QRX|jsLt�W5QRXdS)NrrP)
r�rr�r�r�r�r�r�r�rrr�r�)r�r�r�r1r1r2�test_issue_1014�s

�zTestProcess.test_issue_1014r4c
Cs�tjdttjd�d��D}t��}|��|�tj	��}|�
tj�W5QRX|jsVt
�W5QRX|�|jj|j�|�|jj|���dS)Nzpsutil._pslinux.prlimitrPr)rr�r r�ZENOSYSr�r�rr�r1ZrlimitZ
RLIMIT_NOFILEr�r�r��	exceptionr��r�r�r�r�r1r1r2�test_rlimit_zombie�s
�zTestProcess.test_rlimit_zombiec
Cs�tjdttjd�d��@}t��}|��|�tj	��}|�
�W5QRX|jsRt�W5QRX|�
|jj|j�|�
|jj|���dS)NrrPr)rr�r r�r�r�r�rr�r1r,r�r�r�r4r�r5r1r1r2�test_cwd_zombie�s
�zTestProcess.test_cwd_zombiec*Cs\ddlm}dddddddddddddddd	d
dddddddddddddddddddddddddg*}d
�|���}tdt��|���t��}|�	|�
�d�|�	|��tj�|�	|�
�d�|�	|��d|t���|��}|�	|jd|�|�	|jd|�|�	|jd|�|�	|jd|�|�	|jd|�|�	|��d�W5QRXdS)Nr)�CLOCK_TICKSr�z(cat)�Z�1�2�3�4�5�6�7rqz
/proc/%s/stat�catrmr�r�r�r:rnr�)r�r8rCr�r�rr�r�r�r�r�statusZ
STATUS_ZOMBIE�ppidZcreate_timer�r�r��system�
children_user�children_systemZiowaitZcpu_num)r�r8r�r�r�Zcpur1r1r2�test_stat_file_parsing�sz�,�z"TestProcess.test_stat_file_parsingc	Cs�tdt��t�d������t��}|�|�	�j
d�|�|�	�jd�|�|��d�|�
�}|�|jd�|�|jd�|�|jd�|��}|�|jd	�|�|jd
�|�|jd�|�|j��ttdd
���W5QRXdS)Nr�a                Uid:	1000	1001	1002	1003
                Gid:	1004	1005	1006	1007
                Threads:	66
                Cpus_allowed:	f
                Cpus_allowed_list:	0-7
                voluntary_ctxt_switches:	12
                nonvoluntary_ctxt_switches:	13r��
�Bi�i�i�i�i�i�rr�)r�rr�r�r�r�r�r�r��num_ctx_switches�	voluntary�involuntary�num_threads�uids�realZ	effectiveZsaved�gids�_proc�_get_eligible_cpus�listr@)r�r�rNrPr1r1r2�test_status_file_parsings"
�
z$TestProcess.test_status_file_parsingN)r�r�r�rrrrr%rrr"r#r$r(r)r*r-r0r2r3r
r6r7rGrTr1r1r1r2r�s(
#

$

?rc@sreZdZdZedd��Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Ze
�dd��Zdd�Zdd�ZdS)�TestProcessAgainstStatusa/proc/pid/stat and /proc/pid/status have many values in common.
    Whenever possible, psutil uses /proc/pid/stat (it's faster).
    For all those cases we check that the value found in
    /proc/pid/stat (by psutil) matches the one found in
    /proc/pid/status.
    cCst��|_dSrL)r�r��proc)�clsr1r1r2�
setUpClass%sz#TestProcessAgainstStatus.setUpClassc
Cs�tj�d|jj���}|D]h}|��}|�|�r|�d�d}zt|�WW5QR�St	k
r�|YW5QR�SXqt	d|��W5QRXdS)Nr��	r�z
can't find %r)
r��_psplatformZ	open_textrVr�rrra�	partitionrdr?)r�Z	linestartrFrGrr1r1r2�read_status_file)s
�
z)TestProcessAgainstStatus.read_status_filecCs |�d�}|�|j��|�dS)NzName:)r\r�rVr�r�rr1r1r2�	test_name6s
z"TestProcessAgainstStatus.test_namecCsH|�d�}||�d�d|�d��}|�dd�}|�|j��|�dS)NzState:�(rm�)rqr	)r\�find�rfindr�r�rVrBr]r1r1r2�test_status:s
z$TestProcessAgainstStatus.test_statuscCs |�d�}|�|j��|�dS)NzPPid:)r\r�rVrCr]r1r1r2�	test_ppid@s
z"TestProcessAgainstStatus.test_ppidcCs |�d�}|�|j��|�dS)NzThreads:)r\r�rVrMr]r1r1r2�test_num_threadsDs
z)TestProcessAgainstStatus.test_num_threadscCs:|�d�}ttt|��dd���}|�|j��|�dS)NzUid:rmr:)r\rwrxrdr>r�rVrNr]r1r1r2�	test_uidsHs
z"TestProcessAgainstStatus.test_uidscCs:|�d�}ttt|��dd���}|�|j��|�dS)NzGid:rmr:)r\rwrxrdr>r�rVrPr]r1r1r2�	test_gidsMs
z"TestProcessAgainstStatus.test_gidscCs@|�d�}|�|j��j|�|�d�}|�|j��j|�dS)Nzvoluntary_ctxt_switches:znonvoluntary_ctxt_switches:)r\r�rVrJrKrLr]r1r1r2�test_num_ctx_switchesRs

z.TestProcessAgainstStatus.test_num_ctx_switchescCsN|�d�}dt|�krJtt|�d��\}}|�|j��tt	||d���dS)N�Cpus_allowed_list:r	rm)
r\r�rxrdr>r�rVZcpu_affinityrSr@)r�rZmin_Zmax_r1r1r2�test_cpu_affinityYs
�z*TestProcessAgainstStatus.test_cpu_affinityc	CsR|�d�}t�d��}|jj��W5QRXdt|�krD|jrNt�n
|jsNt�dS)Nrizpsutil._pslinux.per_cpu_timesr	)	r\rr�rVrQrRr�r�r�)r�rr�r1r1r2�test_cpu_affinity_eligible_cpus`s
z8TestProcessAgainstStatus.test_cpu_affinity_eligible_cpusN)r�r�r��__doc__�classmethodrXr\r^rcrdrerfrgrrhrjrkr1r1r1r2rUs


rUc@seZdZdd�Zdd�ZdS)�	TestUtilsc	Cs<tjddd��$}|�tj�d�d�|js.t�W5QRXdS)Nzos.readlinkz
foo (deleted)r-r%r�)rr�r�r�rZ�readlinkr�r�r�r1r1r2�
test_readlinkrszTestUtils.test_readlinkc	Csx|��}t|d��}|�d�W5QRX|�tjj|dd�d�|�tjj|dd�d�|�tjj|dd	d
�d	�dS)NZwtzfoo F)Zbinaryr�Tsfooz??r%)Zfallback)r�r<r�r�r�rZrA)r�rrFr1r1r2�test_catws�zTestUtils.test_catN)r�r�r�rprqr1r1r1r2rnosrn�__main__)�
run_from_name)]rlZ
__future__rrbr&r�Zglobr{rrr�r#r,r�r
r�r�rZpsutil._compatrrrrZpsutil.testsrr	r
rrr
rrrrrrrrrrrrrr&r�dirname�__file__ZHEREr+ZSIOCGIFCONFrVr4r6r�ZEMPTY_TEMPERATURESr3r5r7rKrYrkrprtry�contextmanagerr�r�r%r�r�r�rr(r3rWr]rbrgror}r�r�r�r�r�r�r
rrUrnr�Zpsutil.tests.runnerrsr1r1r1r2�<module>s�


	

.]?
)- ?
?}ArR


Filemanager

Name Type Size Permission Actions
__init__.cpython-38.opt-1.pyc File 44.89 KB 0644
__init__.cpython-38.pyc File 46.44 KB 0644
__main__.cpython-38.opt-1.pyc File 285 B 0644
__main__.cpython-38.pyc File 285 B 0644
runner.cpython-38.opt-1.pyc File 10.84 KB 0644
runner.cpython-38.pyc File 10.84 KB 0644
test_aix.cpython-38.opt-1.pyc File 3.3 KB 0644
test_aix.cpython-38.pyc File 3.3 KB 0644
test_bsd.cpython-38.opt-1.pyc File 19.53 KB 0644
test_bsd.cpython-38.pyc File 19.53 KB 0644
test_connections.cpython-38.opt-1.pyc File 15.13 KB 0644
test_connections.cpython-38.pyc File 15.43 KB 0644
test_contracts.cpython-38.opt-1.pyc File 24.81 KB 0644
test_contracts.cpython-38.pyc File 25.64 KB 0644
test_linux.cpython-38.opt-1.pyc File 67.56 KB 0644
test_linux.cpython-38.pyc File 68.67 KB 0644
test_memleaks.cpython-38.opt-1.pyc File 22.59 KB 0644
test_memleaks.cpython-38.pyc File 22.59 KB 0644
test_misc.cpython-38.opt-1.pyc File 22.69 KB 0644
test_misc.cpython-38.pyc File 22.92 KB 0644
test_osx.cpython-38.opt-1.pyc File 7.1 KB 0644
test_osx.cpython-38.pyc File 7.1 KB 0644
test_posix.cpython-38.opt-1.pyc File 12.36 KB 0644
test_posix.cpython-38.pyc File 12.46 KB 0644
test_process.cpython-38.opt-1.pyc File 45.69 KB 0644
test_process.cpython-38.pyc File 46.52 KB 0644
test_sunos.cpython-38.opt-1.pyc File 1.5 KB 0644
test_sunos.cpython-38.pyc File 1.5 KB 0644
test_system.cpython-38.opt-1.pyc File 25.65 KB 0644
test_system.cpython-38.pyc File 26.92 KB 0644
test_testutils.cpython-38.opt-1.pyc File 15.6 KB 0644
test_testutils.cpython-38.pyc File 16.27 KB 0644
test_unicode.cpython-38.opt-1.pyc File 10.87 KB 0644
test_unicode.cpython-38.pyc File 10.87 KB 0644
test_windows.cpython-38.opt-1.pyc File 27.81 KB 0644
test_windows.cpython-38.pyc File 28 KB 0644