3 ̪e@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddl mZddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ere re j"0e j#dddl$Z$ddl%Z%ddl&Z&ddl'Z'WdQRXerddl(m)Z)e j*j+Z+e j,e de j,ede j,eoe dGdddeZ-ddZ.e/fddZ0Gd d!d!e-Z1Gd"d#d#e-Z2Gd$d%d%e-Z3Gd&d'd'e-Z4Gd(d)d)e-Z5e j,e dGd*d+d+eZ6e j,e dGd,d-d-eZ7e j,e dGd.d/d/eZ8e9d0krdd1l:m;Z;e;e<dS)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)retry_on_failure)sh)spawn_testproc) terminateignore)convert_oserrorz WINDOWS onlyzpywin32 not available on PYPYzpywin32 broken on GITHUB + PY2c@s eZdZdS)WindowsTestCaseN)__name__ __module__ __qualname__rrE/usr/local/lib64/python3.6/site-packages/psutil/tests/test_windows.pyr;srcCs&tdstjddd|}t|S)zCurrently 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")runittestSkipTestr)cmdcmdlinerrr powershellCs   r csjtd||fj}dj|jddj}dk rbd|krXtfdd|jDS|Sn|SdS)zCurrently not used, but available just in case. Usage: >>> wmic("Win32_OperatingSystem", "FreePhysicalMemory") 2134124534 zwmic path %s get %sN,csg|] }|qSrr).0x) converterrr \szwmic..)rstripjoin splitlinestuplesplit)pathwhatr&outdatar)r&rwmicRs r1c@sNeZdZejdejkdddZddZddZ d d Z d d Z d dZ dS) TestCpuAPIsNUMBER_OF_PROCESSORSz-NUMBER_OF_PROCESSORS env var is not availablecCs"ttjd}|j|tjdS)Nr3)intosenviron assertEqualpsutil cpu_count)selfZnum_cpusrrr&test_cpu_count_vs_NUMBER_OF_PROCESSORSisz2TestCpuAPIs.test_cpu_count_vs_NUMBER_OF_PROCESSORScCs$tjd}tj}|j||dS)N)win32apiZ GetSystemInfor8r9r7)r: sys_value psutil_valuerrrtest_cpu_count_vs_GetSystemInfoss z+TestCpuAPIs.test_cpu_count_vs_GetSystemInfocCs2tj}tdd|jD}|jtj|dS)Ncss|] }|jVqdS)N)ZNumberOfLogicalProcessors)r$procrrr }sz.)wmiWMIsumWin32_Processorr7r8r9)r:wZprocsrrrtest_cpu_count_logical_vs_wmizsz)TestCpuAPIs.test_cpu_count_logical_vs_wmicCs6tj}tdd|jD}|jtjdd|dS)Ncss|] }|jVqdS)N)Z NumberOfCores)r$rArrrrBsz:TestCpuAPIs.test_cpu_count_cores_vs_wmi..F)Zlogical)rCrDrErFr7r8r9)r:rGZcoresrrrtest_cpu_count_cores_vs_wmisz'TestCpuAPIs.test_cpu_count_cores_vs_wmicCs |jtjttjdddS)NT)Zpercpu)r7r8r9len cpu_times)r:rrrtest_cpu_count_vs_cpu_timessz'TestCpuAPIs.test_cpu_count_vs_cpu_timescCs@tj}|jd}|j|jtjj|j|jtjj dS)Nr) rCrDrFr7ZCurrentClockSpeedr8Zcpu_freqcurrentZ MaxClockSpeedmax)r:rGrArrr test_cpu_freqs zTestCpuAPIs.test_cpu_freqN) rrrrskipIfr5r6r;r@rHrIrLrOrrrrr2hsr2c@seZdZddZddZddZddZd d Zej e d e d d Z e ddZ e ddZddZddZddZddZdS)TestSystemAPIscCsVtd}tjddj}x8|D]0}d|jddjkr8q||kr|jd|qWdS)Nz ipconfig /allT)Zperniczpseudo-interface -z-%r nic wasn't found in 'ipconfig /all' output)rr8Znet_io_counterskeysreplacelowerfail)r:r/ZnicsZnicrrrtest_nic_namess zTestSystemAPIs.test_nic_namescCs,tjjd}|jt|jtjjdS)Nr) rCrDZWin32_ComputerSystemr7r4ZTotalPhysicalMemoryr8virtual_memorytotal)r:rGrrrtest_total_phymemsz TestSystemAPIs.test_total_phymemcCs0tjjd}|jt|jtjjt ddS)Nr)delta) rCrDWin32_PerfRawData_PerfOS_MemoryassertAlmostEqualr4ZAvailableBytesr8rYfreer )r:rGrrrtest_free_phymems zTestSystemAPIs.test_free_phymemcCshtjjd}|jt|jtjjtj jtj jdkrd|jdtj j |jdtj j dS)Nr) rCrDr]r7r4Z CommitLimitr8rYrZ swap_memoryr_used)r:rGrrrtest_total_swapmems z!TestSystemAPIs.test_total_swapmemcCsxtjjdkrttjjddd}t|jdt|j}|j tjj d|j tjj |dd|j tjj ddS)NrZ_Total)Namedr<)r\) r8rarZrCrDZ#Win32_PerfRawData_PerfOS_PagingFiler4Z PercentUsageZPercentUsage_BaseassertGreaterEqualpercentr^assertLessEqual)r:rGZ percentSwaprrrtest_percent_swapmemsz#TestSystemAPIs.test_percent_swapmemztest not relieable on appveyorcCs:tjj}tdd|D}ttj}|j||dS)NcSsg|] }|jqSr) ProcessId)r$r%rrrr'sz,TestSystemAPIs.test_pids..)rCrD Win32_Processsetr8pidsr7)r:rGZwmi_pidsZ psutil_pidsrrr test_pidss  zTestSystemAPIs.test_pidscCstjdd}tjj}x|D]}x|D]}|jjdd|jkr(|jsHPd|j krTP|jj drbPytj |j}Wnt k rPYnX|j |jt|jt|j}|j |j|t|j|d kr|jd |j|fPq(W|jd t|qWdS) NT)all\r!cdromzA: izpsutil=%s, wmi=%szcan't find partition %si(i)r8disk_partitionsrCrDZWin32_LogicalDiskdevicerUZDeviceID mountpointopts startswith disk_usagerr7rZr4SizeZ FreeSpacer_absrWrepr)r:Zps_partsZ wmi_partsZps_partZwmi_partusageZwmi_freerrr test_diskss.       zTestSystemAPIs.test_diskscCs|xvtjD]j}d|jkrq tj|j}tj|j}|j|d|jt d|j|d|j t d|j |j |j |jq WdS)Nrqr)r\r") r8rsrvr=ZGetDiskFreeSpaceExrurxr^r_r rZr7rb)r:Zdiskr>r?rrrtest_disk_usages   zTestSystemAPIs.test_disk_usagecCs>ddtjjdD}ddtjddD}|j||dS)NcSs$g|]}|r|jd r|dqS)zA:rp)rw)r$r%rrrr' sz7TestSystemAPIs.test_disk_partitions..z\cSsg|]}|jjds|jqS)zA:)rurw)r$r%rrrr'sT)ro)r=ZGetLogicalDriveStringsr,r8rsr7)r:r>r?rrrtest_disk_partitions s z#TestSystemAPIs.test_disk_partitionscCs`ttj}tjj}t}x$|D]}|j|j|j|jq$W|j ||@d||fdS)Nzno common entries in %s, %s) rlcextZ net_if_statsrCrDZWin32_NetworkAdapteraddrdZNetConnectionID assertTrue)r:Zps_namesZ wmi_adaptersZ wmi_namesZ wmi_adapterrrrtest_net_if_statss    z TestSystemAPIs.test_net_if_statscCs^tjj}|djjdd}tjj|d}tjjtj }t ||j }|j |ddS)Nr.z %Y%m%d%H%M%Sr<) rCrDZWin32_OperatingSystemZLastBootUpTimer,datetimestrptime fromtimestampr8 boot_timerz total_secondsrh)r:Zwmi_osZ wmi_btime_strZ wmi_btime_dtZ psutil_dtZdiffrrrtest_boot_time"s zTestSystemAPIs.test_boot_timecCstjddd|jtjdWdQRXtjddd|jtjdWdQRXtjddd|jtjdWdQRXtjddd|jtjdWdQRXdS)Nz psutil._pswindows.cext.boot_timer<) return_valueiM)rpatchr7r8r)r:rrrtest_boot_time_fluctuation,sz)TestSystemAPIs.test_boot_time_fluctuationN)rrrrXr[r`rcrirrPrrrnr}r~rrrrrrrrrQs       rQc@s`eZdZddZeje dddZeje dddZdd Z d d Z d d Z ddZ dS)TestSensorsBatterycCs.tjdr|jtjn|jtjdS)NZSystemBatteriesPresent)r=ZGetPwrCapabilitiesZassertIsNotNoner8sensors_battery assertIsNone)r:rrrtest_has_battery>s z#TestSensorsBattery.test_has_batteryz no batterycCs6tj}|jdd}tj}|j|j|jdddS)Nzselect * from Win32_Batteryrr")r\)rCrDqueryr8rr^rgZEstimatedChargeRemaining)r:rG battery_wmibattery_psutilrrr test_percentDszTestSensorsBattery.test_percentcCs6tj}|jdd}tj}|j|j|jdkdS)Nzselect * from Win32_Batteryr)rCrDrr8rr7 power_pluggedZ BatteryStatus)r:rGrrrrrtest_power_pluggedOs z%TestSensorsBattery.test_power_pluggedc Cs6tjddd}|jtj|js(tWdQRXdS)Nz&psutil._pswindows.cext.sensors_batteryr)r)rrrr)rrrr8rcalledAssertionError)r:mrrrtest_emulate_no_batteryZs z*TestSensorsBattery.test_emulate_no_batteryc Cs<tjddd$}|jtjjtj|js.tWdQRXdS)Nz&psutil._pswindows.cext.sensors_batteryr"r)r)r"rrr) rrr7r8rsecsleftPOWER_TIME_UNLIMITEDrr)r:rrrrtest_emulate_power_connectedbs  z/TestSensorsBattery.test_emulate_power_connectedc Cs<tjddd$}|jtjjtj|js.tWdQRXdS)Nz&psutil._pswindows.cext.sensors_batteryr)r)rrrr) rrr7r8rrrrr)r:rrrrtest_emulate_power_chargingks  z.TestSensorsBattery.test_emulate_power_chargingc Cs<tjddd$}|jtjjtj|js.tWdQRXdS)Nz&psutil._pswindows.cext.sensors_batteryrr")r)rrrr) rrr7r8rrPOWER_TIME_UNKNOWNrr)r:rrrrtest_emulate_secs_left_unknowntsz1TestSensorsBattery.test_emulate_secs_left_unknownN) rrrrrrPrrrrrrrrrrrr=s    rc@seZdZeddZeddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZddZddZddZdd Zd!d"Zd#S)$ TestProcesscCstj|_dS)N)rpid)clsrrr setUpClassszTestProcess.setUpClasscCst|jdS)N)rr)rrrr tearDownClassszTestProcess.tearDownClasscCstjd}|jtj|jdS)Nr)r8Process assertRaises AccessDeniedkill)r:prrr test_issue_24s zTestProcess.test_issue_24c Cstjd}|j|jdt||j|j|jdy|jdd\}}Wn(tj k rzt j dd krvYnX|j |d dS) NrSystemgrr"vistawin-7win7r)rrr) r8rr7namestrusernamerf create_time memory_inforplatformunameZ assertGreater)r:rrssvmsrrrtest_special_pids zTestProcess.test_special_pidcCs"tj|j}|jt|jtjdS)N)r8rrr ValueError send_signalsignalSIGINT)r:rrrrtest_send_signals zTestProcess.test_send_signalcCsbtjtj}|j}tjtjtj tj}|j}|j ||dtj ||j |j|dS)Nr") r8rr5getpid num_handlesr= OpenProcesswin32conPROCESS_QUERY_INFORMATIONFALSEr7 CloseHandle)r:rbeforehandleafterrrrtest_num_handles_increments z&TestProcess.test_num_handles_incrementcCsdtj|jj}|jtj|jtj|j|j |j tj |jtj|j tj |jtjdS)N) r8rrrrrZ CTRL_C_EVENTZCTRL_BREAK_EVENTrwaitr NoSuchProcess)r:rrrrtest_ctrl_signalss  zTestProcess.test_ctrl_signalscCs8tjtj}|jdr tjd|jtj j |dS)N$zrunning as service account) r=Z GetUserNameExrZNameSamCompatibleendswithrrr7r8rr)r:rrrr test_usernames   zTestProcess.test_usernamecCsftjddtjj}djtjj}|ddkoB|dknrV|j ddd}|j ||dS)Nz[ ]+rRr"r!r) resubr=ZGetCommandLiner(r)r8rrrUr7)r:r>r?rrr test_cmdlines  zTestProcess.test_cmdlinecCsJtjtjtjtj}|jtj|t j |}t j j }|j||dS)N)r=rrrrr5r addCleanupr win32processZGetPriorityClassr8rnicer7)r:rr>r?rrr test_nices   zTestProcess.test_nicecCstjtjtj|j}|jtj|tj |}t j |jj }|j |d|j|j |d|j|j |d|j|j |d|j|j |d|j|j |d|j|j |d|j|j |d|j|j |j|j|j |j|jdS) NZPeakWorkingSetSizeWorkingSetSizeZQuotaPeakPagedPoolUsageZQuotaPagedPoolUsageZQuotaPeakNonPagedPoolUsageZQuotaNonPagedPoolUsageZ PagefileUsageZPeakPagefileUsage)r=rrrrrrrrZGetProcessMemoryInfor8rrr7Z peak_wsetZwsetZpeak_paged_poolZ paged_poolZpeak_nonpaged_poolZ nonpaged_poolZpagefileZ peak_pagefilerr)r:rr>r?rrrtest_memory_infos, zTestProcess.test_memory_infocCsXtjtjtj|j}|jtj|tj |j}|j |j }t j |}|j||dS)N)r=rrrrrrrr8rrrrZGetExitCodeProcessr7)r:rrr?r>rrr test_wait s  zTestProcess.test_waitcCs\dd}tjtjtj|j}|jtj||tj |d}t j |jj }|j ||dS)NcsfddtdDS)Ncsg|]}d|>@r|qS)r"r)r$i)r%rrr'szGTestProcess.test_cpu_affinity..from_bitmask..@)range)r%r)r%r from_bitmasksz3TestProcess.test_cpu_affinity..from_bitmaskr)r=rrrrrrrrZGetProcessAffinityMaskr8rZ cpu_affinityr7)r:rrr>r?rrrtest_cpu_affinityszTestProcess.test_cpu_affinitycCstjtjtjtj}|jtj|t j |}t j j }|j|j|d|j|j|d|j|j|d|j|j|d|j|j|d|j|j|ddS)NZReadOperationCountZWriteOperationCountZReadTransferCountZWriteTransferCountZOtherOperationCountZOtherTransferCount)r=rrrrr5rrrrZGetProcessIoCountersr8r io_countersr7 read_count write_count read_bytes write_bytes other_countZ other_bytes)r:rr>r?rrrtest_io_counters#s"  zTestProcess.test_io_counterscCsddl}ddl}d}|jjj|d|j}|j|jjj||jj }|jjj ||j ||j }t j|jj}|j||dS)Nri)ctypesZctypes.wintypeswindllkernel32rrrrZwintypesZDWORDZGetProcessHandleCountbyrefvaluer8rrr7)r:rrrZhndcntr>r?rrrtest_num_handles=s  zTestProcess.test_num_handlescCsft}d|_tjd|d4tjd}tj}|jtj|jWdQRXWdQRX|j |j ddS)Ni+z psutil._psplatform.cext.proc_cwd) side_effectz time.sleepr<) WindowsErrorwinerrorrrr8rrrcwdrfZ call_count)r:excrrrrrtest_error_partial_copyOs $z#TestProcess.test_error_partial_copycCs0tjdd}tjj|}|jtj|jdS)Nr"ir)r8rm _psplatformrrrexe)r:rrArrrtest_exeYs zTestProcess.test_exeN)rrr classmethodrrrrrrrrrrrrrrrrrrrrrrs"         rc@sxeZdZdZeddZeddZddZej e dd d Z d d Z d dZ eddZeddZddZdS)TestProcessWMIz%Compare Process API results with WMI.cCstj|_dS)N)rr)rrrrrdszTestProcessWMI.setUpClasscCst|jdS)N)rr)rrrrrhszTestProcessWMI.tearDownClasscCs8tjj|jdd}tj|j}|j|j|jdS)N)rjr) rCrDrkrr8rr7rZCaption)r:rGrrrr test_namels zTestProcessWMI.test_namez!unreliable path on GITHUB_ACTIONScCs@tjj|jdd}tj|j}|j|jj|j jdS)N)rjr) rCrDrkrr8rr7rrVZExecutablePath)r:rGrrrrrrs zTestProcessWMI.test_execCsFtjj|jdd}tj|j}|jdj|j|j j dddS)N)rjrrRrr!) rCrDrkrr8rr7r)rZ CommandLinerU)r:rGrrrrrzs zTestProcessWMI.test_cmdlinecCsPtjj|jdd}tj|j}|j\}}}d||f}|j|j|dS)N)rjrz%s\%s) rCrDrkrr8rZGetOwnerr7r)r:rGrdomain_rrrrrs   zTestProcessWMI.test_usernamecCsBtjj|jdd}tj|j}|jj}|j|t |j dS)N)rjr) rCrDrkrr8rrrr7r4r)r:rGrrrrrtest_memory_rsss  zTestProcessWMI.test_memory_rsscCs\tjj|jdd}tj|j}|jj}t|j }|||dfkrX|j d||fdS)N)rjrizwmi=%s, psutil=%s) rCrDrkrr8rrrr4Z PageFileUsagerW)r:rGrrZ wmi_usagerrrtest_memory_vmss    zTestProcessWMI.test_memory_vmscCs\tjj|jdd}tj|j}t|jjdd}t j dt j |j }|j ||dS)N)rjrrz %Y%m%d%H%M%S)rCrDrkrr8rrZ CreationDater,timestrftime localtimerr7)r:rGrZ wmic_createZ psutil_createrrrtest_create_times  zTestProcessWMI.test_create_timeN)rrr__doc__rrrrrrPrrrrrrrrrrrrras   rc@sXeZdZdZeddZeddZddZdd Zd d Z d d Z ddZ ddZ 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. cCstj|_dS)N)rr)rrrrrsz(TestDualProcessImplementation.setUpClasscCst|jdS)N)rr)rrrrrsz+TestDualProcessImplementation.tearDownClassc Cstj|jj}tjdttjdd}tj|jj}|j t |t |xLt t |D]<}|j ||d|j ||d|j ||||ddqZW|jstWdQRXdS)Nz(psutil._psplatform.cext.proc_memory_infomsg)rri)r\)r8rrrrrOSErrorerrnoEPERMr7rJrrfr^rr)r:Zmem_1funZmem_2rrrrrsz.TestDualProcessImplementation.test_memory_infoc CsXtj|jj}tjdttjdd(}|j tj|jj||j sJt WdQRXdS)Nz"psutil._psplatform.cext.proc_timesr )r) r8rrrrrr r r r7rr)r:ctimerrrrrsz.TestDualProcessImplementation.test_create_timec Csxtj|jj}tjdttjddH}tj|jj}|j sBt |j |j |j dd|j |j |j ddWdQRXdS)Nz"psutil._psplatform.cext.proc_timesr )rg{Gz?)r\)r8rrrKrrr r r rrr^usersystem)r:Z cpu_times_1rZ cpu_times_2rrrtest_cpu_timess z,TestDualProcessImplementation.test_cpu_timesc Cs~tj|jj}tjdttjddN}tj|jj}x,t t |D]}|j ||||ddqFW|j spt WdQRXdS)Nz(psutil._psplatform.cext.proc_io_countersr )rr<)r\)r8rrrrrr r r rrJr^rr)r:Z io_counters_1rZ io_counters_2rrrrrsz.TestDualProcessImplementation.test_io_countersc CsXtj|jj}tjdttjdd(}|j tj|jj||j sJt WdQRXdS)Nz(psutil._psplatform.cext.proc_num_handlesr )r) r8rrrrrr r r r7rr)r:rrrrrrsz.TestDualProcessImplementation.test_num_handlescCsx|tjD]p}y tj|dd}tj|dd}Wn>tk rl}z"t|}t|tjtjfs\WYdd}~Xq X|j ||q WdS)NT)Zuse_pebF) r8rmrZ proc_cmdliner r isinstancerrr7)r:raberrrrrrsz*TestDualProcessImplementation.test_cmdlineN) rrrrrrrrrrrrrrrrrr s      r cspeZdZdZeddZddgZfddZfdd Zd d Z d d Z ddZ ddZ ddZ ddZZS)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. cCs\d}xRtjdD]D}tj|d|gtjtjd}|j\}}|j|tt kr|SqWdS)Nz6import sys; sys.stdout.write(str(sys.maxsize > 2**32))zC:\Python*\python.exez-c)argsstdoutstderr) glob subprocessPopenPIPESTDOUT communicaterrr )codefilenamerAoutputrrrrfind_other_interpreters  z,RemoteProcessTestCase.find_other_interpreterz-czimport sys; sys.stdin.read()cstj|j}|dkr$tjdtr8tj|_||_ n||_tj|_ t j j }t t j|d<|j|j g|j|tjd|_|j|jg|j|tjd|_dS)Nz0could not find interpreter with opposite bitnessTHINK_OF_A_NUMBER)envstdin)rsetUpr$rrr sys executableZpython64Zpython32r5r6copyrrr test_argsrrproc32proc64)r:Z other_pythonr&) __class__rrr(#s   zRemoteProcessTestCase.setUpcs"tj|jj|jjdS)N)rtearDownr-r r.)r:)r/rrr0;s  zRemoteProcessTestCase.tearDowncCs@tj|jj}|jt|jd|j|jdd|jdS)Nr")r8rr-rr7rJrr,)r:rrrrtest_cmdline_32@sz%RemoteProcessTestCase.test_cmdline_32cCs@tj|jj}|jt|jd|j|jdd|jdS)Nr1r")r8rr.rr7rJrr,)r:rrrrtest_cmdline_64Esz%RemoteProcessTestCase.test_cmdline_64cCs&tj|jj}|j|jtjdS)N)r8rr-rr7rr5getcwd)r:rrrr test_cwd_32Jsz!RemoteProcessTestCase.test_cwd_32cCs&tj|jj}|j|jtjdS)N)r8rr.rr7rr5r4)r:rrrr test_cwd_64Nsz!RemoteProcessTestCase.test_cwd_64cCs>tj|jj}|j}|jd||j|dttj dS)Nr%) r8rr-rr6assertInr7rr5r)r:rerrrtest_environ_32Rs z%RemoteProcessTestCase.test_environ_32c Cs6tj|jj}y |jWntjk r0YnXdS)N)r8rr.rr6r)r:rrrrtest_environ_64Xs  z%RemoteProcessTestCase.test_environ_64)rrrr staticmethodr$r,r(r0r2r3r5r6r9r: __classcell__rr)r/rrs   rc@seZdZddZddZdS) TestServicescCsntdddddddg}tdd d g}tddd d d ddg}x,tjD]}|j}|j|dt|j|djd|j|dt|j|dt|j|d||ddk rtj |d|j|dt|j|dt|j|dt|j|d||j|d||j|dt|j }|dk rLtj |}|j |j tj |j}|j||qFWdS)NrunningZpausedstartpausecontinuestopstoppedZ automaticZmanualdisabledZ start_pendingZ pause_pendingZcontinue_pendingZ stop_pendingrr! display_namerstatusrZbinpathZ start_type description)rlr8win_service_iterZas_dictZassertIsInstancerZassertNotEqualr(r7rrrZ is_runningwin_service_getrr7)r:Zvalid_statusesZvalid_start_typesZservr0rrsrrrtest_win_service_itergsL   z"TestServices.test_win_service_iterc'Cstjjj}tjjj}ttjj}|jtj }tj |dWdQRX|j |j j|dtj |}t rzddd|f}n|df}t|}tjd|d|jtj |jWdQRXtjd|d|jtj |jWdQRXt rddd|f}n|df}t|}tjd|d|jtj|jWdQRXtjd|d|jtj|jWdQRX|j|jt||j|jt||j|jt||j|jt|dS)Nz???rr z/psutil._psplatform.cext.winservice_query_status)rz/psutil._psplatform.cext.winservice_query_config)r8rrERROR_SERVICE_DOES_NOT_EXISTERROR_ACCESS_DENIEDnextrHrrrrIr7 exceptionr rrrrFrrr7rrEr{)r:rLrMrcmZservicerrrrrtest_win_service_gets>       z!TestServices.test_win_service_getN)rrrrKrQrrrrr=es,r=__main__) run_from_name)=rrr rr5rrrrr)rrwarningsr8rZpsutil._compatrrrZ psutil.testsrrrr r r r r rrrrrrcatch_warnings simplefilterr=rrrCZpsutil._pswindowsrrrrPrr r4r1r2rQrrrr rr=rZpsutil.tests.runnerrS__file__rrrrs~                         *,G^F_]^