Your IP : 3.142.195.79


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

3

��JZ���@s|dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddl
mZddl
m
Z
ddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&ddlm'Z'ddlm(Z(ddlm)Z)ddlm*Z*dd lm+Z+dd!lm,Z,dd"lm-Z-dd#lm.Z.dd$lm/Z/dd%lm0Z0dd&lm1Z1dd'lm2Z2dd(lm3Z3dd)lm4Z4dd*lm5Z5dd+lm6Z6dd,lm7Z7dd-lm8Z8dd.lm9Z9dd/lm:Z:dd0lm;Z;dd1lm<Z<ddl
Z
ddlZ
Gd2d3�d3e8j=�Z>ej?d4d5�Z@Gd6d7�d7e8j=�ZAe8jBe6d8�e8jBe7�o�ejCjDe2�d9�Gd:d;�d;e8j=���ZEGd<d=�d=e8j=�ZFGd>d?�d?e8j=�ZGGd@dA�dAe8j=�ZHGdBdC�dCe8j=�ZIGdDdE�dEe8j=�ZJGdFdG�dGe8j=�ZKeLdHk�rxe0eM�dS)Iz
Miscellaneous tests.
�N)�LINUX)�POSIX)�WINDOWS)�memoize)�memoize_when_activated)�
supports_ipv6)�wrap_numbers)�PY3)�APPVEYOR)�bind_socket)�bind_unix_socket)�
call_until)�chdir)�create_proc_children_pair)�create_sockets)�create_zombie_proc)�DEVNULL)�
get_free_port)�get_test_subprocess)�HAS_BATTERY)�HAS_CONNECTIONS_UNIX)�HAS_MEMORY_FULL_INFO)�HAS_MEMORY_MAPS)�HAS_SENSORS_BATTERY)�HAS_SENSORS_FANS)�HAS_SENSORS_TEMPERATURES)�import_module_by_path)�
is_namedtuple)�mock)�
PYTHON_EXE)�
reap_children)�
reload_module)�retry)�ROOT_DIR)�run_test_module_by_name)�safe_rmpath)�SCRIPTS_DIR)�sh)�tcp_socketpair)�TESTFN)�TOX)�TRAVIS)�unittest)�unix_socket_path)�unix_socketpair)�
wait_for_file)�wait_for_pidc@s�eZdZefdd�Zdd�Zefdd�Zefdd�Zefd	d
�Zefdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)S)*�TestMisccCsntj�}||�}|jd|�|jd|j|�|jd|�|j|j�|�tjjtjdtjt	j
��d��@tj�}||�}|jd|j|�|jd|�|jd|�WdQRXtjjtjdtjt	j
��d��@tj�}||�}|jd|j|�|jd|�|jd|�WdQRXtjjtjdtj
t	j
��d��4tj�}||�}|jd|j|�|jd|�WdQRXdS)Nzpsutil.Processzpid=%szname=�name)�side_effectZzombieZ
terminated)�psutil�Process�assertIn�pidr2r�patch�object�
ZombieProcess�os�getpid�assertNotIn�
NoSuchProcess�AccessDenied)�self�func�p�r�rD�!/usr/lib64/python3.6/test_misc.py�test_process__repr__Os4zTestMisc.test_process__repr__cCs|jtd�dS)N)rA)rF�str)r@rDrDrE�test_process__str__kszTestMisc.test_process__str__cCsN|jttjd��d�|jttjddd��d�|jttjddd��d�dS)NiAz7psutil.NoSuchProcess process no longer exists (pid=321)�foo)r2zCpsutil.NoSuchProcess process no longer exists (pid=321, name='foo'))�msgzpsutil.NoSuchProcess foo)�assertEqual�reprr4r>)r@rArDrDrE�test_no_such_process__repr__nsz%TestMisc.test_no_such_process__repr__cCsj|jttjd��d�|jttjddd��d�|jttjdddd��d�|jttjddd	��d
�dS)NiAzEpsutil.ZombieProcess process still exists but it's a zombie (pid=321)rI)r2zQpsutil.ZombieProcess process still exists but it's a zombie (pid=321, name='foo')�)r2�ppidzYpsutil.ZombieProcess process still exists but it's a zombie (pid=321, name='foo', ppid=1))rJzpsutil.ZombieProcess foo)rKrLr4r:)r@rArDrDrE�test_zombie_process__repr__zsz$TestMisc.test_zombie_process__repr__cCsN|jttjd��d�|jttjddd��d�|jttjddd��d�dS)NiAzpsutil.AccessDenied (pid=321)rI)r2z)psutil.AccessDenied (pid=321, name='foo'))rJzpsutil.AccessDenied foo)rKrLr4r?)r@rArDrDrE�test_access_denied__repr__�sz#TestMisc.test_access_denied__repr__cCsP|jttjd��d�|jttjddd��d�|jttjdddd��d�dS)	NiAz/psutil.TimeoutExpired timeout after 321 seconds�o)r7z9psutil.TimeoutExpired timeout after 321 seconds (pid=111)rI)r7r2zEpsutil.TimeoutExpired timeout after 321 seconds (pid=111, name='foo'))rKrLr4ZTimeoutExpired)r@rArDrDrE�test_timeout_expired__repr__�sz%TestMisc.test_timeout_expired__repr__cCs>tj�}tj�}|j||�d|_|j||�|j|d�dS)NrrI)rr)r4r5rKZ_ident�assertNotEqual)r@�p1�p2rDrDrE�test_process__eq__�szTestMisc.test_process__eq__cCs(ttj�tj�g�}|jt|�d�dS)NrN)�setr4r5rK�len)r@�srDrDrE�test_process__hash__�szTestMisc.test_process__hash__cCs�tt�}x�|D]~}|d
krq|jd
�syt|�Wqtk
r�|tjkr�tt|�}|dkr`w|jdk	r�d|jj�kr�|j	d|�YqXqWxtjD]}|j
||�q�WdS)N�callable�error�
namedtuple�tests�long�test�NUM_CPUS�	BOOT_TIME�TOTAL_PHYMEM�_Z
deprecatedz%r not in psutil.__all__)	r\r]r^r_r`rarbrcrd)�dirr4�
startswith�
__import__�ImportError�__all__�getattr�__doc__�lower�failr6)r@Z
dir_psutilr2ZfunrDrDrE�test__all__�s&




zTestMisc.test__all__cCs$|jdjdd�tjD��tj�dS)N�.cSsg|]}t|��qSrD)rG)�.0�xrDrDrE�
<listcomp>�sz)TestMisc.test_version.<locals>.<listcomp>)rK�joinr4�version_info�__version__)r@rDrDrE�test_version�szTestMisc.test_versioncCs"tj�}d|_|jd|j��dS)N�1rI)r4r5rIr=�as_dict)r@rBrDrDrE�!test_process_as_dict_no_new_names�sz*TestMisc.test_process_as_dict_no_new_namescst�fdd��}g�x:td�D].}|�}fif}|j||�|jt��d�qWx<td�D]0}|d�}d
if}|j||�|jt��d�qZWxDtd�D]8}|ddd�}dddif}|j||�|jt��d�q�W|j�|�}fif}|j||�|jt��d�|j|jd	�dS)Ncs�jd�||fS)z
foo docstringN)�append)�args�kwargs)�callsrDrErI�s
z"TestMisc.test_memoize.<locals>.foo�rN)�barr���z
foo docstring)rN)rN)r�rangerKrY�cache_clearrl)r@rIrr�retZexpectedrD)r~rE�test_memoize�s.zTestMisc.test_memoizecs�G�fdd�d�}|�}g�|j�|j�|jt��d�g�|jj�|j�|j�|jt��d�g�|jj�|j�|j�|jt��d�dS)NcseZdZe�fdd��ZdS)z1TestMisc.test_memoize_when_activated.<locals>.Foocs�jd�dS)N)r{)r@)r~rDrErI�sz5TestMisc.test_memoize_when_activated.<locals>.Foo.fooN)�__name__�
__module__�__qualname__rrIrD)r~rDrE�Foo�sr�rrN)rIrKrYZcache_activateZcache_deactivate)r@r��frD)r~rE�test_memoize_when_activated�s 

z$TestMisc.test_memoize_when_activatedcCs�ddlm}dd�}|j|d�|d�di�|j|d�|d�d|d	�d
i�|j|d�|d�d|d	�di�|j|d
�|d�d|d	�d
i�|j|d�|d�di�|j|d�|d�di�|j|d�|d�di�dS)Nr)�parse_environ_blockcSstr|j�S|S)N)r�upper)rZrDrDrE�ksz,TestMisc.test_parse_environ_block.<locals>.kza=1�arxz	a=1b=2�b�2za=1b=�z
a=1b=2c=3zxxxa=1z	a=1=b=2za=1b=2)�psutil._commonr�rK)r@r�r�rDrDrE�test_parse_environ_blocks



z!TestMisc.test_parse_environ_blockcCs8|jtj�t��rtjd�� }d|_tj�t�s:t�WdQRXtj�tjdtjd��}t�sjt�|j	stt�WdQRXtj�tjdtj
d��$}t�s�t�tj�|j	s�t�WdQRXtj�tjdtj
d��$}t�s�t�tj�|j	s�t�WdQRXn0|jt�� tjtj
tj�}|jd�WdQRXdS)	Nzpsutil._common.socketFzpsutil._common.socket.socket)r3z!psutil._common.socket.socket.bind�::1r)r�r)�
addCleanuprr�rr8Zhas_ipv6�AssertionError�socketr]�calledZgaierror�assertRaises�	Exception�AF_INET6�SOCK_STREAMZbind)r@rZ�sockrDrDrE�test_supports_ipv6%s4zTestMisc.test_supports_ipv6cCs�ddlm}tjjt�}||�s$t�|tjj|��s:t�tj	dt
tjd�d��|j
t
||�WdQRXtj	dt
tjd�d��|j
t
||�WdQRXtj	dt
tjd�d��||�s�t�WdQRXtj	ddd��||�s�t�WdQRXdS)	Nr)�
isfile_strictzpsutil._common.os.statrI)r3zpsutil._common.stat.S_ISREGF)�return_value)r�r�r;�path�abspath�__file__r��dirnamerr8�OSError�errnoZEPERMr�ZEACCES�EINVAL)r@r�Z	this_filerDrDrE�test_isfile_strictEszTestMisc.test_isfile_strictcs��fdd�}|tj�j��|tj��|tj��|tj��|tjdd��|tj��trpt	j
jd�rpnts�|tj
��|tj��|tjt	j���|tj��dS)Ncs<tdk	rtjtj|��tj|�}tj|�}�j||�dS)N)�json�loads�dumps�picklerK)r�r�r�)r@rDrE�checkWs


z*TestMisc.test_serialization.<locals>.checkr)�intervalz/proc/diskstats)r4r5ryZvirtual_memoryZswap_memoryZ	cpu_timesZcpu_times_percent�net_io_countersrr;r��existsr
�disk_io_countersZdisk_partitionsZ
disk_usage�getcwd�users)r@r�rD)r@rE�test_serializationVszTestMisc.test_serializationcCsVtjjtd�}tr*tjj|�r*|jd�St|�}|jt	|j
�|j|j�t
j�dS)Nzsetup.pyzcan't find setup.py)r;r�rtr#r+r�ZskipTestrr��
SystemExitZsetuprKZget_versionr4rv)r@Zsetup_py�modulerDrDrE�test_setup_scriptms
zTestMisc.test_setup_scriptcCs�tjjtjdtjd��}tj�|js*t�WdQRXtjjtjdtjd�d��}tj�|jsbt�WdQRXtjjtjdt	d��.}|j
t	��tj�WdQRX|js�t�WdQRXdS)NZcreate_time)r3rN)rr8r9r4r5r?r�r�r:�
ValueErrorr�)r@�methrDrDrE�test_ad_on_process_creationus
z$TestMisc.test_ad_on_process_creationcCsRtjddd��:|jt��}tt�WdQRX|jdt|j�j	��WdQRXdS)Nzpsutil._psplatform.cext.versionz0.0.0)r�zversion conflict)
rr8r�rir!r4r6rG�	exceptionrm)r@�cmrDrDrE�test_sanity_version_check�s
z"TestMisc.test_sanity_version_checkN)r�r�r�rLrFrHrMrPrQrSrWr[rorwrzr�r�r�r�r�r�r�r�r�rDrDrDrEr1Ms(# r1rIza b cc@s�eZdZdd�ZeZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zejej�p�ej�d�dd��ZdS)�TestWrapNumberscCstj�dS)N)rr�)r@rDrDrE�setUp�szTestWrapNumbers.setUpcCs&dtddd�i}|jt|d�|�dS)N�disk1��disk_io)�ntrKr)r@�inputrDrDrE�test_first_call�szTestWrapNumbers.test_first_callcCs8dtddd�i}|jt|d�|�|jt|d�|�dS)Nr�r�r�)r�rKr)r@r�rDrDrE�test_input_hasnt_changed�sz(TestWrapNumbers.test_input_hasnt_changedcCs�dtddd�i}|jt|d�|�dtddd�i}|jt|d�|�dtddd�i}|jt|d�|�dtddd�i}|jt|d�|�dS)	Nr�r�r��
����)r�rKr)r@r�rDrDrE�test_increase_but_no_wrap�sz)TestWrapNumbers.test_increase_but_no_wrapcCs�dtddd�i}|jt|d�|�dtddd�i}|jt|d�dtddd�i�dtddd�i}|jt|d�dtddd�i�dtddd�i}|jt|d�dtddd�i�dtddd�i}|jt|d�dtddd	�i�dtddd�i}|jt|d�dtddd	�i�dtd
dd�i}|jt|d�dtddd	�i�dtddd�i}|jt|d�dtddd	�i�dtddd�i}|jt|d�dtddd	�i�dS)
Nr��dr�r��n�Z�r����2��()r�rKr)r@r�rDrDrE�	test_wrap�s4zTestWrapNumbers.test_wrapcCstdtddd�i}|jt|d�|�tddd�tddd�d�}|jt|d�|�dtddd�i}|jt|d�|�dS)Nr�r�r��)r��disk2�)r�rKr)r@r�rDrDrE�test_changing_keys�s
z"TestWrapNumbers.test_changing_keyscCs.tddd�tddd�d�}|jt|d�|�tddd�tddd�d�}|jt|d�tddd�tddd�d��dtddd�i}|jt|d�|�tddd�tddd�d�}|jt|d�|�tddd�tddd�d�}|jt|d�|�tddd�tddd�d�}|jt|d�tddd�tddd�d��dS)Nr�r�)r�r�r�r�r�r�)r�rKr)r@r�rDrDrE�test_changing_keys_w_wrap�s*






z)TestWrapNumbers.test_changing_keys_w_wrapcCsbd'd(d)d*d"�}|jt|d#�|�|jt|d#�|�d+d,d-d.d"�}t|d#�}|j|d%dd&�dS)/N�,���#�R������ȷ�r�tU��rr��6��$��Nr��r����U	��"r����4����\)�nvme0n1Z	nvme0n1p1Z	nvme0n1p2Z	nvme0n1p3r�r�r�i�)	r�r�r�r�r�r�r�r�r�)	r�rr�r�r�rrrr�)	r�r�r�r�r�r�r�r�r�)	r�r�r�r�r�r�r�r�r�)	r�r�r�r�r�r�r�r�r�)	r�rr�r�r�rrrr�)	r�r�r�r�r�r�r�r�r�)	r�r�r�r�r�r�r�r�r�)rKr)r@�d�outrDrDrE�test_real_datas
zTestWrapNumbers.test_real_datacCsbdtddd�i}t|d�tj�}|j|dd|i�|j|ddii�|j|ddii�dS)Nr�r�r�rrNr)r�r�
cache_inforK)r@r��cacherDrDrE�test_cache_first_calls
z%TestWrapNumbers.test_cache_first_callc	Cs�dtddd�i}t|d�dtddd�i}t|d�tj�}|j|dd|i�|j|ddddd	dd
dii�|j|ddii�dS)Nr�r�r�r�rrNr)r�r)r�rN)r�r)r�rr�rK)r@r�r�rDrDrE�test_cache_call_twices

z%TestWrapNumbers.test_cache_call_twicec	s�dtddd�i}t|d�dtddd�i}t|d�tj�}�j|dd|i��j|ddd
dddddii��j|dddtdg�ii��fdd	�}dtddd�i}t|d�tj�}�j|dd|i�|�dtddd
�i}t|d�tj�}�j|dd|i�|�dtddd�i}t|d�tj�}�j|dd|i��j|ddddddddii��j|dddtdg�ii�dS)Nr�r�r�r�rrNrc	sJtj�}�j|ddddddd	dii��j|dddtd
g�ii�dS)NrNr�r�rrr�)r�r)r�rN)r�r)r�r)rr�rKrX)r�)r@rDrE�assert_4s

z0TestWrapNumbers.test_cache_wrap.<locals>.assert_r�r�r�)r�r)r�rN)r�r)r�r)r�r)r�rN)r�r)r�r)r�rr�rKrX)r@r�r�rrD)r@rE�test_cache_wrap%s:





zTestWrapNumbers.test_cache_wrapc	Cs�dtddd�i}t|d�tddd�tddd�d�}t|d�tj�}|j|dd|i�|j|ddd	dd
dddii�|j|ddii�dS)Nr�r�r�r�)r�r�rrNr)r�r)r�rN)r�r)r�rr�rK)r@r�r�rDrDrE�test_cache_changing_keysUs


z(TestWrapNumbers.test_cache_changing_keyscCs\dtddd�i}t|d�t|d�tjd�|jtj�iiif�tjd�tjd�dS)Nr�r�r�z?!?)r�rr�rKr�)r@r�rDrDrE�test_cache_clearbs



z TestWrapNumbers.test_cache_clearzno disks or NICs availablecCs�tj�tj�tj�}x$|D]}|jd|�|jd|�qWtjj�tj�}x$|D]}|jd|�|jd|�qVWtjj�tj�}|j|iiif�dS)Nzpsutil.disk_io_counterszpsutil.net_io_counters)	r4r�r�rr�r6r�r=rK)r@Zcachesr�rDrDrE�test_cache_clear_public_apisks



z,TestWrapNumbers.test_cache_clear_public_apisN)r�r�r�r��tearDownr�r�r�r�r�r�r�r�r�rrrr,�skipIfr4r�r�rrDrDrDrEr��s"
%0
	r�zcan't test on TOXzcan't locate scripts directoryc@s�eZdZdZedd��Zed=dd��Zdd�Zej	e
d	�d
d��Zdd
�Zdd�Z
dd�Zdd�Zej	epxeoxej�d�dd��Zdd�Zdd�Zdd�Zej	ed�dd��Zej	ed �d!d"��Zej	ed �d#d$��Zd%d&�Zd'd(�Zd)d*�Zd+d,�Z d-d.�Z!ej	e"d/�d0d1��Z#d2d3�Z$ej	e%d �ej	ed�d4d5���Z&ej	e'd �ej	ed�d6d7���Z(ej	e)d �ej	e*d8�d9d:���Z+d;d<�Z,dS)>�TestScriptsz-Tests for scripts in the "scripts" directory.cOs�dtjjt|�}t|g}x|D]}|j|�q Wyt|f|�j�}Wn8tk
r~}zdt	|�krlt	|�S�WYdd}~XnX|s�t
|��|S)Nz%sr?)r;r�rtr&rr{r'�strip�RuntimeErrorrGr�)�exer|r}�cmd�argr��errrDrDrE�
assert_stdout�s
zTestScripts.assert_stdoutNc	CsRtjjt|�}tr"t|ddd�}n
t|d�}|�|j�}WdQRXtj|�dS)NZrt�utf8)�encoding)	r;r�rtr&r	�open�read�ast�parse)r
r|r��srcrDrDrE�
assert_syntax�s
zTestScripts.assert_syntaxcCsZt|�}xLtjt�D]>}|jd�rdtjj|�d|kr|jdtjjt|��qWdS)Nz.pyZtest_rzno test defined for %r script)	rfr;�listdirr&�endswithr��splitextrnrt)r@Zmethsr2rDrDrE�
test_coverage�s
zTestScripts.test_coveragez
POSIX onlycCsTxNtjt�D]@}|jd�rtjjt|�}tjtj|�tj@s|j	d|�qWdS)Nz.pyz%r is not executable)
r;rr&rr�rt�stat�S_IXUSR�ST_MODErn)r@r2r�rDrDrE�test_executable�s

zTestScripts.test_executablecCs|jd�dS)Nz
disk_usage.py)r)r@rDrDrE�test_disk_usage�szTestScripts.test_disk_usagecCs|jd�dS)Nzfree.py)r)r@rDrDrE�	test_free�szTestScripts.test_freecCs|jd�dS)Nz
meminfo.py)r)r@rDrDrE�test_meminfo�szTestScripts.test_meminfocCs|jdttj���dS)Nzprocinfo.py)rrGr;r<)r@rDrDrE�
test_procinfo�szTestScripts.test_procinfoz unreliable on APPVEYOR or TRAVIScCs|jd�dS)Nzwho.py)r)r@rDrDrE�test_who�szTestScripts.test_whocCs|jd�dS)Nzps.py)r)r@rDrDrE�test_ps�szTestScripts.test_pscCs|jd�dS)Nz	pstree.py)r)r@rDrDrE�test_pstree�szTestScripts.test_pstreecCs|jd�dS)Nz
netstat.py)r)r@rDrDrE�test_netstat�szTestScripts.test_netstatzunreliable on TRAVIScCs|jd�dS)Nzifconfig.py)r)r@rDrDrE�
test_ifconfig�szTestScripts.test_ifconfigz
not supportedcCs|jdttj���dS)Nzpmap.py)rrGr;r<)r@rDrDrE�	test_pmap�szTestScripts.test_pmapcCs|jdtd�dS)Nzprocsmem.py)�stderr)rr)r@rDrDrE�
test_procsmem�szTestScripts.test_procsmemcCs|jd�dS)Nz
killall.py)r)r@rDrDrE�test_killall�szTestScripts.test_killallcCs|jd�dS)Nz	nettop.py)r)r@rDrDrE�test_nettop�szTestScripts.test_nettopcCs|jd�dS)Nztop.py)r)r@rDrDrE�test_top�szTestScripts.test_topcCs|jd�dS)Nziotop.py)r)r@rDrDrE�
test_iotop�szTestScripts.test_iotopcCs,|jdtj�j��}|jttj��|�dS)Nzpidof.py)rr4r5r2r6rGr;r<)r@�outputrDrDrE�
test_pidof�szTestScripts.test_pidofzWINDOWS onlycCs|jd�dS)Nzwinservices.py)r)r@rDrDrE�test_winservices�szTestScripts.test_winservicescCs|jd�dS)Nzcpu_distribution.py)r)r@rDrDrE�test_cpu_distribution�sz!TestScripts.test_cpu_distributioncCs|jd�dS)Nztemperatures.py)r)r@rDrDrE�test_temperatures�szTestScripts.test_temperaturescCs|jd�dS)Nzfans.py)r)r@rDrDrE�	test_fans�szTestScripts.test_fansz
no batterycCs|jd�dS)Nz
battery.py)r)r@rDrDrE�test_batteryszTestScripts.test_batterycCs|jd�dS)Nz
sensors.py)r)r@rDrDrE�test_sensorsszTestScripts.test_sensors)N)-r�r�r�rl�staticmethodrrrr,rrrrr r!r"r
r+r4r�r#r$r%r&r'rr(rr*r+r,r-r.r0rr1r2rr3rr4rrr5r6rDrDrDrEr�s@

rc@sxeZdZejd�dd��Zejd�dd��Zejd�dd��Zejd�dd	��Zejd�d
d��Z	ejd�dd
��Z
dS)�TestRetryDecoratorz
time.sleepcsFtdddd��fdd��}ttd���|j|�d�|j|jd�dS)Nr�rN)�retriesr��logfuncsx�r�j�ddqWdS)NrNr)�poprD)�queuerDrErIsz2TestRetryDecorator.test_retry_success.<locals>.foor�)r"�listr�rK�
call_count)r@�sleeprIrD)r<rE�test_retry_successsz%TestRetryDecorator.test_retry_successcsDtdddd��fdd��}ttd���|jt|�|j|jd�dS)Nr�rN)r9r�r:csx�r�j�ddqWdS)NrNr)r;rD)r<rDrErI&sz2TestRetryDecorator.test_retry_failure.<locals>.foo�)r"r=r�r��ZeroDivisionErrorrKr>)r@r?rIrD)r<rE�test_retry_failure"sz%TestRetryDecorator.test_retry_failurecCs2ttdd�dd��}|jt|�|j|jd�dS)NrN)r�r�cSst�dS)N)�	TypeErrorrDrDrDrErI3sz2TestRetryDecorator.test_exception_arg.<locals>.foor)r"r�r�rDrKr>)r@r?rIrDrDrE�test_exception_arg1sz%TestRetryDecorator.test_exception_argcCs4tdddd�dd��}|jt|�|j|jd�dS)Nr�)r9r�r:cSsdddS)NrNrrDrDrDrDrErI>sz4TestRetryDecorator.test_no_interval_arg.<locals>.foor)r"r�rBrKr>)r@r?rIrDrDrE�test_no_interval_arg:sz'TestRetryDecorator.test_no_interval_argcCs4tdddd�dd��}|jt|�|j|jd�dS)Nr�rN)r9r�r:cSsdddS)NrNrrDrDrDrDrErIHsz0TestRetryDecorator.test_retries_arg.<locals>.foo)r"r�rBrKr>)r@r?rIrDrDrE�test_retries_argEsz#TestRetryDecorator.test_retries_argcCs|jttddd�dS)Nr�rN)r9Ztimeout)r�r�r")r@r?rDrDrE�test_retries_and_timeout_argsOsz0TestRetryDecorator.test_retries_and_timeout_argsN)r�r�r�rr8r@rCrErFrGrHrDrDrDrEr8s	
r8c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�TestSyncTestUtilscCstt�dS)N)r%r))r@rDrDrErVszTestSyncTestUtils.tearDowncCsPttj��ttj��d}tjdtdg�d��|j	tj
t|�WdQRXdS)Ni��zpsutil.tests.retry.__iter__r)r�)r0r;r<�maxr4Zpidsrr8�iterr�r>)r@ZnopidrDrDrE�test_wait_for_pidYsz#TestSyncTestUtils.test_wait_for_pidc	Cs>ttd��}|jd�WdQRXtt�tjjt�s:t�dS)N�wrI)rr)�writer/r;r�r�r�)r@r�rDrDrE�test_wait_for_file_sz$TestSyncTestUtils.test_wait_for_filecCs8ttd��WdQRXttdd�tjjt�s4t�dS)NrMT)�empty)rr)r/r;r�r�r�)r@rDrDrE�test_wait_for_file_emptyes
z*TestSyncTestUtils.test_wait_for_file_emptycCs2tjdtdg�d��|jttt�WdQRXdS)Nzpsutil.tests.retry.__iter__r)r�)rr8rKr��IOErrorr/r))r@rDrDrE�test_wait_for_file_no_fileksz,TestSyncTestUtils.test_wait_for_file_no_filecCs@ttd��}|jd�WdQRXttdd�tjjt�s<t�dS)NrMrIF)�delete)rr)rNr/r;r�r�r�)r@r�rDrDrE�test_wait_for_file_no_deleteosz.TestSyncTestUtils.test_wait_for_file_no_deletecCstdd�d�}|j|d�dS)NcSsdS)NrNrDrDrDrDrE�<lambda>vsz3TestSyncTestUtils.test_call_until.<locals>.<lambda>zret == 1rN)r
rK)r@r�rDrDrE�test_call_untilusz!TestSyncTestUtils.test_call_untilN)
r�r�r�rrLrOrQrSrUrWrDrDrDrErITsrIc@s(eZdZdd�ZeZdd�Zdd�ZdS)�TestFSTestUtilscCstt�dS)N)r%r))r@rDrDrEr�|szTestFSTestUtils.setUpcCs�ttd�j�tt�tjjt�s(t�tt�tjt�tt�tjjt�sTt�t	j
dttj
d�d��.}|jt��tt�WdQRX|js�t�WdQRXdS)NrMzpsutil.tests.os.statr�)r3)rr)�closer%r;r�r�r��mkdirrr8r�r�r�r�r�)r@�mrDrDrE�test_safe_rmpath�s
z TestFSTestUtils.test_safe_rmpathcCsTtj�}tjt�tt�� |jtj�tjj|t��WdQRX|jtj�|�dS)N)r;r�rZr)rrKr�rt)r@�baserDrDrE�
test_chdir�s


$zTestFSTestUtils.test_chdirN)r�r�r�r�rr\r^rDrDrDrErXzsrXc@s2eZdZdd�Zdd�Zejed�dd��ZdS)	�TestProcessUtilscCsRt�}tj|j�}|j�st�t�|j�s2t�tjjs@t�tjj	sNt�dS)N)
rr4r5r7�
is_runningr�r r_�
_pids_started�_subprocesses_started)r@ZsubprBrDrDrE�test_reap_children�sz#TestProcessUtils.test_reap_childrencCs�t�\}}|j|j|j�|j�s&t�|j�s2t�tj�jdd�}|jt	|�d�|j
||�|j
||�|j|j�tj
��|j|j�|j�t�|j�s�t�|j�s�t�tjjs�t�tjjs�t�dS)NT)�	recursiver)rrTr7r`r�r4r5�childrenrKrYr6rOr;r<r r_rarb)r@rUrVrerDrDrE�test_create_proc_children_pair�s
z/TestProcessUtils.test_create_proc_children_pairz
POSIX onlycCs4t�}|jtdd�tj|�}|j|j�tj�dS)NT)rd)rr�r r4r5rKZstatusZ
STATUS_ZOMBIE)r@ZzpidrBrDrDrE�test_create_zombie_proc�s
z(TestProcessUtils.test_create_zombie_procN)	r�r�r�rcrfr,rrrgrDrDrDrEr_�s	r_c@sPeZdZdd�Zejed�dd��Zdd�Zejed�dd	��Z	d
d�Z
dS)
�TestNetUtilsc
Cs>t�}tjtd|fd���}|j|j�d|�WdQRXdS)Nr�)�addrrN)r�
contextlib�closingrrK�getsockname)r@ZportrZrDrDrEr�szTestNetUtils.bind_socketz
POSIX onlycCs�t��z}t|�}tj|��\|j|jtj�|j|jtj	�|j|j
�|�tjj
|�s\t�tjtj|�j�srt�WdQRXWdQRXt��:}t|tjd�}tj|��|j|jtj�WdQRXWdQRXdS)N)�type)r-rrjrkrK�familyr��AF_UNIXrmr�rlr;r�r�r�r�S_ISSOCK�st_mode�
SOCK_DGRAM)r@r2r�rDrDrE�test_bind_unix_socket�s*z"TestNetUtils.test_bind_unix_socketcCs|dt�f}ttj|d�\}}tj|��Ltj|��6|j|j�|�|j|j�|�|j	|j�|�WdQRXWdQRXdS)Nz	127.0.0.1)ri)
rr(r��AF_INETrjrkrKrl�getpeernamerT)r@ri�server�clientrDrDrE�tcp_tcp_socketpair�s
zTestNetUtils.tcp_tcp_socketpaircCs�tj�}|j�}|jdd�s"t�t���}t|�\}}zvtjj	|�sHt�t
jtj
|�j�s^t�|j
|j�|d�|j
t|jdd��d�|j
|j�|�|j
|j�|�Wd|j�|j�XWdQRXdS)NZunix)Zkindr)r4r5�num_fdsZconnectionsr�r-r.r;r�r�rrprqrKrYrlrurY)r@rBryr2rvrwrDrDrE�test_unix_socketpair�sz!TestNetUtils.test_unix_socketpaircCs�t���}tjt�}tjt�}x:|D]2}||jd7<||jtjtj�d7<q"W|j	|tj
d�t�r�|j	|tjd�t
r�tr�|j	|tjd�|j	|tjd�|j	|tjd�WdQRXdS)NrNr)r�collections�defaultdict�intrnZ
getsockoptr�Z
SOL_SOCKETZSO_TYPEZassertGreaterEqualrtrr�rrror�rr)r@ZsocksZfams�typesrZrDrDrE�test_create_sockets�s


 z TestNetUtils.test_create_socketsN)r�r�r�rr,rrrsrxrzrrDrDrDrErh�s
rhc@seZdZdd�ZdS)�TestOtherUtilscCs0ttjdd�ddd��st�tt��s,t�dS)NrIza b crNrr�)rr{r^r��tuple)r@rDrDrE�test_is_namedtuplesz!TestOtherUtils.test_is_namedtupleN)r�r�r�r�rDrDrDrEr�sr��__main__)Nrlrr{rjr�r�r;r�r�rr4rrrr�rrrrZpsutil._compatr	Zpsutil.testsr
rrr
rrrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0ZTestCaser1r^r�r�rr�r�rr8rIrXr_rhr�r�r�rDrDrDrE�<module>	s�Ip
C&!&E


?>