
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
U
    =_M                  	   @   s  d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ erzesze  0 e!d ddl"Z"ddl#Z#ddl$Z$ddl%Z%W 5 Q R X ej&j'Z'dd Z(e)e de)ede)eoe dG dd deZ*G dd de*Z+G dd de*Z,G d d! d!e*Z-G d"d# d#e*Z.G d$d% d%e*Z/e)e dG d&d' d'eZ0e)e dG d(d) d)eZ1e)e dG d*d+ d+eZ2e3d,krdd-l4m5Z5 e5e6 dS ).zWindows specific tests.    N)WINDOWS)FileNotFoundError)super)APPVEYOR)GITHUB_ACTIONS)HAS_BATTERY)IS_64BIT)mock)PsutilTestCase)PY3)PYPY)retry_on_failure)sh)spawn_testproc)	terminate)TOLERANCE_DISK_USAGE)unittestignorec                    s    fdd}|S )Nc              
      sv   z | f||W S  t k
rp } z@ddlm} |j|krFtd d |jtjkr^td d  W 5 d }~X Y nX d S )Nr   )ACCESS_DENIED_SET)OSErrorpsutil._pswindowsr   errnopsutilAccessDeniedZESRCHNoSuchProcess)selfargskwargserrr   fun L/opt/alt/python38/lib64/python3.8/site-packages/psutil/tests/test_windows.pywrapper7   s    
z wrap_exceptions.<locals>.wrapperr!   )r    r#   r!   r   r"   wrap_exceptions6   s    
r$   zWINDOWS onlyzpywin32 not available on PYPYzpywin32 broken on GITHUB + PY2c                   @   s   e Zd ZdS )WindowsTestCaseN)__name__
__module____qualname__r!   r!   r!   r"   r%   D   s   r%   c                   @   sN   e Zd Zedejkddd Zdd Zdd Z	d	d
 Z
dd Zdd ZdS )TestCpuAPIsNUMBER_OF_PROCESSORSz-NUMBER_OF_PROCESSORS env var is not availablec                 C   s"   t tjd }| |t  d S )Nr*   )intosenvironassertEqualr   	cpu_count)r   Znum_cpusr!   r!   r"   &test_cpu_count_vs_NUMBER_OF_PROCESSORSS   s    z2TestCpuAPIs.test_cpu_count_vs_NUMBER_OF_PROCESSORSc                 C   s$   t  d }t }| || d S )N   )win32apiZGetSystemInfor   r/   r.   r   	sys_valuepsutil_valuer!   r!   r"   test_cpu_count_vs_GetSystemInfo[   s    z+TestCpuAPIs.test_cpu_count_vs_GetSystemInfoc                 C   s*   t  }| d }| t |j d S Nr   )wmiWMIWin32_Processorr.   r   r/   ZNumberOfLogicalProcessorsr   wprocr!   r!   r"   test_cpu_count_logical_vs_wmib   s    z)TestCpuAPIs.test_cpu_count_logical_vs_wmic                 C   s.   t  }| d }| tjdd|j d S )Nr   F)Zlogical)r8   r9   r:   r.   r   r/   ZNumberOfCoresr;   r!   r!   r"   test_cpu_count_phys_vs_wmig   s    z&TestCpuAPIs.test_cpu_count_phys_vs_wmic                 C   s    |  t ttjdd d S )NT)Zpercpu)r.   r   r/   len	cpu_timesr   r!   r!   r"   test_cpu_count_vs_cpu_timesl   s    
z'TestCpuAPIs.test_cpu_count_vs_cpu_timesc                 C   s@   t  }| d }| |jt j | |jt j	 d S r7   )
r8   r9   r:   r.   ZCurrentClockSpeedr   Zcpu_freqcurrentZMaxClockSpeedmaxr;   r!   r!   r"   test_cpu_freqp   s    zTestCpuAPIs.test_cpu_freqN)r&   r'   r(   r   skipIfr,   r-   r0   r6   r>   r?   rC   rF   r!   r!   r!   r"   r)   Q   s   
r)   c                   @   sr   e Zd Zdd Zdd Zeede dd Z	e dd	 Z
e d
d Zdd Zdd Zdd Zdd ZdS )TestSystemAPIsc                 C   sR   t d}tjdd }|D ]0}d|dd kr6q||kr| d|  qd S )Nzipconfig /allT)Zperniczpseudo-interface -z-%r nic wasn't found in 'ipconfig /all' output)r   r   Znet_io_counterskeysreplacelowerfail)r   outZnicsZnicr!   r!   r"   test_nic_namesy   s    zTestSystemAPIs.test_nic_namesc                 C   s,   t   d }| t|jt j d S r7   )	r8   r9   ZWin32_ComputerSystemr.   r+   ZTotalPhysicalMemoryr   Zvirtual_memorytotal)r   r<   r!   r!   r"   test_total_phymem   s    z TestSystemAPIs.test_total_phymemztest not relieable on appveyorc                 C   s:   t   }tdd |D }tt }| || d S )Nc                 S   s   g | ]
}|j qS r!   Z	ProcessId.0xr!   r!   r"   
<listcomp>   s     z,TestSystemAPIs.test_pids.<locals>.<listcomp>)r8   r9   Win32_Processsetr   pidsr.   )r   r<   Zwmi_pidsZpsutil_pidsr!   r!   r"   	test_pids   s    zTestSystemAPIs.test_pidsc              
   C   s   t jdd}t  }|D ]}|D ]}|jdd|jkr$|jsF qd|j	krT q|j
drd qzt |j}W n tk
r   Y  qY nX | |jt|j t|j}| |j| t|j| dkr| d|j|f   qq$| d	t|  qd S )
NTall\ cdromA:i   zpsutil=%s, wmi=%szcan't find partition %s)r   disk_partitionsr8   r9   ZWin32_LogicalDiskdevicerL   ZDeviceID
mountpointopts
startswith
disk_usager   r.   rQ   r+   SizeZ	FreeSpacefreeabsrN   repr)r   Zps_partsZ	wmi_partsZps_partZwmi_partusageZwmi_freer!   r!   r"   
test_disks   s2    

 zTestSystemAPIs.test_disksc                 C   sx   t  D ]j}d|jkrqt|j}t |j}| j|d |jt	d | j|d |j
t	d | |j|j
|j  qd S )Nr`   r   delta   )r   rb   re   r2   ZGetDiskFreeSpaceExrd   rg   assertAlmostEqualri   r   rQ   r.   used)r   Zdiskr4   r5   r!   r!   r"   test_disk_usage   s    

zTestSystemAPIs.test_disk_usagec                 C   s>   dd t  dD }dd tjddD }| || d S )Nc                 S   s"   g | ]}|r| d s|d qS )ra   r^   )rf   rT   r!   r!   r"   rW      s    
z7TestSystemAPIs.test_disk_partitions.<locals>.<listcomp>z\ c                 S   s   g | ]}|j d s|j qS )ra   )rd   rf   rT   r!   r!   r"   rW      s    Tr\   )r2   ZGetLogicalDriveStringssplitr   rb   r.   r3   r!   r!   r"   test_disk_partitions   s
    z#TestSystemAPIs.test_disk_partitionsc                 C   s\   t t }t  }t  }|D ]}||j ||j q"| 	||@ d||f  d S )Nzno common entries in %s, %s)
rY   cextZnet_if_statsr8   r9   ZWin32_NetworkAdapteraddNameZNetConnectionID
assertTrue)r   Zps_namesZwmi_adaptersZ	wmi_namesZwmi_adapterr!   r!   r"   test_net_if_stats   s    

z TestSystemAPIs.test_net_if_statsc                 C   s^   t   }|d jdd }tj|d}tjt	 }t
||  }| |d d S )Nr   .%Y%m%d%H%M%S   )r8   r9   ZWin32_OperatingSystemZLastBootUpTimert   datetimestrptimefromtimestampr   	boot_timerj   total_secondsZassertLessEqual)r   Zwmi_osZwmi_btime_strZwmi_btime_dtZ	psutil_dtZdiffr!   r!   r"   test_boot_time   s     zTestSystemAPIs.test_boot_timec              	   C   s   t jddd | t d W 5 Q R X t jddd | t d W 5 Q R X t jddd | t d W 5 Q R X t jddd | t d W 5 Q R X d S )Nz psutil._pswindows.cext.boot_timer1   Zreturn_value      iM  )r	   patchr.   r   r   rB   r!   r!   r"   test_boot_time_fluctuation   s    z)TestSystemAPIs.test_boot_time_fluctuationN)r&   r'   r(   rP   rR   r   rG   r   r   r[   rm   rs   ru   rz   r   r   r!   r!   r!   r"   rH   w   s   




	rH   c                   @   s`   e Zd Zdd Zee ddd Zee ddd Zdd	 Z	d
d Z
dd Zdd ZdS )TestSensorsBatteryc                 C   s.   t  d r| t  n| t  d S )NZSystemBatteriesPresent)r2   ZGetPwrCapabilitiesZassertIsNotNoner   sensors_batteryassertIsNonerB   r!   r!   r"   test_has_battery   s    z#TestSensorsBattery.test_has_batteryz
no batteryc                 C   s6   t  }|dd }t }| j|j|jdd d S )Nselect * from Win32_Batteryr   rp   rn   )r8   r9   queryr   r   rq   percentZEstimatedChargeRemainingr   r<   Zbattery_wmiZbattery_psutilr!   r!   r"   test_percent   s     zTestSensorsBattery.test_percentc                 C   s6   t  }|dd }t }| |j|jdk d S )Nr   r      )r8   r9   r   r   r   r.   power_pluggedZBatteryStatusr   r!   r!   r"   test_power_plugged  s    z%TestSensorsBattery.test_power_pluggedc              	   C   s6   t jddd}| t  |js(tW 5 Q R X d S )N&psutil._pswindows.cext.sensors_battery)r      r   r   r   )r	   r   r   r   r   calledAssertionErrorr   mr!   r!   r"   test_emulate_no_battery  s    z*TestSensorsBattery.test_emulate_no_batteryc              	   C   s<   t jddd$}| t jtj |js.tW 5 Q R X d S )Nr   )rp   r   r   r   r   	r	   r   r.   r   r   secsleftPOWER_TIME_UNLIMITEDr   r   r   r!   r!   r"   test_emulate_power_connected  s    z/TestSensorsBattery.test_emulate_power_connectedc              	   C   s<   t jddd$}| t jtj |js.tW 5 Q R X d S )Nr   )r      r   r   r   r   r   r!   r!   r"   test_emulate_power_charging  s    z.TestSensorsBattery.test_emulate_power_chargingc              	   C   s<   t jddd$}| t jtj |js.tW 5 Q R X d S )Nr   )r   r   r   r   )	r	   r   r.   r   r   r   POWER_TIME_UNKNOWNr   r   r   r!   r!   r"   test_emulate_secs_left_unknown%  s    z1TestSensorsBattery.test_emulate_secs_left_unknownN)r&   r'   r(   r   r   rG   r   r   r   r   r   r   r   r!   r!   r!   r"   r      s   

	r   c                   @   s   e Zd Zedd Zedd Zdd Zdd Zd	d
 Zdd Z	e
ejdk ddd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%S )&TestProcessc                 C   s   t  j| _d S Nr   pidclsr!   r!   r"   
setUpClass4  s    zTestProcess.setUpClassc                 C   s   t | j d S r   r   r   r   r!   r!   r"   tearDownClass8  s    zTestProcess.tearDownClassc                 C   s   t d}| t j|j d S r7   )r   ProcessassertRaisesr   killr   pr!   r!   r"   test_issue_24<  s    
zTestProcess.test_issue_24c                 C   s   t d}| | d t| |  | | dk z| d d \}}W n( t j	k
r|   t
 d dkrx Y nX | |dk d S )Nr   Systemg        r   rp   )Zvistazwin-7Zwin7r   )r   r   r.   namestrusernamery   create_timememory_infor   platformuname)r   r   rssvmsr!   r!   r"   test_special_pid@  s    
zTestProcess.test_special_pidc                 C   s"   t | j}| t|jtj d S r   )r   r   r   r   
ValueErrorsend_signalsignalSIGINTr   r!   r!   r"   test_send_signalQ  s    zTestProcess.test_send_signalc                 C   sb   t t }| }ttjtj	t }| }| 
||d  t| | 
| | d S )Nrp   )r   r   r,   getpidnum_handlesr2   OpenProcesswin32conPROCESS_QUERY_INFORMATIONFALSEr.   CloseHandle)r   r   beforehandleafterr!   r!   r"   test_num_handles_incrementU  s     
z&TestProcess.test_num_handles_increment)r      zCTRL_* signals not supportedc                 C   sd   t |  j}|tj |tj |  |	  | 
t j|jtj | 
t j|jtj d S r   )r   r   r   r   r   r   ZCTRL_C_EVENTZCTRL_BREAK_EVENTr   waitr   r   r   r!   r!   r"   test_ctrl_signals_  s      zTestProcess.test_ctrl_signalsc                 C   s    |  t  ttj d S r   )r.   r   r   r   r2   ZGetUserNameExr   ZNameSamCompatiblerB   r!   r!   r"   test_usernamel  s    
zTestProcess.test_usernamec                 C   s8   t ddt  }dt  }| 	|| d S )Nz +rI   )
resubr2   ZGetCommandLinestripjoinr   r   cmdliner.   r3   r!   r!   r"   test_cmdlinep  s    zTestProcess.test_cmdlinec                 C   sJ   t tjtjt }| t j| t	
|}t  }| || d S r   )r2   r   r   r   r   r,   r   
addCleanupr   win32processZGetPriorityClassr   r   nicer.   r   r   r4   r5   r!   r!   r"   	test_nice  s     
zTestProcess.test_nicec                 C   s   t tjtj| j}| t j| t	|}t
| j }| |d |j | |d |j | |d |j | |d |j | |d |j | |d |j | |d |j | |d |j | |j|j | |j|j d S )	NZPeakWorkingSetSizeWorkingSetSizeZQuotaPeakPagedPoolUsageZQuotaPagedPoolUsageZQuotaPeakNonPagedPoolUsageZQuotaNonPagedPoolUsageZPagefileUsageZPeakPagefileUsage)r2   r   r   r   r   r   r   r   r   ZGetProcessMemoryInfor   r   r   r.   Z	peak_wsetZwsetZpeak_paged_poolZ
paged_poolZpeak_nonpaged_poolZnonpaged_poolZpagefileZpeak_pagefiler   r   r   r!   r!   r"   test_memory_info  sR     
       zTestProcess.test_memory_infoc                 C   sX   t tjtj| j}| t j| t	| j}|
  | }t|}| || d S r   )r2   r   r   r   r   r   r   r   r   r   r   r   r   ZGetExitCodeProcessr.   )r   r   r   r5   r4   r!   r!   r"   	test_wait  s     
zTestProcess.test_waitc                 C   s\   dd }t tjtj| j}| t j| |t	|d }t
| j }| || d S )Nc                    s    fddt dD S )Nc                    s   g | ]}d |>  @ r|qS )rp   r!   )rU   irV   r!   r"   rW     s      zGTestProcess.test_cpu_affinity.<locals>.from_bitmask.<locals>.<listcomp>@   )ranger   r!   r   r"   from_bitmask  s    z3TestProcess.test_cpu_affinity.<locals>.from_bitmaskr   )r2   r   r   r   r   r   r   r   r   ZGetProcessAffinityMaskr   r   Zcpu_affinityr.   )r   r   r   r4   r5   r!   r!   r"   test_cpu_affinity  s     zTestProcess.test_cpu_affinityc                 C   s   t tjtjt }| t j| t	
|}t  }| |j|d  | |j|d  | |j|d  | |j|d  | |j|d  | |j|d  d S )NZReadOperationCountZWriteOperationCountZReadTransferCountZWriteTransferCountZOtherOperationCountZOtherTransferCount)r2   r   r   r   r   r,   r   r   r   r   ZGetProcessIoCountersr   r   io_countersr.   
read_countwrite_count
read_byteswrite_bytesother_countZother_bytesr   r!   r!   r"   test_io_counters  s>     
      zTestProcess.test_io_countersc                 C   s   dd l }dd l}d}|jj|d| j}| |jjj| |j	 }|jj
||| |j}t| j }| || d S )Nr      )ctypesZctypes.wintypeswindllkernel32r   r   r   r   ZwintypesZDWORDZGetProcessHandleCountbyrefvaluer   r   r   r.   )r   r   r   r   Zhndcntr4   r5   r!   r!   r"   test_num_handles  s"      
 zTestProcess.test_num_handlesc              
   C   sf   t  }d|_tjd|d4 td}t }| tj|j W 5 Q R X W 5 Q R X | 	|j
d d S )Ni+  z psutil._psplatform.cext.proc_cwdside_effectz
time.sleepr1   )WindowsErrorwinerrorr	   r   r   r   r   r   cwdassertGreaterEqualZ
call_count)r   excr   r   r!   r!   r"   test_error_partial_copy  s    $z#TestProcess.test_error_partial_copyc                 C   s0   t  d d }t j|}| t j|j d S )Nr   i )r   rZ   _psplatformr   r   r   exe)r   r   r=   r!   r!   r"   test_exe  s    zTestProcess.test_exeN)r&   r'   r(   classmethodr   r   r   r   r   r   r   rG   sysversion_infor   r   r   r   r   r   r   r   r   r   r   r!   r!   r!   r"   r   2  s,   





r   c                   @   sx   e Zd ZdZedd Zedd Zdd Ze	e
dd	d
 Zdd Zdd Ze dd Ze dd Zdd ZdS )TestProcessWMIz%Compare Process API results with WMI.c                 C   s   t  j| _d S r   r   r   r!   r!   r"   r     s    zTestProcessWMI.setUpClassc                 C   s   t | j d S r   r   r   r!   r!   r"   r     s    zTestProcessWMI.tearDownClassc                 C   s8   t  j| jdd }t| j}| | |j d S NrS   r   )	r8   r9   rX   r   r   r   r.   r   ZCaptionr   r<   r   r!   r!   r"   	test_name  s    zTestProcessWMI.test_namez!unreliable path on GITHUB_ACTIONSc                 C   s@   t  j| jdd }t| j}| |  |j	  d S r  )
r8   r9   rX   r   r   r   r.   r   rM   ZExecutablePathr  r!   r!   r"   r     s    zTestProcessWMI.test_exec                 C   sF   t  j| jdd }t| j}| d| |j	
dd d S )NrS   r   rI   "r_   )r8   r9   rX   r   r   r   r.   r   r   ZCommandLinerL   r  r!   r!   r"   r   
  s
    zTestProcessWMI.test_cmdlinec                 C   sP   t  j| jdd }t| j}| \}}}d||f }| | | d S )NrS   r   z%s\%s)	r8   r9   rX   r   r   r   ZGetOwnerr.   r   )r   r<   r   domain_r   r!   r!   r"   r     s
    zTestProcessWMI.test_usernamec                 C   sB   t  j| jdd }t| j}| j}| |t	|j
 d S r  )r8   r9   rX   r   r   r   r   r   r.   r+   r   )r   r<   r   r   r!   r!   r"   test_memory_rss  s    
zTestProcessWMI.test_memory_rssc                 C   s`   t  j| jdd }t| j}| j}t|j	}||kr\||d kr\| 
d||f  d S )NrS   r   r   zwmi=%s, psutil=%s)r8   r9   rX   r   r   r   r   r   r+   ZPageFileUsagerN   )r   r<   r   r   Z	wmi_usager!   r!   r"   test_memory_vms  s    

zTestProcessWMI.test_memory_vmsc                 C   s\   t  j| jdd }t| j}t|jdd }t	
dt	| }| || d S )NrS   r   r{   r|   )r8   r9   rX   r   r   r   r   ZCreationDatert   timestrftime	localtimer   r.   )r   r<   r   Zwmic_createZpsutil_creater!   r!   r"   test_create_time+  s    zTestProcessWMI.test_create_timeN)r&   r'   r(   __doc__r   r   r   r  r   rG   r   r   r   r   r   r
  r  r  r!   r!   r!   r"   r    s   





r  c                   @   sX   e Zd ZdZedd Zedd Zdd Zdd	 Zd
d Z	dd Z
dd Zdd ZdS )TestDualProcessImplementationa{  
    Certain 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
    c                 C   s   t  j| _d S r   r   r   r!   r!   r"   r   C  s    z(TestDualProcessImplementation.setUpClassc                 C   s   t | j d S r   r   r   r!   r!   r"   r   G  s    z+TestDualProcessImplementation.tearDownClassc              	   C   s   t | j }tjdttjdd~}t | j }| 	t
|t
| tt
|D ]<}| || d | || d | j|| || dd qX|jstW 5 Q R X d S )Nz(psutil._psplatform.cext.proc_memory_infomsgr   r   i   rn   )r   r   r   r   r	   r   r   r   EPERMr.   r@   r   r   rq   r   r   )r   Zmem_1r    Zmem_2r   r!   r!   r"   r   K  s    
z.TestDualProcessImplementation.test_memory_infoc              	   C   sX   t | j }tjdttjdd(}| 	t | j | |j
sJtW 5 Q R X d S )N"psutil._psplatform.cext.proc_timesr  r   )r   r   r   r   r	   r   r   r   r  r.   r   r   )r   ctimer    r!   r!   r"   r  W  s    
z.TestDualProcessImplementation.test_create_timec              	   C   sx   t | j }tjdttjddH}t | j }|j	sBt
| j|j|jdd | j|j|jdd W 5 Q R X d S )Nr  r  r   g{Gz?rn   )r   r   r   rA   r	   r   r   r   r  r   r   rq   usersystem)r   Zcpu_times_1r    Zcpu_times_2r!   r!   r"   test_cpu_times^  s"    

    z,TestDualProcessImplementation.test_cpu_timesc              	   C   sz   t | j }tjdttjddJ}t | j }t	t
|D ]}| j|| || dd qD|jsltW 5 Q R X d S )Nz(psutil._psplatform.cext.proc_io_countersr  r   r1   rn   )r   r   r   r   r	   r   r   r   r  r   r@   rq   r   r   )r   Zio_counters_1r    Zio_counters_2r   r!   r!   r"   r   i  s    
  z.TestDualProcessImplementation.test_io_countersc              	   C   sX   t | j }tjdttjdd(}| 	t | j | |j
sJtW 5 Q R X d S )Nz(psutil._psplatform.cext.proc_num_handlesr  r   )r   r   r   r   r	   r   r   r   r  r.   r   r   )r   r   r    r!   r!   r"   r   s  s    
z.TestDualProcessImplementation.test_num_handlesc                 C   s   ddl m} t D ]p}z tj|dd}tj|dd}W n> tk
rv } z ||}t|tjtj	fsf W 5 d }~X Y qX | 
|| qd S )Nr   )convert_oserrorT)Zuse_pebF)r   r  r   rZ   rv   Zproc_cmdliner   
isinstancer   r   r.   )r   r  r   abr   r!   r!   r"   r   {  s    z*TestDualProcessImplementation.test_cmdlineN)r&   r'   r(   r  r   r   r   r   r  r  r   r   r   r!   r!   r!   r"   r  7  s   



r  c                       sp   e Zd ZdZedd ZddgZ fddZ fdd	Zd
d Z	dd Z
dd Zdd Zdd Zdd Z  ZS )RemoteProcessTestCasezCertain 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.
    c                  C   s\   d} t  dD ]H}tj|d| gtjtjd}| \}}|  |tt kr|  S qd S )Nz6import sys; sys.stdout.write(str(sys.maxsize > 2**32))zC:\Python*\python.exe-c)r   stdoutstderr)	glob
subprocessPopenPIPESTDOUTcommunicater   r   r   )codefilenamer=   outputr	  r!   r!   r"   find_other_interpreter  s    z,RemoteProcessTestCase.find_other_interpreterr  zimport sys; sys.stdin.read()c                    s   t    |  }|d kr$tdtr8tj| _|| _	n|| _tj| _	t
j }tt
 |d< | j| j	g| j |tjd| _| j| jg| j |tjd| _d S )Nz0could not find interpreter with opposite bitnessTHINK_OF_A_NUMBER)envstdin)r   setUpr*  r   ZSkipTestr   r  
executableZpython64Zpython32r,   r-   copyr   r   r   	test_argsr"  r$  proc32proc64)r   Zother_pythonr,  	__class__r!   r"   r.    s.    

zRemoteProcessTestCase.setUpc                    s"   t    | j  | j  d S r   )r   tearDownr2  r&  r3  rB   r4  r!   r"   r6    s    

zRemoteProcessTestCase.tearDownc                 C   s@   t | jj}| t| d | | dd  | j d S Nr}   rp   )r   r   r2  r   r.   r@   r   r1  r   r!   r!   r"   test_cmdline_32  s    z%RemoteProcessTestCase.test_cmdline_32c                 C   s@   t | jj}| t| d | | dd  | j d S r7  )r   r   r3  r   r.   r@   r   r1  r   r!   r!   r"   test_cmdline_64  s    z%RemoteProcessTestCase.test_cmdline_64c                 C   s&   t | jj}| | t  d S r   )r   r   r2  r   r.   r   r,   getcwdr   r!   r!   r"   test_cwd_32  s    z!RemoteProcessTestCase.test_cwd_32c                 C   s&   t | jj}| | t  d S r   )r   r   r3  r   r.   r   r,   r:  r   r!   r!   r"   test_cwd_64  s    z!RemoteProcessTestCase.test_cwd_64c                 C   s>   t | jj}| }| d| | |d tt	  d S )Nr+  )
r   r   r2  r   r-   assertInZassertEqualsr   r,   r   )r   r   er!   r!   r"   test_environ_32  s    z%RemoteProcessTestCase.test_environ_32c                 C   s6   t | jj}z|  W n t jk
r0   Y nX d S r   )r   r   r3  r   r-   r   r   r!   r!   r"   test_environ_64  s
    z%RemoteProcessTestCase.test_environ_64)r&   r'   r(   r  staticmethodr*  r1  r.  r6  r8  r9  r;  r<  r?  r@  __classcell__r!   r!   r4  r"   r    s   
r  c                   @   s   e Zd Zdd Zdd ZdS )TestServicesc                 C   sh  t dddddddg}t dd	d
g}t dddddddg}t D ]}| }| |d t | |d  d | |d t | |d t | |d | |d d k	rt	|d  | |d t | |d t | |d t | |d | | |d | | |d t |
 }|d k	rHt	|}| |  t| }| || qBd S )NrunningZpausedstartpausecontinuestopstoppedZ	automaticZmanualdisabledZstart_pendingZpause_pendingZcontinue_pendingZstop_pendingr   r_   display_namer   statusr   ZbinpathZ
start_typedescription)rY   r   win_service_iterZas_dictZassertIsInstancer   ZassertNotEqualr   r=  r   r   ry   Z
is_runningwin_service_getr   r.   )r   Zvalid_statusesZvalid_start_typesZservdatar   r   sr!   r!   r"   test_win_service_iter  sX    		

z"TestServices.test_win_service_iterc              	   C   s  t jjj}t jjj}tt   }| t j	}t 
|d  W 5 Q R X | |jj|d  t 
|}trzddd|f}n|df}t| }tjd|d | t j	|j W 5 Q R X tjd|d | t j	|j W 5 Q R X trddd|f}n|df}t| }tjd|d | t j|j W 5 Q R X tjd|d | t j|j W 5 Q R X | | t| | | t| | | t| | | t| d S )Nz???r   r  z/psutil._psplatform.cext.winservice_query_statusr   z/psutil._psplatform.cext.winservice_query_config)r   r   rv   ERROR_SERVICE_DOES_NOT_EXISTERROR_ACCESS_DENIEDnextrN  r   r   r   rO  r.   	exceptionr   r   r	   r   rL  r   r   r=  r   rK  rk   )r   rS  rT  r   cmZservicer   r   r!   r!   r"   test_win_service_get  sH    

z!TestServices.test_win_service_getN)r&   r'   r(   rR  rX  r!   r!   r!   r"   rC    s   0rC  __main__)run_from_name)7r  r~   r   r!  r,   r   r   r   r"  r  r  warningsr   r   Zpsutil._compatr   r   Zpsutil.testsr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   catch_warningssimplefilterr2   r   r   r8   r   rv   r$   rG   r%   r)   rH   r   r   r  r  r  rC  r&   Zpsutil.tests.runnerrZ  __file__r!   r!   r!   r"   <module>   sr   


	&< @FR\^
