HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/psutil/tests/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/psutil/tests/__pycache__/test_windows.cpython-36.pyc
3

�[g؄�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlm
Z
ddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!e
�r�e�r�ej"��0ej#d�ddl$Z$ddl%Z%ddl&Z&ddl'Z'WdQRXe
�r�ddl(m)Z)ej*j+Z+ej,j-e
dd�ej,j-edd�ej,j-e�o�edd�Gdd�de����Z.dd�Z/e0fd d!�Z1Gd"d#�d#e.�Z2Gd$d%�d%e.�Z3Gd&d'�d'e.�Z4Gd(d)�d)e.�Z5Gd*d+�d+e.�Z6ej,j-e
dd�Gd,d-�d-e��Z7ej,j-e
dd�Gd.d/�d/e��Z8ej,j-e
dd�Gd0d1�d1e��Z9dS)2zWindows specific tests.�N)�WINDOWS)�FileNotFoundError)�super)�which)�APPVEYOR)�GITHUB_ACTIONS)�HAS_BATTERY)�IS_64BIT)�PY3)�PYPY)�TOLERANCE_DISK_USAGE)�TOLERANCE_SYS_MEM)�PsutilTestCase)�mock)�pytest)�retry_on_failure)�sh)�spawn_testproc)�	terminate�ignore)�convert_oserrorzWINDOWS only)�reasonzpywin32 not available on PYPYzpywin32 broken on GITHUB + PY2c@seZdZdS)�WindowsTestCaseN)�__name__�
__module__�__qualname__�rr�E/usr/local/lib64/python3.6/site-packages/psutil/tests/test_windows.pyr;srcCs&td�stjd��dd|}t|�S)z�Currently not used, but available just in case. Usage:

    >>> powershell(
        "Get-CIMInstance Win32_PageFileUsage | Select AllocatedBaseSize")
    zpowershell.exezpowershell.exe not availablez?powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive z,-NoProfile -WindowStyle Hidden -Command "%s")rr�skipr)�cmd�cmdlinerrr�
powershellEs


r!csjtd||f�j�}dj|j�dd��j�}�dk	rbd|krXt�fdd�|j�D��S�|�Sn|SdS)z�Currently not used, but available just in case. Usage:

    >>> wmic("Win32_OperatingSystem", "FreePhysicalMemory")
    2134124534
    zwmic path %s get %s��N�,csg|]}�|��qSrr)�.0�x)�	converterrr�
<listcomp>^szwmic.<locals>.<listcomp>)r�strip�join�
splitlines�tuple�split)�path�whatr'�out�datar)r'r�wmicTs
r2c@sReZdZejjdejkdd�dd��Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dS)�TestCpuAPIs�NUMBER_OF_PROCESSORSz-NUMBER_OF_PROCESSORS env var is not available)rcCs"ttjd�}|tj�kst�dS)Nr4)�int�os�environ�psutil�	cpu_count�AssertionError)�selfZnum_cpusrrr�&test_cpu_count_vs_NUMBER_OF_PROCESSORSksz2TestCpuAPIs.test_cpu_count_vs_NUMBER_OF_PROCESSORScCs$tj�d}tj�}||ks t�dS)N�)�win32apiZ
GetSystemInfor8r9r:)r;�	sys_value�psutil_valuerrr�test_cpu_count_vs_GetSystemInfousz+TestCpuAPIs.test_cpu_count_vs_GetSystemInfocCs2tj�}tdd�|j�D��}tj�|ks.t�dS)Ncss|]}|jVqdS)N)ZNumberOfLogicalProcessors)r%�procrrr�	<genexpr>sz<TestCpuAPIs.test_cpu_count_logical_vs_wmi.<locals>.<genexpr>)�wmi�WMI�sum�Win32_Processorr8r9r:)r;�wZprocsrrr�test_cpu_count_logical_vs_wmi|sz)TestCpuAPIs.test_cpu_count_logical_vs_wmicCs6tj�}tdd�|j�D��}tjdd�|ks2t�dS)Ncss|]}|jVqdS)N)Z
NumberOfCores)r%rBrrrrC�sz:TestCpuAPIs.test_cpu_count_cores_vs_wmi.<locals>.<genexpr>F)Zlogical)rDrErFrGr8r9r:)r;rHZcoresrrr�test_cpu_count_cores_vs_wmi�sz'TestCpuAPIs.test_cpu_count_cores_vs_wmicCs tj�ttjdd��kst�dS)NT)Zpercpu)r8r9�len�	cpu_timesr:)r;rrr�test_cpu_count_vs_cpu_times�sz'TestCpuAPIs.test_cpu_count_vs_cpu_timescCs@tj�}|j�d}|jtj�jks(t�|jtj�j	ks<t�dS)Nr)
rDrErGZCurrentClockSpeedr8Zcpu_freq�currentr:Z
MaxClockSpeed�max)r;rHrBrrr�
test_cpu_freq�szTestCpuAPIs.test_cpu_freqN)rrrr�mark�skipifr6r7r<rArIrJrMrPrrrrr3jsr3c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zej	j
edd�e�d
d���Z
e�dd��Ze�dd��Zdd�Zdd�Zdd�Zdd�ZdS)�TestSystemAPIscCsVtd�}tjdd�j�}x8|D]0}d|jdd�j�kr8q||kr|jd|��qWdS)Nz
ipconfig /allT)Zperniczpseudo-interface� �-z-%r nic wasn't found in 'ipconfig /all' output)rr8Znet_io_counters�keys�replace�lower�fail)r;r0ZnicsZnicrrr�test_nic_names�s
zTestSystemAPIs.test_nic_namescCs,tj�j�d}t|j�tj�jks(t�dS)Nr)	rDrEZWin32_ComputerSystemr5ZTotalPhysicalMemoryr8�virtual_memory�totalr:)r;rHrrr�test_total_phymem�sz TestSystemAPIs.test_total_phymemcCs4tj�j�d}tt|j�tj�j�t	ks0t
�dS)Nr)rDrE�Win32_PerfRawData_PerfOS_Memory�absr5ZAvailableBytesr8r[�freer
r:)r;rHrrr�test_free_phymem�szTestSystemAPIs.test_free_phymemcCshtj�j�d}t|j�tj�jtj�jks2t	�tj�jdkrdtj�j
dksRt	�tj�jdksdt	�dS)Nr)rDrEr^r5ZCommitLimitr8r[r\�swap_memoryr:r`�used)r;rHrrr�test_total_swapmem�sz!TestSystemAPIs.test_total_swapmemcCs|tj�jdkrxtj�jdd�d}t|j�dt|j�}tj�j	dksLt
�ttj�j	|�dksft
�tj�j	dksxt
�dS)NrZ_Total)�Name�dr=)r8rbr\rDrEZ#Win32_PerfRawData_PerfOS_PagingFiler5ZPercentUsageZPercentUsage_Base�percentr:r_)r;rHZpercentSwaprrr�test_percent_swapmem�sz#TestSystemAPIs.test_percent_swapmemztest not relieable on appveyor)rcCs:tj�j�}tdd�|D��}ttj��}||ks6t�dS)NcSsg|]
}|j�qSr)�	ProcessId)r%r&rrrr(�sz,TestSystemAPIs.test_pids.<locals>.<listcomp>)rDrE�
Win32_Process�setr8�pidsr:)r;rHZwmi_pidsZpsutil_pidsrrr�	test_pids�szTestSystemAPIs.test_pidscCs�tjdd�}tj�j�}x�|D]�}x�|D]�}|jjdd�|jkr(|jsHPd|j	krTP|jj
d�rbPytj|j�}Wntk
r�PYnX|j
t|j�ks�t�t|j�}|j|ks�t�t|j|�dkr�|jd	|j|f��Pq(W|jd
t|���qWdS)
NT)�all�\r"�cdromzA:�
izpsutil=%s, wmi=%szcan't find partition %si(i�)r8�disk_partitionsrDrEZWin32_LogicalDisk�devicerWZDeviceID�
mountpoint�opts�
startswith�
disk_usagerr\r5�Sizer:Z	FreeSpacer`r_rY�repr)r;Zps_partsZ	wmi_partsZps_partZwmi_part�usageZwmi_freerrr�
test_disks�s.



zTestSystemAPIs.test_diskscCs�x~tj�D]r}d|jkrq
tj|j�}tj|j�}t|d|j�t	ksLt
�t|d|j�t	ksft
�|j|j|jks
t
�q
WdS)Nrprr#)
r8rrrur>ZGetDiskFreeSpaceExrtrwr_r`rr:r\rc)r;Zdiskr?r@rrr�test_disk_usage�s
zTestSystemAPIs.test_disk_usagecCs>dd�tj�jd�D�}dd�tjdd�D�}||ks:t�dS)NcSs$g|]}|r|jd�r|d�qS)zA:ro)rv)r%r&rrrr(sz7TestSystemAPIs.test_disk_partitions.<locals>.<listcomp>z\cSsg|]}|jjd�s|j�qS)zA:)rtrv)r%r&rrrr(sT)rn)r>ZGetLogicalDriveStringsr-r8rrr:)r;r?r@rrr�test_disk_partitionss
z#TestSystemAPIs.test_disk_partitionscCs`ttj��}tj�j�}t�}x$|D]}|j|j�|j|j�q$W||@s\t	d||f��dS)Nzno common entries in %s, %s)
rk�cextZnet_if_statsrDrEZWin32_NetworkAdapter�addreZNetConnectionIDr:)r;Zps_namesZwmi_adaptersZ	wmi_namesZwmi_adapterrrr�test_net_if_stats
s
z TestSystemAPIs.test_net_if_statscCs^tj�j�}|djjd�d}tjj|d�}tjjtj	��}t
||j��}|dksZt�dS)Nr�.z%Y%m%d%H%M%Sr=)
rDrEZWin32_OperatingSystemZLastBootUpTimer-�datetime�strptime�
fromtimestampr8�	boot_timer_�
total_secondsr:)r;Zwmi_osZ
wmi_btime_strZwmi_btime_dtZ	psutil_dtZdiffrrr�test_boot_timeszTestSystemAPIs.test_boot_timecCs�tjddd��tj�dks t�WdQRXtjddd��tj�dksJt�WdQRXtjddd��tj�dkstt�WdQRXtjddd��tj�dks�t�WdQRXdS)Nz psutil._pswindows.cext.boot_timer=)�return_value��iM)r�patchr8r�r:)r;rrr�test_boot_time_fluctuation#sz)TestSystemAPIs.test_boot_time_fluctuationN)rrrrZr]rardrhrrQrRrrrmr{r|r}r�r�r�rrrrrS�s
	


rSc@sheZdZdd�Zejjedd�dd��Zejjedd�dd��Z	d	d
�Z
dd�Zd
d�Zdd�Z
dS)�TestSensorsBatterycCs2tj�drtj�dk	s.t�ntj�dks.t�dS)NZSystemBatteriesPresent)r>ZGetPwrCapabilitiesr8�sensors_batteryr:)r;rrr�test_has_battery5sz#TestSensorsBattery.test_has_batteryz
no battery)rcCs:tj�}|jd�d}tj�}t|j|j�dks6t�dS)Nzselect * from Win32_Batteryrr#)	rDrE�queryr8r�r_rgZEstimatedChargeRemainingr:)r;rH�battery_wmi�battery_psutilrrr�test_percent;s
zTestSensorsBattery.test_percentcCs6tj�}|jd�d}tj�}|j|jdkks2t�dS)Nzselect * from Win32_Batteryr�)rDrEr�r8r��
power_pluggedZ
BatteryStatusr:)r;rHr�r�rrr�test_power_pluggedEsz%TestSensorsBattery.test_power_pluggedc	Cs8tjddd�� }tj�dks t�|js*t�WdQRXdS)Nz&psutil._pswindows.cext.sensors_batteryr�)r�)rr�rr)rr�r8r�r:�called)r;�mrrr�test_emulate_no_batteryNsz*TestSensorsBattery.test_emulate_no_batteryc	Cs<tjddd��$}tj�jtjks$t�|js.t�WdQRXdS)Nz&psutil._pswindows.cext.sensors_batteryr#r)r�)r#rrr)rr�r8r��secsleft�POWER_TIME_UNLIMITEDr:r�)r;r�rrr�test_emulate_power_connectedVs
z/TestSensorsBattery.test_emulate_power_connectedc	Cs<tjddd��$}tj�jtjks$t�|js.t�WdQRXdS)Nz&psutil._pswindows.cext.sensors_batteryr�)r�)rr�rr)rr�r8r�r�r�r:r�)r;r�rrr�test_emulate_power_charging`s
z.TestSensorsBattery.test_emulate_power_chargingc	Cs<tjddd��$}tj�jtjks$t�|js.t�WdQRXdS)Nz&psutil._pswindows.cext.sensors_batteryrr#)r����)rrrr�)rr�r8r�r��POWER_TIME_UNKNOWNr:r�)r;r�rrr�test_emulate_secs_left_unknownjsz1TestSensorsBattery.test_emulate_secs_left_unknownN)rrrr�rrQrRrr�r�r�r�r�r�rrrrr�4s
	

r�c@s�eZdZedd��Zedd��Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#S)$�TestProcesscCst�j|_dS)N)r�pid)�clsrrr�
setUpClass{szTestProcess.setUpClasscCst|j�dS)N)rr�)r�rrr�
tearDownClassszTestProcess.tearDownClassc	Cs.tjd�}tjtj��|j�WdQRXdS)Nr)r8�Processr�raises�AccessDenied�kill)r;�prrr�
test_issue_24�s
zTestProcess.test_issue_24cCs�tjd�}|j�dkst�t|�|j�|j�dks:t�y|j�dd�\}}Wn(tjk
rzt	j
�dd
krv�YnX|d	ks�t�dS)Nr��Systemgr�r#�vista�win-7�win7r)r�r�r�)r8r��namer:�str�username�create_time�memory_infor��platform�uname)r;r��rssZ_vmsrrr�test_special_pid�s
zTestProcess.test_special_pidc	Cs2tj|j�}tjt��|jtj�WdQRXdS)N)	r8r�r�rr��
ValueError�send_signal�signal�SIGINT)r;r�rrr�test_send_signal�szTestProcess.test_send_signalcCsbtjtj��}|j�}tjtjtj	tj��}|j�}||dksDt
�tj|�|j�|ks^t
�dS)Nr#)r8r�r6�getpid�num_handlesr>�OpenProcess�win32con�PROCESS_QUERY_INFORMATION�FALSEr:�CloseHandle)r;r��before�handle�afterrrr�test_num_handles_increment�s
z&TestProcess.test_num_handles_incrementcCs�tj|j�j�}|jtj�|jtj�|j�|j	�t
jtj��|jtj�WdQRXt
jtj��|jtj�WdQRXdS)N)
r8r�rr�r�r�ZCTRL_C_EVENTZCTRL_BREAK_EVENTr��waitrr��
NoSuchProcess)r;r�rrr�test_ctrl_signals�szTestProcess.test_ctrl_signalscCs8tjtj�}|jd�r tjd��tj�j	�|ks4t
�dS)N�$zrunning as service account)r>Z
GetUserNameExr�ZNameSamCompatible�endswithrrr8r�r�r:)r;r�rrr�
test_username�s

zTestProcess.test_usernamecCsftjddtj��j�}djtj�j��}|ddkoB|dknrV|j	ddd�}||ksbt
�dS)Nz[ ]+rTr�"r"r�)�re�subr>ZGetCommandLiner)r*r8r�r rWr:)r;r?r@rrr�test_cmdline�s
 zTestProcess.test_cmdlinecCsJtjtjtjtj��}|jtj|�t	j
|�}tj�j
�}||ksFt�dS)N)r>r�r�r�r�r6r��
addCleanupr��win32processZGetPriorityClassr8r��nicer:)r;r�r?r@rrr�	test_nice�s
zTestProcess.test_nicecCs�tjtjtj|j�}|jtj|�tj	|�}t
j|j�j�}|d|j
ksNt�|d|jks`t�|d|jksrt�|d|jks�t�|d|jks�t�|d|jks�t�|d|jks�t�|d|jks�t�|j|jks�t�|j|jks�t�dS)	NZPeakWorkingSetSize�WorkingSetSizeZQuotaPeakPagedPoolUsageZQuotaPagedPoolUsageZQuotaPeakNonPagedPoolUsageZQuotaNonPagedPoolUsageZ
PagefileUsageZPeakPagefileUsage)r>r�r�r�r�r�r�r�r�ZGetProcessMemoryInfor8r�r�Z	peak_wsetr:ZwsetZpeak_paged_poolZ
paged_poolZpeak_nonpaged_poolZ
nonpaged_poolZpagefileZ
peak_pagefiler��vms)r;r�r?r@rrr�test_memory_info�s"
zTestProcess.test_memory_infocCsXtjtjtj|j�}|jtj|�tj	|j�}|j
�|j�}tj
|�}||ksTt�dS)N)r>r�r�r�r�r�r�r�r8r�rr�r�ZGetExitCodeProcessr:)r;r�r�r@r?rrr�	test_wait�s
zTestProcess.test_waitcCs\dd�}tjtjtj|j�}|jtj|�|tj	|�d�}t
j|j�j�}||ksXt
�dS)Ncs�fdd�td�D�S)Ncsg|]}d|>�@r|�qS)r#r)r%�i)r&rrr(szGTestProcess.test_cpu_affinity.<locals>.from_bitmask.<locals>.<listcomp>�@)�range)r&r)r&r�from_bitmasksz3TestProcess.test_cpu_affinity.<locals>.from_bitmaskr)r>r�r�r�r�r�r�r�r�ZGetProcessAffinityMaskr8r�Zcpu_affinityr:)r;r�r�r?r@rrr�test_cpu_affinityszTestProcess.test_cpu_affinitycCs�tjtjtjtj��}|jtj|�t	j
|�}tj�j
�}|j|dksLt�|j|dks^t�|j|dkspt�|j|dks�t�|j|dks�t�|j|dks�t�dS)NZReadOperationCountZWriteOperationCountZReadTransferCountZWriteTransferCountZOtherOperationCountZOtherTransferCount)r>r�r�r�r�r6r�r�r�r�ZGetProcessIoCountersr8r��io_counters�
read_countr:�write_count�
read_bytes�write_bytes�other_countZother_bytes)r;r�r?r@rrr�test_io_counterss
zTestProcess.test_io_counterscCs�ddl}ddl}d}|jjj|d|j�}|j|jjj|�|jj	�}|jjj
||j|��|j}t
j|j�j�}||ks|t�dS)Nri)�ctypesZctypes.wintypes�windll�kernel32r�r�r�r�ZwintypesZDWORDZGetProcessHandleCount�byref�valuer8r�r�r:)r;r�r�r�Zhndcntr?r@rrr�test_num_handles"s
zTestProcess.test_num_handlescCsvt�}d|_tjd|d��Dtjd��.}tj�}tjtj��|j	�WdQRXWdQRXWdQRX|j
dksrt�dS)Ni+z psutil._psplatform.cext.proc_cwd)�side_effectz
time.sleepr=)�WindowsError�winerrorrr�r8r�rr�r��cwdZ
call_countr:)r;�excr�r�rrr�test_error_partial_copy4s&z#TestProcess.test_error_partial_copyc	Cs@tj�dd}tjj|�}tjtj��|j�WdQRXdS)Nr#i��r�)r8rl�_psplatformr�rr�r��exe)r;r�rBrrr�test_exe?szTestProcess.test_exeN)rrr�classmethodr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�zs"		r�c@s|eZdZdZedd��Zedd��Zdd�Zej	j
edd	�d
d��Zdd
�Z
dd�Ze�dd��Ze�dd��Zdd�ZdS)�TestProcessWMIz%Compare Process API results with WMI.cCst�j|_dS)N)rr�)r�rrrr�KszTestProcessWMI.setUpClasscCst|j�dS)N)rr�)r�rrrr�OszTestProcessWMI.tearDownClasscCs8tj�j|jd�d}tj|j�}|j�|jks4t�dS)N)rir)	rDrErjr�r8r�r�ZCaptionr:)r;rHr�rrr�	test_nameSszTestProcessWMI.test_namez!unreliable path on GITHUB_ACTIONS)rcCs@tj�j|jd�d}tj|j�}|j�j�|jj�ks<t	�dS)N)rir)
rDrErjr�r8r�r�rXZExecutablePathr:)r;rHr�rrrr�YszTestProcessWMI.test_execCsFtj�j|jd�d}tj|j�}dj|j��|jj	dd�ksBt
�dS)N)rirrTr�r")rDrErjr�r8r�r*r ZCommandLinerWr:)r;rHr�rrrr�cszTestProcessWMI.test_cmdlinecCsPtj�j|jd�d}tj|j�}|j�\}}}d||f}|j�|ksLt�dS)N)rirz%s\%s)	rDrErjr�r8r�ZGetOwnerr�r:)r;rHr��domain�_r�rrrr�hs
zTestProcessWMI.test_usernamecCsBtj�j|jd�d}tj|j�}|j�j}|t|j	�ks>t
�dS)N)rir)rDrErjr�r8r�r�r�r5r�r:)r;rHr�r�rrr�test_memory_rssos
zTestProcessWMI.test_memory_rsscCs\tj�j|jd�d}tj|j�}|j�j}t|j	�}|||dfkrX|j
d||f��dS)N)ririzwmi=%s, psutil=%s)rDrErjr�r8r�r�r�r5Z
PageFileUsagerY)r;rHr�r�Z	wmi_usagerrr�test_memory_vmsvs

zTestProcessWMI.test_memory_vmscCs\tj�j|jd�d}tj|j�}t|jjd�d�}t	j
dt	j|j���}||ksXt
�dS)N)rirr�z%Y%m%d%H%M%S)rDrErjr�r8r�r�ZCreationDater-�time�strftime�	localtimer�r:)r;rHr�Zwmic_createZ
psutil_createrrr�test_create_time�szTestProcessWMI.test_create_timeN)rrr�__doc__r�r�r�r�rrQrRrr�r�r�rr�r�rrrrrr�Hs	
r�c@sXeZdZdZedd��Zedd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�ZdS)�TestDualProcessImplementationawCertain APIs on Windows have 2 internal implementations, one
    based on documented Windows APIs, another one based
    NtQuerySystemInformation() which gets called as fallback in
    case the first fails because of limited permission error.
    Here we test that the two methods return the exact same value,
    see:
    https://github.com/giampaolo/psutil/issues/304.
    cCst�j|_dS)N)rr�)r�rrrr��sz(TestDualProcessImplementation.setUpClasscCst|j�dS)N)rr�)r�rrrr��sz+TestDualProcessImplementation.tearDownClasscCs�tj|j�j�}tjdttjd�d���}tj|j�j�}t	|�t	|�ksLt
�xPtt	|��D]@}||dksnt
�||dks~t
�t||||�dksZt
�qZW|j
s�t
�WdQRXdS)Nz(psutil._psplatform.cext.proc_memory_info�msg)r�ri)r8r�r�r�rr��OSError�errno�EPERMrKr:r�r_r�)r;Zmem_1�funZmem_2r�rrrr��s z.TestDualProcessImplementation.test_memory_infoc	CsXtj|j�j�}tjdttjd�d��(}tj|j�j�|ks@t	�|j
sJt	�WdQRXdS)Nz"psutil._psplatform.cext.proc_timesr)r�)r8r�r�r�rr�rrrr:r�)r;�ctimer	rrrr�sz.TestDualProcessImplementation.test_create_timec
Cs�tj|j�j�}tjdttjd�d��P}tj|j�j�}|j	sBt
�t|j|j�dksZt
�t|j
|j
�dksrt
�WdQRXdS)Nz"psutil._psplatform.cext.proc_timesr)r�g{�G�z�?)r8r�r�rLrr�rrrr�r:r_�user�system)r;Zcpu_times_1r	Zcpu_times_2rrr�test_cpu_times�s
z,TestDualProcessImplementation.test_cpu_timescCs�tj|j�j�}tjdttjd�d��R}tj|j�j�}x0t	t
|��D] }t||||�dksFt�qFW|j
stt�WdQRXdS)Nz(psutil._psplatform.cext.proc_io_countersr)r�r=)r8r�r�r�rr�rrrr�rKr_r:r�)r;Z
io_counters_1r	Z
io_counters_2r�rrrr��s z.TestDualProcessImplementation.test_io_countersc	CsXtj|j�j�}tjdttjd�d��(}tj|j�j�|ks@t	�|j
sJt	�WdQRXdS)Nz(psutil._psplatform.cext.proc_num_handlesr)r�)r8r�r�r�rr�rrrr:r�)r;r�r	rrrr��sz.TestDualProcessImplementation.test_num_handlescCs�x|tj�D]p}y tj|dd�}tj|dd�}Wn>tk
rl}z"t|�}t|tjtjf�s\�WYdd}~Xq
X||ks
t	�q
WdS)NT)Zuse_pebF)
r8rlr~Zproc_cmdlinerr�
isinstancer�r�r:)r;r��a�b�errrrrr��sz*TestDualProcessImplementation.test_cmdlineN)
rrrrr�r�r�r�rr
r�r�r�rrrrr�s			rcspeZdZdZedd��ZddgZ�fdd�Z�fdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Z�ZS)�RemoteProcessTestCasez�Certain functions require calling ReadProcessMemory.
    This trivially works when called on the current process.
    Check that this works on other processes, especially when they
    have a different bitness.
    cCs\d}xRtjd�D]D}tj|d|gtjtjd�}|j�\}}|j�|tt�kr|SqWdS)Nz6import sys; sys.stdout.write(str(sys.maxsize > 2**32))zC:\Python*\python.exez-c)�args�stdout�stderr)	�glob�
subprocess�Popen�PIPE�STDOUT�communicater�r�r	)�code�filenamerB�outputr�rrr�find_other_interpreter�s
z,RemoteProcessTestCase.find_other_interpreterz-czimport sys; sys.stdin.read()cs�t�j�|j�}|dkr$tjd��tr8tj|_||_	n||_tj|_	t
jj�}t
t
j��|d<|j|j	g|j|tjd�|_|j|jg|j|tjd�|_dS)Nz0could not find interpreter with opposite bitness�THINK_OF_A_NUMBER)�env�stdin)r�setUprrrr	�sys�
executableZpython64Zpython32r6r7�copyr�r�r�	test_argsrr�proc32�proc64)r;Zother_pythonr!)�	__class__rrr#s 

zRemoteProcessTestCase.setUpcs"t�j�|jj�|jj�dS)N)r�tearDownr(rr))r;)r*rrr+s

zRemoteProcessTestCase.tearDowncCs@tj|jj�}t|j��dks"t�|j�dd�|jks<t�dS)N�r#)r8r�r(r�rKr r:r')r;r�rrr�test_cmdline_32!sz%RemoteProcessTestCase.test_cmdline_32cCs@tj|jj�}t|j��dks"t�|j�dd�|jks<t�dS)Nr,r#)r8r�r)r�rKr r:r')r;r�rrr�test_cmdline_64&sz%RemoteProcessTestCase.test_cmdline_64cCs&tj|jj�}|j�tj�ks"t�dS)N)r8r�r(r�r�r6�getcwdr:)r;r�rrr�test_cwd_32+sz!RemoteProcessTestCase.test_cwd_32cCs&tj|jj�}|j�tj�ks"t�dS)N)r8r�r)r�r�r6r/r:)r;r�rrr�test_cwd_64/sz!RemoteProcessTestCase.test_cwd_64cCs>tj|jj�}|j�}d|ks"t�|dttj��ks:t�dS)Nr )	r8r�r(r�r7r:r�r6r�)r;r��errr�test_environ_323sz%RemoteProcessTestCase.test_environ_32cCs6tj|jj�}y|j�Wntjk
r0YnXdS)N)r8r�r)r�r7r�)r;r�rrr�test_environ_649s
z%RemoteProcessTestCase.test_environ_64)rrrr�staticmethodrr'r#r+r-r.r0r1r3r4�
__classcell__rr)r*rr�src@seZdZdd�Zdd�ZdS)�TestServicescCs~tdddddddg�}tdd	d
g�}tddddd
ddg�}�x<tj�D�].}|j�}t|dt�sft�|dj�svt�t|dt�s�t�t|dt�s�t�|d|ks�t�|ddk	r�tj|d�t|dt�s�t�t|dt�s�t�t|dt�s�t�|d|k�st�|d|k�st�t|dt��s2t�|j	�}|dk	�r\tj|�}|j
��s\t�tj|j��}||ksFt�qFWdS)N�runningZpaused�start�pause�continue�stop�stoppedZ	automaticZmanual�disabledZ
start_pendingZ
pause_pendingZcontinue_pendingZstop_pendingr��display_namer��statusr�ZbinpathZ
start_type�description)
rkr8�win_service_iterZas_dictrr�r:r)r�r�Z
is_running�win_service_getr�)r;Zvalid_statusesZvalid_start_typesZservr1r�r��srrr�test_win_service_iterHsL

z"TestServices.test_win_service_itercBCs�tjjj}tjjj}ttj��j�}tj	tj
��}tj|d�WdQRX|jj|dks^t
�tj|�}trzddd|f}n|df}t|�}tjd|d��&tj	tj
��|j�WdQRXWdQRXtjd|d��&tj	tj
��|j�WdQRXWdQRXt�rddd|f}n|df}t|�}tjd|d��&tj	tj��|j�WdQRXWdQRXtjd|d��&tj	tj��|j�WdQRXWdQRX|j�t|�k�s�t
�|j�t|�k�s�t
�|j�t|�k�s�t
�|j�t|�k�s�t
�dS)Nz???rrz/psutil._psplatform.cext.winservice_query_status)r�z/psutil._psplatform.cext.winservice_query_config)r8r�r~�ERROR_SERVICE_DOES_NOT_EXIST�ERROR_ACCESS_DENIED�nextrBr�rr�r�rCr�r:r
r�rr�r@r�r�r�r?ry)r;rFrGr��cmZservicerr�rrr�test_win_service_gettsF


z!TestServices.test_win_service_getN)rrrrErJrrrrr7Fs,r7):rr�rrr6r�r�r�rr$r��warningsr8rZpsutil._compatrrrZpsutil.testsrrrr	r
rrr
rrrrrrr�catch_warnings�simplefilterr>r�r�rDZpsutil._pswindowsrr�r~rQrRrr!r5r2r3rSr�r�r�rrr7rrrr�<module>sz

(#FOHW]