Viewing File: /opt/hc_python/lib/python3.12/site-packages/psutil/tests/__pycache__/test_windows.cpython-312.pyc

�

h0iu����dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddlZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZer>es<ej<�5ej>d�ddl Z ddl!Z!ddl"Z"ddl#Z#ddd�erddl$m%Z%ejLjNZ'ejPjSed��ejPjSed��Gd�de���Z*d�Z+e,fd�Z-Gd�de*�Z.Gd�de*�Z/Gd�de*�Z0Gd �d!e*�Z1Gd"�d#e*�Z2ejPjSed��Gd$�d%e��Z3ejPjSed��Gd&�d'e��Z4ejPjSed��Gd(�d)e��Z5y#1swY��8xYw)*zWindows specific tests.�N)�mock)�WINDOWS)�GITHUB_ACTIONS)�HAS_BATTERY)�IS_64BIT)�PYPY)�TOLERANCE_DISK_USAGE)�TOLERANCE_SYS_MEM)�PsutilTestCase)�pytest)�retry_on_failure)�sh)�
spawn_subproc)�	terminate�ignore)�convert_oserrorzWINDOWS only��reasonzpywin32 not available on PYPYc��eZdZy)�WindowsTestCaseN)�__name__�
__module__�__qualname__���J/opt/hc_python/lib64/python3.12/site-packages/psutil/tests/test_windows.pyrr5s��	rrc�x�tjd�stjd�Sd|�d�}t	|�S)z�Currently not used, but available just in case. Usage:

    >>> powershell(
        "Get-CIMInstance Win32_PageFileUsage | Select AllocatedBaseSize")
    zpowershell.exezpowershell.exe not availablezhpowershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -Command "�")�shutil�whichr�skipr)�cmd�cmdlines  r�
powershellr$;sC���<�<�(�)��{�{�9�:�:�	5�58�E��	=���g�;�rc���td|�d|���j�}dj|j�dd�j�}��.d|vr"t	�fd�|j�D��S�|�S|S)z�Currently not used, but available just in case. Usage:

    >>> wmic("Win32_OperatingSystem", "FreePhysicalMemory")
    2134124534
    z
wmic path z get ��N�,c3�.�K�|]}�|����y�w�Nr)�.0�x�	converters  �r�	<genexpr>zwmic.<locals>.<genexpr>Ts�����<�|�!��1��|�s�)r�strip�join�
splitlines�tuple�split)�path�whatr-�out�datas  `  r�wmicr8Js}���
�z�$��u�T�F�
+�
,�
2�
2�
4�C�
�7�7�3�>�>�#�A�B�'�(�.�.�0�D����$�;��<�t�z�z�|�<�<�<��T�?�"��rc��eZdZejjdejvd��d��Zd�Z	d�Z
d�Zd�Zd	�Z
y
)�TestCpuAPIs�NUMBER_OF_PROCESSORSz-NUMBER_OF_PROCESSORS env var is not availablerc�n�ttjd�}|tj�k(sJ�y)Nr;)�int�os�environ�psutil�	cpu_count)�self�num_cpuss  r�&test_cpu_count_vs_NUMBER_OF_PROCESSORSz2TestCpuAPIs.test_cpu_count_vs_NUMBER_OF_PROCESSORSas/���r�z�z�"8�9�:���6�+�+�-�-�-�-rc�h�tj�d}tj�}||k(sJ�y)N�)�win32api�
GetSystemInfor@rA�rB�	sys_value�psutil_values   r�test_cpu_count_vs_GetSystemInfoz+TestCpuAPIs.test_cpu_count_vs_GetSystemInfoks3���*�*�,�Q�/�	��'�'�)���L�(�(�(rc��tj�}td�|j�D��}t	j
�|k(sJ�y)Nc3�4K�|]}|j���y�wr*)�NumberOfLogicalProcessors�r+�procs  rr.z<TestCpuAPIs.test_cpu_count_logical_vs_wmi.<locals>.<genexpr>ts����
�7J�t�D�*�*�7J�����wmi�WMI�sum�Win32_Processorr@rA)rB�w�procss   r�test_cpu_count_logical_vs_wmiz)TestCpuAPIs.test_cpu_count_logical_vs_wmirsF���G�G�I���
�78�7H�7H�7J�
�
�����!�U�*�*�*rc��tj�}td�|j�D��}t	j
d��|k(sJ�y)Nc3�4K�|]}|j���y�wr*)�
NumberOfCoresrPs  rr.z:TestCpuAPIs.test_cpu_count_cores_vs_wmi.<locals>.<genexpr>{s����G�3F�4�D�&�&�3F�rRF)�logicalrS)rBrX�coress   r�test_cpu_count_cores_vs_wmiz'TestCpuAPIs.test_cpu_count_cores_vs_wmiys?���G�G�I���G�1�3D�3D�3F�G�G������.�%�7�7�7rc�p�tj�ttjd���k(sJ�y)NT)�percpu)r@rA�len�	cpu_times�rBs r�test_cpu_count_vs_cpu_timesz'TestCpuAPIs.test_cpu_count_vs_cpu_times~s)�����!�S��)9�)9��)F�%G�G�G�Grc��tj�}|j�d}|jt	j
�jk(sJ�|jt	j
�jk(sJ�y�Nr)	rTrUrW�CurrentClockSpeedr@�cpu_freq�current�
MaxClockSpeed�max)rBrXrQs   r�
test_cpu_freqzTestCpuAPIs.test_cpu_freq�sb���G�G�I��� � �"�1�%���%�%����):�)B�)B�B�B�B��!�!�V�_�_�%6�%:�%:�:�:�:rN)rrrr�mark�skipifr>r?rDrLrZr`rfrnrrrr:r:`sQ���[�[����b�j�j�0�>���.�	�.�)�+�8�
H�;rr:c��eZdZd�Zd�Zd�Zd�Zd�Ze�d��Z	e�d��Z
e�d��Zd	�Zd
�Z
d�Zd�Zd
�Zd�Zy)�TestSystemAPIsc���td�}tjd��j�}|D]C}d|j	dd�j�vr�&||vs�+t
j|�d��cSy)Nz
ipconfig /allT)�perniczpseudo-interface� �-z+ nic wasn't found in 'ipconfig /all' output)rr@�net_io_counters�keys�replace�lowerr�fail)rBr6�nics�nics    r�test_nic_nameszTestSystemAPIs.test_nic_names�sq����!���%�%�T�2�7�7�9���C�!�S�[�[��c�%:�%@�%@�%B�B���#�~��{�{��g�H�I���	rc��tj�j�d}t|j�tj�jk(sJ�yrh)rTrU�Win32_ComputerSystemr=�TotalPhysicalMemoryr@�virtual_memory�total�rBrXs  r�test_total_phymemz TestSystemAPIs.test_total_phymem�sC���G�G�I�*�*�,�Q�/���1�(�(�)�V�-B�-B�-D�-J�-J�J�J�Jrc���tj�j�d}tt	|j
�t
j�jz
�tksJ�yrh)
rTrU�Win32_PerfRawData_PerfOS_Memory�absr=�AvailableBytesr@r��freer
r�s  r�test_free_phymemzTestSystemAPIs.test_free_phymem�sT���G�G�I�5�5�7��:����A�$�$�%��(=�(=�(?�(D�(D�D�E��
 �	
�
 rc���tj�j�d}t|j�tj�jz
tj�jk(sJ�tj�jdk(rGtj�jdk(sJ�tj�jdk(sJ�yyrh)rTrUr�r=�CommitLimitr@r�r��swap_memoryr��usedr�s  r�test_total_swapmemz!TestSystemAPIs.test_total_swapmem�s����G�G�I�5�5�7��:����
�
���!6�!6�!8�!>�!>�>��!�!�#�)�)�
*�	
�
*�����%�%��*��%�%�'�,�,��1�1�1��%�%�'�,�,��1�1�1�+rc���tj�jdkDr�tj�jd��d}t
|j�dzt
|j�z}tj�jdk\sJ�ttj�j|z
�dksJ�tj�jdksJ�yy)Nr�_Total)�Name�drF)r@r�r�rTrU�#Win32_PerfRawData_PerfOS_PagingFiler=�PercentUsage�PercentUsage_Base�percentr�)rBrX�percentSwaps   r�test_percent_swapmemz#TestSystemAPIs.test_percent_swapmem�s�������%�%��)����	�=�=�8�=�L�Q�O�A��a�n�n�-��3�c�!�:M�:M�6N�N�K��%�%�'�/�/�1�4�4�4��v�)�)�+�3�3�k�A�B�Q�F�F�F��%�%�'�/�/�3�6�6�6�*rc���tj�j�}|D�chc]}|j��}}t	tj��}||k(sJ�ycc}wr*)rTrU�
Win32_Process�	ProcessId�setr@�pids)rBrXr,�wmi_pids�psutil_pidss     r�	test_pidszTestSystemAPIs.test_pids�sS��
�G�G�I�#�#�%��)*�+��A�A�K�K���+��&�+�+�-�(���;�&�&�&��,s�A!c��tjd��}tj�j	�}|D�]8}|D�]}|j
j
dd�|jk(s�.|js�Bd|jvr�R|jjd�r�o	tj|j�}|jt|j�k(sJ�t|j �}|j"|k(sJ�t%|j"|z
�dkDr)t'j(d|j"�d	|���ccS�� t'j(d
|���cSy#t$rY��JwxYw)NT��all�\r&�cdrom�A:i�zpsutil=z, wmi=zcan't find partition )r@�disk_partitionsrTrU�Win32_LogicalDisk�devicery�DeviceID�
mountpoint�opts�
startswith�
disk_usage�FileNotFoundErrorr�r=�Size�	FreeSpacer�r�rr{)rB�ps_parts�	wmi_parts�ps_part�wmi_part�usage�wmi_frees       r�
test_diskszTestSystemAPIs.test_disks�sS���)�)�d�3���G�G�I�/�/�1�	��G�%���>�>�)�)�$��3�x�7H�7H�H�"�-�-���'�,�,�.���)�)�4�4�T�:��� &� 1� 1�'�2D�2D� E��!�;�;�#�h�m�m�*<�<�<�<�"�8�#5�#5�6�H� �:�:��1�1�1��5�:�:��0�1�4D�D�%�{�{�%�e�j�j�\���z�B� ���-&�0�{�{�%:�7�+�#F�G�G�3 ��-����s�+E8�8	F�Fc��tj�D]�}d|jvr�tj|j
�}tj|j
�}t|d|jz
�tksJ�t|d|jz
�tksJ�|j|j|jz
k(r��J�y)Nr�rr')r@r�r�rG�GetDiskFreeSpaceExr�r�r�r�r	r�r�)rB�diskrJrKs    r�test_disk_usagezTestSystemAPIs.test_disk_usage�s����*�*�,�D��$�)�)�#�� �3�3�D�O�O�D�I�!�,�,�T�_�_�=�L��y��|�l�&7�&7�7�8�;O�O�O�O��I�a�L�<�#5�#5�5�6�9M�M�
�M��$�$��(:�(:�\�=N�=N�(N�N�N�N�-rc�B�tj�jd�D�cgc]}|r|jd�s|dz��}}t	j
d��D�cgc])}|jjd�s|j��+}}||k(sJ�ycc}wcc}w)Nz\r�r�Tr�)rG�GetLogicalDriveStringsr3r�r@r�r�)rBr,rJrKs    r�test_disk_partitionsz#TestSystemAPIs.test_disk_partitions�s����4�4�6�<�<�X�F�
�F������d�+�
��H�F�	�
��+�+��5�
�5���<�<�*�*�4�0�
�L�L�5�	�
�
�L�(�(�(��
��

s�B�.Bc�:�d}d}d}d}d}||i}tjd|j��5}tjj|�|k(sJ�tjj|�|k(sJ�|jsJ�	ddd�y#1swYyxYw)NzC:\Windows\TempzC:z\Device\HarddiskVolume1z\??\C:\Windows\Tempz$\Device\HarddiskVolume1\Windows\Tempz%psutil._pswindows.cext.QueryDosDevice��side_effect)r�patch�getr@�
_pswindows�convert_dos_path�called)rB�winpath�driveletter�
devicepath�ntpath1�ntpath2�devices�ms        r�test_convert_dos_path_drivez*TestSystemAPIs.test_convert_dos_path_drives���%����0�
�,��<���{�+��
�Z�Z�3����
�
��$�$�5�5�g�>�'�I�I�I��$�$�5�5�g�>�'�I�I�I��8�8�O�8�
�
�
�s�AB�Bc���d}d}d}tjj|�|k(sJ�tjj|�|k(sJ�tjj|�|k(sJ�y)Nz\\localhost\C$\Windows\Tempz!\??\UNC\localhost\C$\Windows\Tempz%\Device\Mup\localhost\C$\Windows\Temp)r@r�r�)rBr�r�r�s    r�test_convert_dos_path_uncz(TestSystemAPIs.test_convert_dos_path_uncsn��4��;��?��� � �1�1�'�:�g�E�E�E�� � �1�1�'�:�g�E�E�E�� � �1�1�'�:�g�E�E�Erc�4�ttj��}tj�j�}t�}|D]8}|j
|j�|j
|j��:||zs
Jd|�d|����y)Nzno common entries in z, )	r��cext�net_if_statsrTrU�Win32_NetworkAdapter�addr��NetConnectionID)rB�ps_names�wmi_adapters�	wmi_names�wmi_adapters     r�test_net_if_statsz TestSystemAPIs.test_net_if_stats"s����t�(�(�*�+���w�w�y�5�5�7���E�	�'�K��M�M�+�*�*�+��M�M�+�5�5�6�(�
�y� �	;�
"�8�*�B�y�k�:�	;� rc��tj�j�}|djj	d�d}t
j
j
|d�}t
j
jtj��}t||z
j��}|dks	J||f��y)Nr�.�%Y%m%d%H%M%SrF)rTrU�Win32_OperatingSystem�LastBootUpTimer3�datetime�strptime�
fromtimestampr@�	boot_timer��
total_seconds)rB�wmi_os�
wmi_btime_str�wmi_btime_dt�	psutil_dt�diffs      r�test_boot_timezTestSystemAPIs.test_boot_time-s�������0�0�2���q�	�0�0�6�6�s�;�A�>�
��(�(�1�1��>�
���%�%�3�3�F�4D�4D�4F�G�	��L�9�,�;�;�=�>���q�y�3�9�l�3�3�yrc��tjjj�}|dz}t	t
j
�|z
�dksJ�y)Ng@�@g�?)�ctypes�windll�kernel32�GetTickCount64r�r��uptime)rB�ms�secss   r�test_uptimezTestSystemAPIs.test_uptime7sC���]�]�
#�
#�
2�
2�
4���F�{���4�;�;�=�4�'�(�3�.�.�.rN)rrrr~r�r�r�r�r
r�r�r�r�r�r�r�r�r�rrrrrrr�s���	�K�
�2�	7�.��'��'���H��H�<��
O��
O�)��(
F�	;�4�/rrrc��eZdZd�Zej
j
ed��d��Zej
j
ed��d��Z	d�Z
d�Zd�Zd	�Z
y
)�TestSensorsBatteryc��tj�drtj��J�ytj��J�y)N�SystemBatteriesPresent)rG�GetPwrCapabilitiesr@�sensors_batteryres r�test_has_batteryz#TestSensorsBattery.test_has_batteryEs>���&�&�(�)A�B��)�)�+�7�7�7��)�)�+�3�3�3rz
no batteryrc���tj�}|jd�d}tj�}t|j|jz
�dksJ�y)N�select * from Win32_Batteryrr')rTrU�queryr@r�r�r��EstimatedChargeRemaining�rBrX�battery_wmi�battery_psutils    r�test_percentzTestSensorsBattery.test_percentKsZ���G�G�I���g�g�;�<�Q�?���/�/�1����&�&��)M�)M�M�N��
�	
�
rc��tj�}|jd�d}tj�}|j
|jdk(k(sJ�y)Nrr�)rTrUrr@r��
power_plugged�
BatteryStatusrs    r�test_power_pluggedz%TestSensorsBattery.test_power_pluggedUsP���G�G�I���g�g�;�<�Q�?���/�/�1���+�+��0I�0I�Q�0N�O�O�Orc��tjdd��5}tj��J�|jsJ�	ddd�y#1swYyxYw)N�&psutil._pswindows.cext.sensors_battery)r�rr��return_value)rr�r@r�r��rBr�s  r�test_emulate_no_batteryz*TestSensorsBattery.test_emulate_no_battery^sI��
�Z�Z�4�'�
���)�)�+�3�3�3��8�8�O�8�
�
�
�s�%A�Ac���tjdd��5}tj�jtj
k(sJ�|jsJ�	ddd�y#1swYyxYw)Nr
)r'rrrr�rr�r@r��secsleft�POWER_TIME_UNLIMITEDr�rs  r�test_emulate_power_connectedz/TestSensorsBattery.test_emulate_power_connectedf�]��
�Z�Z�4�<�
�
��&�&�(�1�1��.�.�/�
�/��8�8�O�8�
�
�
���AA"�"A+c���tjdd��5}tj�jtj
k(sJ�|jsJ�	ddd�y#1swYyxYw)Nr
)r�rrrrrs  r�test_emulate_power_chargingz.TestSensorsBattery.test_emulate_power_chargingprrc���tjdd��5}tj�jtj
k(sJ�|jsJ�	ddd�y#1swYyxYw)Nr
)rrr���r)rr�r@r�r�POWER_TIME_UNKNOWNr�rs  r�test_emulate_secs_left_unknownz1TestSensorsBattery.test_emulate_secs_left_unknownzsY��
�Z�Z�4�&�
���&�&�(�1�1�V�5N�5N�N�
�N��8�8�O�8�
�
�
�rN)rrrr�rrorprrrrrrr rrrr�r�Dsq��4��[�[���K����=�
�>�
��[�[���K����=�P�>�P����rr�c��eZdZed��Zed��Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Zd�Zy)�TestProcessc�6�t�j|_yr*�r�pid��clss r�
setUpClasszTestProcess.setUpClass�����/�%�%��rc�.�t|j�yr*�rr%r&s r�
tearDownClasszTestProcess.tearDownClass�����#�'�'�rc��tjd�}tjtj�5|j�ddd�y#1swYyxYwrh)r@�Processr�raises�AccessDenied�kill�rB�ps  r�
test_issue_24zTestProcess.test_issue_24�s7���N�N�1���
�]�]�6�.�.�
/�
�F�F�H�0�
/�
/�s�A�Ac�Z�tjd�}|j�dk(sJ�t|�|j	�|j�dk\sJ�	|j
�dd\}}|dkDsJ�y#tj$rtj�ddvr�YywxYw)N��Systemgrrr'>�win-7�win7�vista)
r@r/�name�str�username�create_time�memory_infor1�platform�uname)rBr4�rss�_vmss    r�test_special_pidzTestProcess.test_special_pid�s����N�N�1����v�v�x�8�#�#�#�	�A��	�
�
���}�}��#�%�%�%�	��
�
����+�I�C����7�N�7���"�"�	��~�~���"�*D�D��E�	�s�A:�:-B*�)B*c���tj|j�}tjt
�5|j
tj�ddd�y#1swYyxYwr*)	r@r/r%rr0�
ValueError�send_signal�signal�SIGINTr3s  r�test_send_signalzTestProcess.test_send_signal�s<���N�N�4�8�8�$��
�]�]�:�
&�
�M�M�&�-�-�(�'�
&�
&�s� A"�"A+c��tjtj��}|j	�}tjtjtjtj��}|j	�}||dzk(sJ�tj|�|j	�|k(sJ�y)Nr')r@r/r>�getpid�num_handlesrG�OpenProcess�win32con�PROCESS_QUERY_INFORMATION�FALSE�CloseHandle)rBr4�before�handle�afters     r�test_num_handles_incrementz&TestProcess.test_num_handles_increment�s����N�N�2�9�9�;�'��������%�%��.�.�����	�	��
���
�
������
�"�"�"����V�$��}�}��&�(�(�(rc�v�tj|j�j�}|j	t
j�|j	t
j�|j�|j�tjtj�5|j	t
j�ddd�tjtj�5|j	t
j�ddd�y#1swY�UxYw#1swYyxYwr*)
r@r/rr%rHrI�CTRL_C_EVENT�CTRL_BREAK_EVENTr2�waitrr0�
NoSuchProcessr3s  r�test_ctrl_signalszTestProcess.test_ctrl_signals�s����N�N�4�-�-�/�3�3�4��	�
�
�f�)�)�*�	�
�
�f�-�-�.�	����	����
�]�]�6�/�/�
0�
�M�M�&�-�-�.�1�
�]�]�6�/�/�
0�
�M�M�&�1�1�2�1�
0�1�
0��
0�
0�s�/ D#�: D/�#D,�/D8c���tjtj�}|j	d�rtjd�Stj�j�|k(sJ�y)N�$zrunning as service account)
rG�
GetUserNameExrP�NameSamCompatible�endswithrr!r@r/r>)rBr<s  r�
test_usernamezTestProcess.test_username�sT���%�%�h�&@�&@�A���=�=����;�;�;�<�<��~�~��(�(�*�d�2�2�2rc�*�tjddtj��j	�}djt
j�j��}|jdd�}|jdd�}||k(sJ�y)Nz[ ]+rurr&)
�re�subrG�GetCommandLiner/r0r@r/r#ryrIs   r�test_cmdlinezTestProcess.test_cmdline�sx���F�F�7�C��)@�)@�)B�C�I�I�K�	��x�x���� 0� 8� 8� :�;��
�%�%�c�2�.�	�#�+�+�C��4���L�(�(�(rc�J�tjtjtjtj��}|jtj|�tj|�}tj�j�}||k(sJ�yr*)rGrOrPrQrRr>rM�
addCleanuprS�win32process�GetPriorityClassr@r/�nice�rBrUrJrKs    r�	test_nicezTestProcess.test_nice�sr���%�%��.�.�����	�	��
��	
����,�,�f�5� �1�1�&�9�	��~�~�'�,�,�.���y�(�(�(rc���tjtjtj|j
�}|j
tj|�tj|�}tj|j
�j�}|d|jk(sJ�|d|jk(sJ�|d|jk(sJ�|d|j k(sJ�|d|j"k(sJ�|d|j$k(sJ�|d|j&k(sJ�|d|j(k(sJ�|j*|jk(sJ�|j,|j&k(sJ�y)	N�PeakWorkingSetSize�WorkingSetSize�QuotaPeakPagedPoolUsage�QuotaPagedPoolUsage�QuotaPeakNonPagedPoolUsage�QuotaNonPagedPoolUsage�
PagefileUsage�PeakPagefileUsage)rGrOrPrQrRr%rjrSrk�GetProcessMemoryInfor@r/r@�	peak_wset�wset�peak_paged_pool�
paged_pool�peak_nonpaged_pool�
nonpaged_pool�pagefile�
peak_pagefilerC�vmsrns    r�test_memory_infozTestProcess.test_memory_info�s���%�%��.�.�������
��	
����,�,�f�5� �5�5�f�=�	��~�~�d�h�h�/�;�;�=���-�.�,�2H�2H�H�H�H��)�*�l�.?�.?�?�?�?��/�0��+�+�
,�	
�
,��.�/�<�3J�3J�J�J�J��2�3��.�.�
/�	
�
/�
�.�/�<�3M�3M�M�	
�M���)�\�-B�-B�B�B�B��,�-��1K�1K�K�K�K����<�#4�#4�4�4�4����<�#8�#8�8�8�8rc�t�tjtjtj|j
�}|j
tj|�tj|j
�}|j�|j�}tj|�}||k(sJ�yr*)rGrOrPrQrRr%rjrSr@r/rr[rk�GetExitCodeProcess)rBrUr4rKrJs     r�	test_waitzTestProcess.test_waits����%�%��.�.�������
��	
����,�,�f�5��N�N�4�8�8�$��	���
��v�v�x�� �3�3�F�;�	��y�(�(�(rc�h�d�}tjtjtj|j
�}|j
tj|�|tj|�d�}tj|j
�j�}||k(sJ�y)Nc�P�td�D�cgc]
}d|z|zs�|��c}Scc}w)N�@r')�range)r,�is  r�from_bitmaskz3TestProcess.test_cpu_affinity.<locals>.from_bitmasks(��$�R�y�9�y�!�Q�!�V�q�L�A�y�9�9��9s�
#�#r)
rGrOrPrQrRr%rjrSrk�GetProcessAffinityMaskr@r/�cpu_affinity)rBr�rUrJrKs     r�test_cpu_affinityzTestProcess.test_cpu_affinitys���	:��%�%��.�.�������
��	
����,�,�f�5� ��/�/��7��:�
�	��~�~�d�h�h�/�<�<�>���y�(�(�(rc�,�tjtjtjtj��}|jtj|�tj|�}tj�j�}|j|dk(sJ�|j|dk(sJ�|j |dk(sJ�|j"|dk(sJ�|j$|dk(sJ�|j&|dk(sJ�y)N�ReadOperationCount�WriteOperationCount�ReadTransferCount�WriteTransferCount�OtherOperationCount�OtherTransferCount)rGrOrPrQrRr>rMrjrSrk�GetProcessIoCountersr@r/�io_counters�
read_count�write_count�
read_bytes�write_bytes�other_count�other_bytesrns    r�test_io_counterszTestProcess.test_io_counters!s���%�%��.�.�����	�	��
��	
����,�,�f�5� �5�5�f�=�	��~�~�'�3�3�5���&�&�)�4H�*I�I�I�I��'�'�9�5J�+K�K�K�K��&�&�)�4G�*H�H�H�H��'�'�9�5I�+J�J�J�J��'�'�9�5J�+K�K�K�K��'�'�9�5I�+J�J�J�Jrc��ddl}ddl}d}|jjj	|d|j
�}|j
|jjj|�|jj�}|jjj||j|��|j}tj|j
�j�}||k(sJ�y)Nr�)r��ctypes.wintypesr�r�rOr%rjrS�wintypes�DWORD�GetProcessHandleCount�byref�valuer@r/rN)rBr�rQrU�hndcntrJrKs       r�test_num_handleszTestProcess.test_num_handles/s�����$)�!����'�'�3�3�%�q�$�(�(�
��	
����
�
�.�.�:�:�F�C����&�&�(���
�
���4�4��L�F�L�L��(�	
��L�L�	��~�~�d�h�h�/�;�;�=���y�(�(�(rc��t�}d|_tjd|��5tjd�5}t	j
�}t
jtj�5|j�ddd�ddd�ddd�jdk\sJ�y#1swY�+xYw#1swY�/xYw#1swY�3xYw)Ni+z psutil._psplatform.cext.proc_cwdr�z
time.sleeprF)�OSError�winerrorrr�r@r/rr0r1�cwd�
call_count)rB�excr�r4s    r�test_error_partial_copyz#TestProcess.test_error_partial_copyAs����i�����
�Z�Z�:��
L����L�)�Q��N�N�$���]�]�6�#6�#6�7��E�E�G�8�*�M�
�|�|�q� � � �8�7��*�)��M�
L�s:�C
�8B>�7B2�B>�C
�2B;�7B>�>C	�C
�
Cc��tj�ddz}tjj|�}t	j
tj�5|j�ddd�y#1swYyxYw)Nri��)r@r��_psplatformr/rr0r\�exe)rBr%rQs   r�test_exezTestProcess.test_exeLsV���k�k�m�B��%�'���!�!�)�)�#�.��
�]�]�6�/�/�
0��H�H�J�1�
0�
0�s�A7�7BN)rrr�classmethodr(r,r5rErKrWr]rcrhror�r�r�r�r�r�r�rrrr"r"�st���&��&������
�")�
	)�	3�3�	)�.)�9�6	)�)�K�)�$	!�rr"c���eZdZdZed��Zed��Zd�Zejjed��d��Zd�Z
d	�Ze�d
��Ze�d��Zd�Zy
)�TestProcessWMIz%Compare Process API results with WMI.c�6�t�j|_yr*r$r&s rr(zTestProcessWMI.setUpClassXr)rc�.�t|j�yr*r+r&s rr,zTestProcessWMI.tearDownClass\r-rc���tj�j|j��d}t	j
|j�}|j
�|jk(sJ�y�N�r�r)rTrUr�r%r@r/r<�Caption�rBrXr4s   r�	test_namezTestProcessWMI.test_name`sN���G�G�I�#�#�d�h�h�#�7��:���N�N�4�8�8�$���v�v�x�1�9�9�$�$�$rz!unreliable path on GITHUB_ACTIONSrc��tj�j|j��d}t	j
|j�}|j
�j�|jj�k(sJ�yr�)	rTrUr�r%r@r/r�rz�ExecutablePathr�s   rr�zTestProcessWMI.test_exefsc��
�G�G�I�#�#�d�h�h�#�7��:���N�N�4�8�8�$���u�u�w�}�}��!�"2�"2�"8�"8�":�:�:�:rc� �tj�j|j��d}t	j
|j�}dj
|j��|jjdd�k(sJ�y)Nr�rrurr&)
rTrUr�r%r@r/r0r#�CommandLineryr�s   rrhzTestProcessWMI.test_cmdlinepsd���G�G�I�#�#�d�h�h�#�7��:���N�N�4�8�8�$���x�x��	�	��$��
�
�(=�(=�c�2�(F�F�F�Frc��tj�j|j��d}t	j
|j�}|j
�\}}}|�d|��}|j�|k(sJ�y)Nr�rr�)rTrUr�r%r@r/�GetOwnerr>)rBrXr4�domain�_r>s      rrczTestProcessWMI.test_usernameusl���G�G�I�#�#�d�h�h�#�7��:���N�N�4�8�8�$���j�j�l����8��X�R��z�*���z�z�|�x�'�'�'rc��tj�j|j��d}t	j
|j�}|j
�j}|t|j�k(sJ�yr�)
rTrUr�r%r@r/r@rCr=rr)rBrXr4rCs    r�test_memory_rsszTestProcessWMI.test_memory_rss|s`���G�G�I�#�#�d�h�h�#�7��:���N�N�4�8�8�$���m�m�o�!�!���c�!�*�*�+�+�+�+rc�J�tj�j|j��d}t	j
|j�}|j
�j}t|j�}|||dzhvrtjd|�d|���Sy)Nr�rr�zwmi=z	, psutil=)rTrUr�r%r@r/r@r�r=�
PageFileUsagerr{)rBrXr4r��	wmi_usages     r�test_memory_vmszTestProcessWMI.test_memory_vms�s����G�G�I�#�#�d�h�h�#�7��:���N�N�4�8�8�$���m�m�o�!�!��
����(�	��y�)�d�"2�3�3��;�;��i�[�	�#��?�@�@�4rc�n�tj�j|j��d}t	j
|j�}t
|jjd�d�}tjdtj|j���}||k(sJ�y)Nr�rr�r�)
rTrUr�r%r@r/r=�CreationDater3�time�strftime�	localtimer?)rBrXr4�wmic_create�
psutil_creates     r�test_create_timezTestProcessWMI.test_create_time�s����G�G�I�#�#�d�h�h�#�7��:���N�N�4�8�8�$���!�.�.�.�.�s�3�A�6�7���
�
��D�N�N�1�=�=�?�;�
�
��m�+�+�+rN)rrr�__doc__r�r(r,r�rrorprr�rhrcr
r�r�r�rrrr�r�Us���/��&��&�����%��[�[����B���;��;�G�
(���,��,���
A��
A�,rr�c�T�eZdZdZed��Zed��Zd�Zd�Zd�Z	d�Z
d�Zd	�Zy
)�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.
    c�6�t�j|_yr*r$r&s rr(z(TestDualProcessImplementation.setUpClass�r)rc�.�t|j�yr*r+r&s rr,z+TestDualProcessImplementation.tearDownClass�r-rc���tj|j�j�}t	j
dt��5}tj|j�j�}t|�t|�k(sJ�tt|��D]/}||dk\sJ�||dk\sJ�t||||z
�dkr�/J�|jsJ�	ddd�y#1swYyxYw)Nz(psutil._psplatform.cext.proc_memory_infor�ri)r@r/r%r@rr��PermissionErrorrcr�r�r�)rB�mem_1�fun�mem_2r�s     rr�z.TestDualProcessImplementation.test_memory_info�s������t�x�x�(�4�4�6��
�Z�Z�6�'�
���N�N�4�8�8�,�8�8�:�E��u�:��U��+�+�+��3�u�:�&���Q�x�1�}�$�}��Q�x�1�}�$�}��5��8�e�A�h�.�/�#�5�5�5�'��:�:��:�
�
�
�s�	B	C.�C.�.C7c�@�tj|j�j�}t	j
dt��5}tj|j�j�|k(sJ�|jsJ�	ddd�y#1swYyxYw)N�"psutil._psplatform.cext.proc_timesr�)r@r/r%r?rr�r�r�)rB�ctimer�s   rr�z.TestDualProcessImplementation.test_create_time�st�����t�x�x�(�4�4�6��
�Z�Z�0�'�
���>�>�$�(�(�+�7�7�9�U�B�B�B��:�:��:�
�
�
��
�	AB�Bc���tj|j�j�}t	j
dt��5}tj|j�j�}|jsJ�t|j|jz
�dksJ�t|j|jz
�dksJ�	ddd�y#1swYyxYw)Nr�r�g{�G�z�?)r@r/r%rdrr�r�r�r��user�system)rB�cpu_times_1r��cpu_times_2s    r�test_cpu_timesz,TestDualProcessImplementation.test_cpu_times�s����n�n�T�X�X�.�8�8�:��
�Z�Z�0�'�
�� �.�.����2�<�<�>�K��:�:��:��{�'�'�+�*:�*:�:�;�d�B�B�B��{�)�)�K�,>�,>�>�?�$�F�F�F�
�
�
�s
�	B
C�C&c��tj|j�j�}t	j
dt��5}tj|j�j�}tt|��D]}t||||z
�dkr�J�|jsJ�	ddd�y#1swYyxYw)Nz(psutil._psplatform.cext.proc_io_countersr�rF)r@r/r%r�rr�r�r�rcr�r�)rB�
io_counters_1r��
io_counters_2r�s     rr�z.TestDualProcessImplementation.test_io_counters�s������t�x�x�0�<�<�>�
�
�Z�Z�6�'�
��"�N�N�4�8�8�4�@�@�B�M��3�}�-�.���=��+�m�A�.>�>�?�!�C�C�C�/��:�:��:�
�
�
�s�	AC�&C�C
c�@�tj|j�j�}t	j
dt��5}tj|j�j�|k(sJ�|jsJ�	ddd�y#1swYyxYw)Nz(psutil._psplatform.cext.proc_num_handlesr�)r@r/r%rNrr�r�r�)rBrNr�s   rr�z.TestDualProcessImplementation.test_num_handles�st���n�n�T�X�X�.�:�:�<��
�Z�Z�6�'�
���>�>�$�(�(�+�7�7�9�[�H�H�H��:�:��:�
�
�
�r�c�:�tj�D]8}	tj|d��}tj|d��}||k(r�8J�y#t$r@}t|�}t
|tjtjf�s�Yd}~��d}~wwxYw)NT)�use_pebF)	r@r�r��proc_cmdliner�r�
isinstancer1r\)rBr%�a�b�errs     rrhz*TestDualProcessImplementation.test_cmdline�s����;�;�=�C�

��%�%�c�4�%�8���%�%�c�5�%�9���A�v�
�v�!���
�%�c�*��!��&�-�-�v�/C�/C�D�����
�s�.A�	B�6B�BN)
rrrr�r�r(r,r�r�r�r�r�rhrrrr�r��sN����&��&�������	G�	��rr�c�h��eZdZdZed��ZddgZ�fd�Z�fd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Z�xZS)
�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.
    c��d}tjd�D]s}tj|d|gtjtj��}|j�\}}|j
�|tt�k(s�q|cSy)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�filenamerQ�outputr�s     r�find_other_interpreterz,RemoteProcessTestCase.find_other_interpreter�s{��H���	�	�":�;�H��#�#���d�+�!���!�(�(��D�
�(�(�*�I�F�A��I�I�K����\�*�*���<rr�zimport sys; sys.stdin.read()c�f��t�|��|j�}|�tjd�St
rtj|_||_	n||_tj|_	tjj�}ttj��|d<|j|jg|j z|t"j$��|_|j|jg|j z|t"j$��|_y)Nz0could not find interpreter with opposite bitness�THINK_OF_A_NUMBER)�env�stdin)�super�setUprrr!r�sys�
executable�python64�python32r>r?�copyr=rMr�	test_argsr�r��proc32�proc64)rB�other_pythonr�	__class__s   �rrzRemoteProcessTestCase.setUps����
��
���2�2�4�����;�;�B��
���N�N�D�M�(�D�M�(�D�M��N�N�D�M��j�j�o�o���#&�r�y�y�{�#3��� ��(�(�
�]�]�O�d�n�n�,�#�Z�_�_�)�
����(�(�
�]�]�O�d�n�n�,�#�Z�_�_�)�
��rc���t�|��|jj�|jj�yr*)r
�tearDownrrr)rBrs �rrzRemoteProcessTestCase.tearDown)s.���
���������!������!rc���tj|jj�}t	|j��dk(sJ�|j�dd|jk(sJ�y�N�r')r@r/rr%rcr#rr3s  r�test_cmdline_32z%RemoteProcessTestCase.test_cmdline_32.�O���N�N�4�;�;�?�?�+���1�9�9�;��1�$�$�$��y�y�{�1�2��$�.�.�0�0�0rc���tj|jj�}t	|j��dk(sJ�|j�dd|jk(sJ�yr)r@r/rr%rcr#rr3s  r�test_cmdline_64z%RemoteProcessTestCase.test_cmdline_643rrc��tj|jj�}|j	�tj�k(sJ�yr*)r@r/rr%r�r>�getcwdr3s  r�test_cwd_32z!RemoteProcessTestCase.test_cwd_328�2���N�N�4�;�;�?�?�+���u�u�w�"�)�)�+�%�%�%rc��tj|jj�}|j	�tj�k(sJ�yr*)r@r/rr%r�r>r r3s  r�test_cwd_64z!RemoteProcessTestCase.test_cwd_64<r"rc���tj|jj�}|j	�}d|vsJ�|dtt
j��k(sJ�y)Nr)r@r/rr%r?r=r>rM)rBr4�es   r�test_environ_32z%RemoteProcessTestCase.test_environ_32@sP���N�N�4�;�;�?�?�+��
�I�I�K��"�a�'�'�'��$�%��R�Y�Y�[�)9�9�9�9rc��tj|jj�}	|j	�y#tj
$rYywxYwr*)r@r/rr%r?r1r3s  r�test_environ_64z%RemoteProcessTestCase.test_environ_64Fs>���N�N�4�;�;�?�?�+��	�
�I�I�K���"�"�	��	�s�<�A�A)rrrr��staticmethodrrrrrrr!r$r'r)�
__classcell__)rs@rr�r��sQ����� �� �"�5�6�I�
�0"�
1�
1�
&�&�:�rr�c��eZdZd�Zd�Zy)�TestServicesc� �hd�}hd�}hd�}tj�D�]j}|j�dk(r�|j�}t	|dt
�sJ�|dj
�sJ�t	|dt
�sJ�t	|dt
�sJ�|d|vsJ�|d	�tj|d	�t	|d
t
�sJ�t	|dt
�sJ�t	|dt
�sJ�|d|vsJ�|d|vsJ�t	|dt
�sJ�|j�}|�'tj|�}|j�sJ�tj|j��}||k(r��kJ�y)
N>�stop�pause�start�paused�running�stopped�continue>�manual�disabled�	automatic>r2r3r4�stop_pending�
pause_pending�
start_pending�continue_pending�WaaSMedicSvcr<�display_namer>�statusr%�binpath�
start_type�description)r@�win_service_iterr<�as_dictr�r=r/r/r%�
is_running�win_service_get)rB�valid_statuses�valid_start_types�servr7r%r4�ss        r�test_win_service_iterz"TestServices.test_win_service_iterUs���
��@��
���+�+�-�D��y�y�{�n�,���<�<�>�D��d�6�l�C�0�0�0���<�%�%�'�'�'��d�>�2�C�8�8�8��d�:�.��4�4�4���>�^�3�3�3��E�{�&����t�E�{�+��d�9�o�s�3�3�3��d�:�.��4�4�4��d�<�0�#�6�6�6���%�):�:�:�:���>�^�3�3�3��d�=�1�3�7�7�7��(�(�*�C����N�N�3�'���|�|�~�%�~��&�&�t�y�y�{�3�A��1�9��9�7.rc���tjjj}tjjj}ttj��j�}tjtj�5}tj|dz�ddd�jj|dzk(sJ�tj|�}tddd�}||_tj d|��5tjtj�5|j#�ddd�ddd�tj d|��5tjtj�5|j%�ddd�ddd�tddd�}||_tj d|��5tjtj&�5|j#�ddd�ddd�tj d|��5tjtj&�5|j%�ddd�ddd�|j�t)|�vsJ�|j+�t)|�vsJ�|j�t-|�vsJ�|j+�t-|�vsJ�y#1swY��JxYw#1swY���xYw#1swY���xYw#1swY��zxYw#1swY��xYw#1swY��$xYw#1swY��)xYw#1swY��xYw#1swY��xYw)Nz???r�msgz/psutil._psplatform.cext.winservice_query_statusr�z/psutil._psplatform.cext.winservice_query_config)r@r�r��ERROR_SERVICE_DOES_NOT_EXIST�ERROR_ACCESS_DENIED�nextrCr<rr0r\rFr�r�r�rr�r?r>r1r=r>�repr)rBrNrOr<�cm�servicer�s       r�test_win_service_getz!TestServices.test_win_service_get�s������#�#�@�@�	%�%�0�0�5�5�I�I���F�+�+�-�.�3�3�5��
�]�]�6�/�/�
0�B��"�"�4�%�<�0�1��x�x�}�}��u��,�,�,��(�(��.���a���"��3���
�Z�Z�=�3�
����v�3�3�4���� �5�
�
�Z�Z�=�3�
����v�3�3�4�� � �"�5�
��a���"��*���
�Z�Z�=�3�
����v�2�2�3���� �4�
�
�Z�Z�=�3�
����v�2�2�3�� � �"�4�
��|�|�~��W��-�-�-��#�#�%��W��5�5�5��|�|�~��g��.�.�.��#�#�%��g��6�6�6�K1�
0��5�4��
�
��5�4��
�
��4�3��
�
��4�3��
�
�s��K8�$L�:L�L�2$L,�L�'L,�"$M�L9�M�>$M�"M�3M�8L�L	�
L�L�L)	�$L,�,L6�9M	�>M�M�M	�M�M(N)rrrrKrTrrrr-r-Ss
��/�b,7rr-)6r�r�r�r�r>rArerrIr�rr��warnings�unittestrr@r�psutil.testsrrrrr	r
rrr
rrr�catch_warnings�simplefilterrGrPrkrT�psutil._pswindowsrr�r�rorprr$r=r8r:rrr�r"r�r�r�r-rrr�<module>r[s����
���	��	�
�
��
����
��'�$�!��-�*�'��)��&�"�
�4�	 ��	 �	 �	"�����h�'�����
#��1�������������K���7������D�!@��A�	�n�	�B�8�	�� #��,%;�/�%;�Pt/�_�t/�x>��>�LH�/�H�VB,�_�B,�P������K���7�T�N�T�8�T�n������K���7�U�N�U�8�U�z������K���7�^7�>�^7�8�^7�[
#�	"�s� #G9�9H
Back to Directory File Manager