U €1gØ„ã @sÄdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl m Z ddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!e r’es’e  "¡0e  #d¡ddl$Z$ddl%Z%ddl&Z&ddl'Z'W5QRXe r¤ddl(m)Z)e j*j+Z+ej,j-e ddej,j-eddej,j-eoÚe ddGdd„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 ddGd,d-„d-eƒƒZ7ej,j-e ddGd.d/„d/eƒƒZ8ej,j-e ddGd0d1„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úI/opt/hc_python/lib64/python3.8/site-packages/psutil/tests/test_windows.pyr;srcCs&tdƒst d¡‚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ƒ ¡}d | ¡dd…¡ ¡}ˆdk rbd|krXt‡fdd„| ¡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Ú ^szwmic..)rÚstripÚjoinÚ splitlinesÚtupleÚsplit)ÚpathÚwhatr*ÚoutÚdatarr)rÚwmicTs r5c@sReZdZejjdejkdddd„ƒZdd„Z dd „Z d d „Z d d „Z dd„Z dS)Ú TestCpuAPIsÚNUMBER_OF_PROCESSORSz-NUMBER_OF_PROCESSORS env var is not availablercCs"ttjdƒ}|t ¡kst‚dS)Nr7)ÚintÚosÚenvironÚpsutilÚ cpu_countÚAssertionError)ÚselfZnum_cpusrrrÚ&test_cpu_count_vs_NUMBER_OF_PROCESSORSksz2TestCpuAPIs.test_cpu_count_vs_NUMBER_OF_PROCESSORScCs$t ¡d}t ¡}||ks t‚dS)Né)Úwin32apiZ GetSystemInfor;r<r=©r>Ú sys_valueÚ psutil_valuerrrÚtest_cpu_count_vs_GetSystemInfous z+TestCpuAPIs.test_cpu_count_vs_GetSystemInfocCs2t ¡}tdd„| ¡Dƒƒ}t ¡|ks.t‚dS)Ncss|] }|jVqdS©N)ZNumberOfLogicalProcessors©r'ÚprocrrrÚ ~sz.©ÚwmiÚWMIÚsumÚWin32_Processorr;r<r=)r>ÚwZprocsrrrÚtest_cpu_count_logical_vs_wmi|s ÿz)TestCpuAPIs.test_cpu_count_logical_vs_wmicCs6t ¡}tdd„| ¡Dƒƒ}tjdd|ks2t‚dS)Ncss|] }|jVqdSrF)Z NumberOfCoresrGrrrrI…sz:TestCpuAPIs.test_cpu_count_cores_vs_wmi..F)ZlogicalrJ)r>rOZcoresrrrÚtest_cpu_count_cores_vs_wmiƒsz'TestCpuAPIs.test_cpu_count_cores_vs_wmicCs t ¡ttjddƒkst‚dS)NT)Zpercpu)r;r<ÚlenÚ cpu_timesr=©r>rrrÚtest_cpu_count_vs_cpu_timesˆsz'TestCpuAPIs.test_cpu_count_vs_cpu_timescCs@t ¡}| ¡d}|jt ¡jks(t‚|jt ¡j ksrOrHrrrÚ test_cpu_freq‹s zTestCpuAPIs.test_cpu_freqN)rrrrÚmarkÚskipifr9r:r?rErPrQrUrYrrrrr6jsþ r6c@sŽeZdZdd„Zdd„Zdd„Zdd„Zd d „Zej j e d d e ƒd d„ƒƒZ e ƒdd„ƒZe ƒdd„ƒZdd„Zdd„Zdd„Zdd„ZdS)ÚTestSystemAPIscCsRtdƒ}tjdd ¡}|D]0}d| dd¡ ¡kr6q||kr| d|¡‚qdS)Nz ipconfig /allT)Zperniczpseudo-interfaceú ú-z-%r nic wasn't found in 'ipconfig /all' output)rr;Znet_io_countersÚkeysÚreplaceÚlowerÚfail)r>r3ZnicsZnicrrrÚtest_nic_names“sÿzTestSystemAPIs.test_nic_namescCs,t ¡ ¡d}t|jƒt ¡jks(t‚dSrV) rKrLZWin32_ComputerSystemr8ZTotalPhysicalMemoryr;Úvirtual_memoryÚtotalr=©r>rOrrrÚtest_total_phymemžsz TestSystemAPIs.test_total_phymemcCs4t ¡ ¡d}tt|jƒt ¡jƒt ks0t ‚dSrV) rKrLÚWin32_PerfRawData_PerfOS_MemoryÚabsr8ZAvailableBytesr;rdÚfreer r=rfrrrÚtest_free_phymem¢s ÿÿzTestSystemAPIs.test_free_phymemcCsht ¡ ¡d}t|jƒt ¡jt ¡jks2t ‚t ¡jdkrdt ¡j dksRt ‚t ¡j dksdt ‚dSrV) rKrLrhr8Z CommitLimitr;rdreÚ swap_memoryr=rjÚusedrfrrrÚtest_total_swapmem©sÿÿz!TestSystemAPIs.test_total_swapmemcCs|t ¡jdkrxt ¡jddd}t|jƒdt|jƒ}t ¡j dksLt ‚t t ¡j |ƒdksft ‚t ¡j dksxt ‚dS)NrZ_Total)ÚNameédr@) r;rlrerKrLZ#Win32_PerfRawData_PerfOS_PagingFiler8Z PercentUsageZPercentUsage_BaseÚpercentr=ri)r>rOZ percentSwaprrrÚtest_percent_swapmem³s z#TestSystemAPIs.test_percent_swapmemztest not relieable on appveyorrcCs:t ¡ ¡}tdd„|Dƒƒ}tt ¡ƒ}||ks6t‚dS)NcSsg|] }|j‘qSr©Z ProcessIdr&rrrr+Ðsz,TestSystemAPIs.test_pids..)rKrLÚ Win32_ProcessÚsetr;Úpidsr=)r>rOZwmi_pidsZ psutil_pidsrrrÚ test_pidsÊs  zTestSystemAPIs.test_pidsc Cstjdd}t ¡ ¡}|D]Þ}|D]Â}|j dd¡|jkr$|jsFqd|j krTq|j  d¡rdqzt  |j¡}Wnt k rŽYqYnX|j t|jƒks¤t‚t|jƒ}|j|ks¼t‚t|j|ƒdkrâ| d|j|f¡‚qq$| d t|ƒ¡‚qdS) NT©Úallú\r#ÚcdromúA:i zpsutil=%s, wmi=%szcan't find partition %s)r;Údisk_partitionsrKrLZWin32_LogicalDiskZdevicer`ZDeviceIDÚ mountpointÚoptsÚ startswithÚ disk_usagerrer8ÚSizer=Z FreeSpacerjrirbÚrepr)r>Zps_partsZ wmi_partsZps_partZwmi_partÚusageZwmi_freerrrÚ test_disksÔs0       ÿzTestSystemAPIs.test_diskscCs€t ¡D]r}d|jkrqt |j¡}t |j¡}t|d|jƒt ksJt ‚t|d|j ƒt ksdt ‚|j |j |jkst ‚qdS)Nr{rr$) r;r}rrAZGetDiskFreeSpaceExr~rrirjr r=rerm)r>ZdiskrCrDrrrÚtest_disk_usageós    ÿzTestSystemAPIs.test_disk_usagecCs>dd„t ¡ d¡Dƒ}dd„tjddDƒ}||ks:t‚dS)NcSs"g|]}|r| d¡s|d‘qS)r|rz)r€r&rrrr+s þz7TestSystemAPIs.test_disk_partitions..z\cSsg|]}|j d¡s|j‘qS)r|)r~r€r&rrrr+s þTrx)rAZGetLogicalDriveStringsr0r;r}r=rBrrrÚtest_disk_partitionss þ þz#TestSystemAPIs.test_disk_partitionscCs\tt ¡ƒ}t ¡ ¡}tƒ}|D]}| |j¡| |j¡q"||@sXt d||fƒ‚dS)Nzno common entries in %s, %s) ruÚcextZ net_if_statsrKrLZWin32_NetworkAdapterÚaddroZNetConnectionIDr=)r>Zps_namesZ wmi_adaptersZ wmi_namesZ wmi_adapterrrrÚtest_net_if_stats s    þz TestSystemAPIs.test_net_if_statscCs^t ¡ ¡}|dj d¡d}tj |d¡}tj t  ¡¡}t ||  ¡ƒ}|dksZt ‚dS)NrÚ.ú %Y%m%d%H%M%Sr@) rKrLZWin32_OperatingSystemZLastBootUpTimer0ÚdatetimeÚstrptimeÚ fromtimestampr;Ú boot_timeriÚ total_secondsr=)r>Zwmi_osZ wmi_btime_strZ wmi_btime_dtZ psutil_dtÚdiffrrrÚtest_boot_times ÿzTestSystemAPIs.test_boot_timec Cs¬tjdddt ¡dks t‚W5QRXtjdddt ¡dksJt‚W5QRXtjdddt ¡dkstt‚W5QRXtjdddt ¡dksžt‚W5QRXdS)Nz psutil._pswindows.cext.boot_timer@©Z return_valueééiM)rÚpatchr;rr=rTrrrÚtest_boot_time_fluctuation#sz)TestSystemAPIs.test_boot_time_fluctuationN)rrrrcrgrkrnrrrrZr[rrrwr…r†r‡rŠr“r˜rrrrr\’s         r\c@sheZdZdd„Zejje dddd„ƒZejje dddd„ƒZ d d „Z d d „Z d d„Z dd„Z dS)ÚTestSensorsBatterycCs2t ¡drt ¡dk s.t‚nt ¡dks.t‚dS)NZSystemBatteriesPresent)rAZGetPwrCapabilitiesr;Úsensors_batteryr=rTrrrÚtest_has_battery5s z#TestSensorsBattery.test_has_batteryz no batteryrcCs:t ¡}| d¡d}t ¡}t|j|jƒdks6t‚dS)Núselect * from Win32_Batteryrr$) rKrLÚqueryr;ršrirqZEstimatedChargeRemainingr=©r>rOZ battery_wmiZbattery_psutilrrrÚ test_percent;sÿÿzTestSensorsBattery.test_percentcCs6t ¡}| d¡d}t ¡}|j|jdkks2t‚dS)Nrœré)rKrLrr;ršZ power_pluggedZ BatteryStatusr=ržrrrÚtest_power_pluggedEsz%TestSensorsBattery.test_power_pluggedc Cs8tjddd }t ¡dks t‚|js*t‚W5QRXdS)Nú&psutil._pswindows.cext.sensors_battery)ré€rrr”)rr—r;ršr=Úcalled©r>ÚmrrrÚtest_emulate_no_batteryNsþz*TestSensorsBattery.test_emulate_no_batteryc Cs<tjddd$}t ¡jtjks$t‚|js.t‚W5QRXdS)Nr¢)r$rrrr”©rr—r;ršÚsecsleftZPOWER_TIME_UNLIMITEDr=r¤r¥rrrÚtest_emulate_power_connectedVsÿÿÿz/TestSensorsBattery.test_emulate_power_connectedc Cs<tjddd$}t ¡jtjks$t‚|js.t‚W5QRXdS)Nr¢)rérrr”r¨r¥rrrÚtest_emulate_power_charging`sÿÿÿz.TestSensorsBattery.test_emulate_power_chargingc Cs<tjddd$}t ¡jtjks$t‚|js.t‚W5QRXdS)Nr¢)rrréÿÿÿÿr”)rr—r;ršr©ZPOWER_TIME_UNKNOWNr=r¤r¥rrrÚtest_emulate_secs_left_unknownjsþÿz1TestSensorsBattery.test_emulate_secs_left_unknownN)rrrr›rrZr[rrŸr¡r§rªr¬r®rrrrr™4s    r™c@sœeZdZedd„ƒZedd„ƒZdd„Zdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#S)$Ú TestProcesscCstƒj|_dSrF©rÚpid©ÚclsrrrÚ setUpClass{szTestProcess.setUpClasscCst|jƒdSrF©rr±r²rrrÚ tearDownClassszTestProcess.tearDownClassc Cs.t d¡}t tj¡| ¡W5QRXdSrV)r;ÚProcessrÚraisesÚ AccessDeniedÚkill©r>ÚprrrÚ test_issue_24ƒs zTestProcess.test_issue_24cCsŒt d¡}| ¡dkst‚t|ƒ| ¡| ¡dks:t‚z| ¡dd…\}}Wn(tjk rzt   ¡ddkrv‚YnX|dksˆt‚dS)Nr•ÚSystemgr r$)Zvistazwin-7Zwin7r) r;r·Únamer=ÚstrÚusernameÚ create_timeÚ memory_infor¹ÚplatformÚuname)r>r¼ÚrssZ_vmsrrrÚtest_special_pidˆs zTestProcess.test_special_pidc Cs2t |j¡}t t¡| tj¡W5QRXdSrF) r;r·r±rr¸Ú ValueErrorÚ send_signalÚsignalÚSIGINTr»rrrÚtest_send_signal™s  zTestProcess.test_send_signalcCsbt t ¡¡}| ¡}t tjtj t ¡¡}| ¡}||dksDt ‚t  |¡| ¡|ks^t ‚dS)Nr$) r;r·r9ÚgetpidÚ num_handlesrAÚ OpenProcessÚwin32conÚPROCESS_QUERY_INFORMATIONÚFALSEr=Ú CloseHandle)r>r¼ÚbeforeÚhandleÚafterrrrÚtest_num_handles_incrementžsÿ z&TestProcess.test_num_handles_incrementc Cs„t | ¡j¡}| tj¡| tj¡| ¡|  ¡t   tj ¡| tj¡W5QRXt   tj ¡| tj¡W5QRXdSrF) r;r·rr±rÉrÊZ CTRL_C_EVENTZCTRL_BREAK_EVENTrºÚwaitrr¸Ú NoSuchProcessr»rrrÚtest_ctrl_signals©s  zTestProcess.test_ctrl_signalscCs8t tj¡}| d¡r t d¡‚t ¡  ¡|ks4t ‚dS)Nú$zrunning as service account) rAZ GetUserNameExrÐZNameSamCompatibleÚendswithrrr;r·rÁr=)r>r¿rrrÚ test_username´s   zTestProcess.test_usernamecCsft ddt ¡¡ ¡}d t ¡ ¡¡}|ddkrD|dkrVnn|  ddd¡}||ksbt ‚dS)Nz[ ]+r]rú"r#r ) ÚreÚsubrAZGetCommandLiner,r-r;r·r!r`r=rBrrrÚ test_cmdline½s  zTestProcess.test_cmdlinecCsJt tjtjt ¡¡}| tj|¡t   |¡}t   ¡  ¡}||ksFt‚dSrF)rArÏrÐrÑrÒr9rÍÚ addCleanuprÓÚ win32processZGetPriorityClassr;r·Únicer=©r>rÕrCrDrrrÚ test_nice×sÿ  zTestProcess.test_nicecCsðt tjtj|j¡}| tj|¡t  |¡}t   |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)rArÏrÐrÑrÒr±rârÓrãZGetProcessMemoryInfor;r·rÃZ peak_wsetr=ZwsetZpeak_paged_poolZ paged_poolZpeak_nonpaged_poolZ nonpaged_poolZpagefileZ peak_pagefilerÆÚvmsrårrrÚtest_memory_infoàs2ÿ ÿÿÿÿ ÿzTestProcess.test_memory_infocCsXt tjtj|j¡}| tj|¡t  |j¡}|  ¡|  ¡}t   |¡}||ksTt‚dSrF)rArÏrÐrÑrÒr±rârÓr;r·rrØrãZGetExitCodeProcessr=)r>rÕr¼rDrCrrrÚ test_waitûsÿ  zTestProcess.test_waitcCs\dd„}t tjtj|j¡}| tj|¡|t  |¡dƒ}t   |j¡  ¡}||ksXt ‚dS)Ncs‡fdd„tdƒDƒS)Ncsg|]}d|>ˆ@r|‘qS)r$r)r'Úi©r(rrr+s zGTestProcess.test_cpu_affinity..from_bitmask..é@)ÚrangerìrrìrÚ from_bitmasksz3TestProcess.test_cpu_affinity..from_bitmaskr)rArÏrÐrÑrÒr±rârÓrãZGetProcessAffinityMaskr;r·Z cpu_affinityr=)r>rïrÕrCrDrrrÚtest_cpu_affinitysÿ ÿzTestProcess.test_cpu_affinitycCsªt tjtjt ¡¡}| tj|¡t   |¡}t   ¡  ¡}|j|dksLt‚|j|dks^t‚|j|dkspt‚|j|dks‚t‚|j|dks”t‚|j|dks¦t‚dS)NZReadOperationCountZWriteOperationCountZReadTransferCountZWriteTransferCountZOtherOperationCountZOtherTransferCount)rArÏrÐrÑrÒr9rÍrârÓrãZGetProcessIoCountersr;r·Ú io_countersZ read_countr=Z write_countÚ read_bytesÚ write_bytesÚ other_countZ other_bytesrårrrÚtest_io_counterssÿ  zTestProcess.test_io_counterscCs€ddl}ddl}d}|jj |d|j¡}| |jjj|¡|j  ¡}|jj  ||  |¡¡|j }t  |j¡ ¡}||ks|t‚dS)Nré)ÚctypesZctypes.wintypesÚwindllÚkernel32rÏr±rârÓZwintypesZDWORDZGetProcessHandleCountZbyrefÚvaluer;r·rÎr=)r>r÷rÑrÕZhndcntrCrDrrrÚtest_num_handles"s"ÿ ÿzTestProcess.test_num_handlesc Csvtƒ}d|_tjd|dDt d¡.}t ¡}t tj¡|  ¡W5QRXW5QRXW5QRX|j dksrt ‚dS)Ni+z psutil._psplatform.cext.proc_cwd©Z side_effectz time.sleepr@) Ú WindowsErrorÚwinerrorrr—r;r·rr¸r¹ÚcwdZ call_countr=)r>Úexcr¦r¼rrrÚtest_error_partial_copy4s &z#TestProcess.test_error_partial_copyc Cs@t ¡dd}tj |¡}t tj¡| ¡W5QRXdS)Nr­iŸ†)r;rvÚ _psplatformr·rr¸rÙÚexe)r>r±rHrrrÚtest_exe?s zTestProcess.test_exeN)rrrÚ classmethodr´r¶r½rÇrÌr×rÚrÝrárærérêrðrõrûrrrrrrr¯zs&        r¯c@s|eZdZdZedd„ƒZedd„ƒZdd„Zej j e dd d d „ƒZ d d „Z dd„Zeƒdd„ƒZeƒdd„ƒZdd„ZdS)ÚTestProcessWMIz%Compare Process API results with WMI.cCstƒj|_dSrFr°r²rrrr´KszTestProcessWMI.setUpClasscCst|jƒdSrFrµr²rrrr¶OszTestProcessWMI.tearDownClasscCs8t ¡j|jdd}t |j¡}| ¡|jks4t‚dS©Nrsr) rKrLrtr±r;r·r¿ZCaptionr=©r>rOr¼rrrÚ test_nameSs zTestProcessWMI.test_namez!unreliable path on GITHUB_ACTIONSrcCs@t ¡j|jdd}t |j¡}| ¡ ¡|j ¡ksrOr¼ÚdomainÚ_rÁrrrrÝhs   zTestProcessWMI.test_usernamecCsBt ¡j|jdd}t |j¡}| ¡j}|t|j ƒks>t ‚dSr) rKrLrtr±r;r·rÃrÆr8rçr=)r>rOr¼rÆrrrÚtest_memory_rssos  zTestProcessWMI.test_memory_rsscCs\t ¡j|jdd}t |j¡}| ¡j}t|j ƒ}|||dfkrX|  d||f¡‚dS)Nrsrrözwmi=%s, psutil=%s) rKrLrtr±r;r·rÃrèr8Z PageFileUsagerb)r>rOr¼rèZ wmi_usagerrrÚtest_memory_vmsvs    zTestProcessWMI.test_memory_vmscCs\t ¡j|jdd}t |j¡}t|j d¡dƒ}t   dt   |  ¡¡¡}||ksXt ‚dS)Nrsrr‹rŒ)rKrLrtr±r;r·rÀZ CreationDater0ÚtimeÚstrftimeÚ localtimerÂr=)r>rOr¼Z wmic_createZ psutil_createrrrÚtest_create_timeƒs  ÿzTestProcessWMI.test_create_timeN)rrrÚ__doc__rr´r¶r rrZr[rrrárÝrr r rrrrrrHs$  ÿ   rc@sXeZdZdZedd„ƒZedd„ƒZdd„Zdd „Zd d „Z d d „Z dd„Z dd„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|_dSrFr°r²rrrr´›sz(TestDualProcessImplementation.setUpClasscCst|jƒdSrFrµr²rrrr¶Ÿsz+TestDualProcessImplementation.tearDownClassc Cs²t |j¡ ¡}tjdttjdƒd‚}t |j¡ ¡}t |ƒt |ƒksLt ‚t t |ƒƒD]@}||dkslt ‚||dks|t ‚t ||||ƒdksXt ‚qX|j s¤t ‚W5QRXdS)Nz(psutil._psplatform.cext.proc_memory_infoÚmsgrüri)r;r·r±rÃrr—ÚOSErrorÚerrnoÚEPERMrRr=rîrir¤)r>Zmem_1ÚfunZmem_2rërrrré£s þz.TestDualProcessImplementation.test_memory_infoc CsXt |j¡ ¡}tjdttjdƒd(}t |j¡ ¡|ks@t ‚|j sJt ‚W5QRXdS)Nú"psutil._psplatform.cext.proc_timesrrü) r;r·r±rÂrr—rrrr=r¤)r>Úctimerrrrr±s þz.TestDualProcessImplementation.test_create_timec Cs€t |j¡ ¡}tjdttjdƒdP}t |j¡ ¡}|j sBt ‚t |j |j ƒdksZt ‚t |j |j ƒdksrt ‚W5QRXdS)Nrrrüg{®Gáz„?)r;r·r±rSrr—rrrr¤r=riÚuserÚsystem)r>Z cpu_times_1rZ cpu_times_2rrrÚtest_cpu_timesºs þ z,TestDualProcessImplementation.test_cpu_timesc Cs~t |j¡ ¡}tjdttjdƒdN}t |j¡ ¡}t t |ƒƒD] }t ||||ƒdksDt ‚qD|j spt ‚W5QRXdS)Nz(psutil._psplatform.cext.proc_io_countersrrür@)r;r·r±rñrr—rrrrîrRrir=r¤)r>Z io_counters_1rZ io_counters_2rërrrrõÅs þz.TestDualProcessImplementation.test_io_countersc CsXt |j¡ ¡}tjdttjdƒd(}t |j¡ ¡|ks@t ‚|j sJt ‚W5QRXdS)Nz(psutil._psplatform.cext.proc_num_handlesrrü) r;r·r±rÎrr—rrrr=r¤)r>rÎrrrrrûÐs þz.TestDualProcessImplementation.test_num_handlesc Cs~t ¡D]p}z tj|dd}tj|dd}Wn>tk rj}z t|ƒ}t|tjtjfƒsZ‚W5d}~XYqX||kst ‚qdS)NT)Zuse_pebF) r;rvrˆZ proc_cmdlinerrÚ isinstancer¹rÙr=)r>r±ÚaÚbÚerrrrrráÙs  ÿz*TestDualProcessImplementation.test_cmdlineN) rrrrrr´r¶rérrrõrûrárrrrrs       rcspeZdZdZedd„ƒZddgZ‡fdd„Z‡fdd „Zd d „Z d d „Z dd„Z dd„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}t d¡D]H}tj|d|gtjtjd}| ¡\}}| ¡|tt ƒkr|SqdS)Nz6import sys; sys.stdout.write(str(sys.maxsize > 2**32))zC:\Python*\python.exeú-c)ÚargsÚstdoutÚstderr) ÚglobÚ subprocessÚPopenÚPIPEÚSTDOUTÚ communicaterØrÀr )ÚcodeÚfilenamerHÚoutputr rrrÚfind_other_interpreterðsý z,RemoteProcessTestCase.find_other_interpreterr#zimport sys; sys.stdin.read()cs tƒ ¡| ¡}|dkr$t d¡‚tr8tj|_||_ n||_tj|_ t j   ¡}t t  ¡ƒ|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ÚsetUpr0rrr ÚsysÚ executableZpython64Zpython32r9r:ÚcopyrÀrÍrÚ test_argsr(r*Úproc32Úproc64)r>Z other_pythonr2©Ú __class__rrr4s. ÿ  ÿ ÿzRemoteProcessTestCase.setUpcs"tƒ ¡|j ¡|j ¡dSrF)rÚtearDownr9r,r:rTr;rrr=s  zRemoteProcessTestCase.tearDowncCs@t |jj¡}t| ¡ƒdks"t‚| ¡dd…|jks)r;r·r:r±rRr!r=r8r»rrrÚtest_cmdline_64&sz%RemoteProcessTestCase.test_cmdline_64cCs&t |jj¡}| ¡t ¡ks"t‚dSrF)r;r·r9r±rÿr9Úgetcwdr=r»rrrÚ test_cwd_32+sz!RemoteProcessTestCase.test_cwd_32cCs&t |jj¡}| ¡t ¡ks"t‚dSrF)r;r·r:r±rÿr9rBr=r»rrrÚ test_cwd_64/sz!RemoteProcessTestCase.test_cwd_64cCs>t |jj¡}| ¡}d|ks"t‚|dtt ¡ƒks:t‚dS)Nr1) r;r·r9r±r:r=rÀr9rÍ)r>r¼ÚerrrÚtest_environ_323s z%RemoteProcessTestCase.test_environ_32cCs6t |jj¡}z | ¡Wntjk r0YnXdSrF)r;r·r:r±r:r¹r»rrrÚtest_environ_649s  z%RemoteProcessTestCase.test_environ_64)rrrrÚ staticmethodr0r8r4r=r@rArCrDrFrGÚ __classcell__rrr;rr"ès   r"c@seZdZdd„Zdd„ZdS)Ú TestServicescCsxtdddddddgƒ}tdd d gƒ}tddd d d ddgƒ}t ¡D].}| ¡}t|dtƒsbt‚|d ¡srt‚t|dtƒs„t‚t|dtƒs–t‚|d|ks¦t‚|ddk rÀt |d¡t|dtƒsÒt‚t|dtƒsät‚t|dtƒsöt‚|d|kst‚|d|kst‚t|dtƒs.t‚|  ¡}|dk rXt |¡}|  ¡sXt‚t  |  ¡¡}||ksBt‚qBdS)NÚrunningZpausedÚstartÚpauseÚcontinueÚstopÚstoppedZ automaticZmanualÚdisabledZ start_pendingZ pause_pendingZcontinue_pendingZ stop_pendingr¿Ú display_namerÁÚstatusr±ZbinpathZ start_typeÚ description) rur;Úwin_service_iterÚas_dictrrÀr=r,r·r±Z is_runningÚwin_service_getr¿)r>Zvalid_statusesZvalid_start_typesZservr4r±r¼ÚsrrrÚtest_win_service_iterHsPù ù    z"TestServices.test_win_service_iterc Csòtjjj}tjjj}tt ¡ƒ ¡}t  tj ¡}t  |d¡W5QRX|j j|dks^t ‚t  |¡}trzddd|f}n|df}t|Ž}tjd|d&t  tj ¡| ¡W5QRXW5QRXtjd|d&t  tj ¡| ¡W5QRXW5QRXtrddd|f}n|df}t|Ž}tjd|d&t  tj¡| ¡W5QRXW5QRXtjd|d&t  tj¡| ¡W5QRXW5QRX| ¡t|ƒks¬t ‚| ¡t|ƒksÂt ‚| ¡t|ƒksØt ‚| ¡t|ƒksît ‚dS)Nz???rrz/psutil._psplatform.cext.winservice_query_statusrüz/psutil._psplatform.cext.winservice_query_config)r;rrˆÚERROR_SERVICE_DOES_NOT_EXISTÚERROR_ACCESS_DENIEDÚnextrUr¿rr¸rÙrWrúr=r rýrr—rSrÁr¹rÀrRrƒ)r>rZr[r¿ÚcmZservicer$rrrrÚtest_win_service_gettsXÿ  ÿÿÿÿz!TestServices.test_win_service_getN)rrrrYr^rrrrrJFs,rJ):rrrr'r9rÄrßrÊr(r5rÚwarningsr;rZpsutil._compatrrrZ psutil.testsrrrr r r r r rrrrrrrÚcatch_warningsÚ simplefilterrArÐrãrKZpsutil._pswindowsrrrˆrZr[rr"r8r5r6r\r™r¯rrr"rJrrrrÚs~                        ÿ (#FOHW]