U
    ;g.                     @   sl  d 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 ddlmZ ddlmZ ddlmZ ddlm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dS )"zContracts tests. These tests mainly check API sanity in terms of
returned types and APIs availability.
Some of these are duplicates of tests test_system.py and test_process.py.
    N)AIX)FREEBSD)LINUX)MACOS)NETBSD)OPENBSD)POSIX)SUNOS)WINDOWS)GITHUB_ACTIONS)HAS_CPU_FREQ)HAS_NET_IO_COUNTERS)HAS_SENSORS_FANS)HAS_SENSORS_TEMPERATURES)SKIP_SYSCONS)PsutilTestCase)create_sockets)enum)is_namedtuple)kernel_version)pytestc                   @   sH   e Zd Zdd Zdd Zdd Zdd Zejj	e
o4ed	d
dd ZdS )TestAvailConstantsAPIsc                 C   s   t tdtptptkstd S )NZPROCFS_PATH)hasattrpsutilr   r	   r   AssertionErrorself r   [/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/psutil/tests/test_contracts.pytest_PROCFS_PATH0   s    z'TestAvailConstantsAPIs.test_PROCFS_PATHc                 C   sj   | j }|ttdt |ttdt |ttdt |ttdt |ttdt |ttdt d S )NZABOVE_NORMAL_PRIORITY_CLASSZBELOW_NORMAL_PRIORITY_CLASSZHIGH_PRIORITY_CLASSZIDLE_PRIORITY_CLASSZNORMAL_PRIORITY_CLASSZREALTIME_PRIORITY_CLASSassertEqualr   r   r
   r   Zaer   r   r   test_win_priority3   s    z(TestAvailConstantsAPIs.test_win_priorityc                 C   sJ   | j }|ttdt |ttdt |ttdt |ttdt d S )NZIOPRIO_CLASS_NONEZIOPRIO_CLASS_RTZIOPRIO_CLASS_BEZIOPRIO_CLASS_IDLE)r!   r   r   r   r"   r   r   r   test_linux_ioprio_linux<   s
    z.TestAvailConstantsAPIs.test_linux_ioprio_linuxc                 C   sJ   | j }|ttdt |ttdt |ttdt |ttdt d S )NZIOPRIO_HIGHZIOPRIO_NORMALZ
IOPRIO_LOWZIOPRIO_VERYLOWr    r"   r   r   r   test_linux_ioprio_windowsC   s
    z0TestAvailConstantsAPIs.test_linux_ioprio_windows%unsupported on GITHUB_ACTIONS + LINUXreasonc                 C   s  | j }|ttdtpt |ttdtp*t |ttdtp>t |ttdtpRt |ttdtpft |ttdtpzt |ttdtpt |ttdtpt |ttd	tpt |ttd
tpt |ttdtpt |ttdt trt dkr|ttdt t dkr0|ttdt t dkrL|ttdt t dkrh|ttdt t dkr|ttdt |ttdt |ttdt |ttdt d S )NZRLIM_INFINITYZ	RLIMIT_ASZRLIMIT_COREZ
RLIMIT_CPUZRLIMIT_DATAZRLIMIT_FSIZEZRLIMIT_MEMLOCKZRLIMIT_NOFILEZRLIMIT_NPROCZ
RLIMIT_RSSZRLIMIT_STACKZRLIMIT_LOCKS)         ZRLIMIT_MSGQUEUE)r)   r*      ZRLIMIT_NICEZRLIMIT_RTPRIO)r)   r*      ZRLIMIT_RTTIMEZRLIMIT_SIGPENDINGZRLIMIT_SWAPZRLIMIT_SBSIZEZRLIMIT_NPTS)r!   r   r   r   r   r   r   r"   r   r   r   test_rlimitJ   s6    z"TestAvailConstantsAPIs.test_rlimitN)__name__
__module____qualname__r   r#   r$   r%   r   markskipifr   r   r.   r   r   r   r   r   /   s   	r   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestAvailSystemAPIsc                 C   s   t tdtkstd S )NZwin_service_iterr   r   r
   r   r   r   r   r   test_win_service_itero   s    z)TestAvailSystemAPIs.test_win_service_iterc                 C   s   t tdtkstd S )NZwin_service_getr5   r   r   r   r   test_win_service_getr   s    z(TestAvailSystemAPIs.test_win_service_getc                 C   s&   t tdtptptptptks"td S )Ncpu_freq)r   r   r   r   r
   r   r   r   r   r   r   r   test_cpu_frequ   s    z!TestAvailSystemAPIs.test_cpu_freqc                 C   s   t tdtptkstd S )Nsensors_temperatures)r   r   r   r   r   r   r   r   r   test_sensors_temperaturesz   s    z-TestAvailSystemAPIs.test_sensors_temperaturesc                 C   s   t tdtkstd S )Nsensors_fans)r   r   r   r   r   r   r   r   test_sensors_fans}   s    z%TestAvailSystemAPIs.test_sensors_fansc                 C   s"   t tdtptptptkstd S )NZsensors_battery)r   r   r   r
   r   r   r   r   r   r   r   test_battery   s    z TestAvailSystemAPIs.test_batteryN)	r/   r0   r1   r6   r7   r9   r;   r=   r>   r   r   r   r   r4   n   s   r4   c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zej	j
eo<edddd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )TestAvailProcessAPIsc                 C   s4   t tjdtp(tp(tp(tp(tp(tp(t	p(t
ks0td S )Nenviron)r   r   Processr   r   r
   r   r	   r   r   r   r   r   r   r   r   test_environ   s     
z!TestAvailProcessAPIs.test_environc                 C   s   t tjdtkstd S NZuidsr   r   rA   r   r   r   r   r   r   	test_uids   s    zTestAvailProcessAPIs.test_uidsc                 C   s   t tjdtkstd S rC   rD   r   r   r   r   	test_gids   s    zTestAvailProcessAPIs.test_gidsc                 C   s   t tjdtkstd S )NterminalrD   r   r   r   r   test_terminal   s    z"TestAvailProcessAPIs.test_terminalc                 C   s   t tjdtptkstd S )NZionice)r   r   rA   r   r
   r   r   r   r   r   test_ionice   s    z TestAvailProcessAPIs.test_ionicer&   r'   c                 C   s   t tjdtptkstd S )NZrlimit)r   r   rA   r   r   r   r   r   r   r   r.      s    z TestAvailProcessAPIs.test_rlimitc                 C   s"   t tjd}|tpt kstd S )NZio_counters)r   r   rA   r   r	   r   r   Zhasitr   r   r   test_io_counters   s    z%TestAvailProcessAPIs.test_io_countersc                 C   s   t tjdtkstd S )NZnum_fdsrD   r   r   r   r   test_num_fds   s    z!TestAvailProcessAPIs.test_num_fdsc                 C   s   t tjdtkstd S )NZnum_handles)r   r   rA   r
   r   r   r   r   r   test_num_handles   s    z%TestAvailProcessAPIs.test_num_handlesc                 C   s    t tjdtptptkstd S )NZcpu_affinity)r   r   rA   r   r
   r   r   r   r   r   r   test_cpu_affinity   s    

z&TestAvailProcessAPIs.test_cpu_affinityc                 C   s    t tjdtptptkstd S )NZcpu_num)r   r   rA   r   r   r	   r   r   r   r   r   test_cpu_num   s    

z!TestAvailProcessAPIs.test_cpu_numc                 C   s*   t tjd}|tptptpt ks&td S )NZmemory_maps)r   r   rA   r   r   r   r   r   rJ   r   r   r   test_memory_maps   s    z%TestAvailProcessAPIs.test_memory_mapsN)r/   r0   r1   rB   rE   rF   rH   rI   r   r2   r3   r   r   r.   rK   rL   rM   rN   rO   rP   r   r   r   r   r?      s    
r?   c                   @   s  e Zd ZdZedd ZedfddZdd Zd	d
 Z	dd Z
dd ZejjeoZe dkddejje dddd Zdd Zdd Zejjedddd Zdd Zdd Zejje ddd d! Zejje ddd"d# Zejje ddd$d% Zd&d' Z d(d) Z!d*S )+TestSystemAPITypeszhCheck the return types of system related APIs.
    https://github.com/giampaolo/psutil/issues/1039.
    c                 C   s   t  | _d S N)r   rA   proc)clsr   r   r   
setUpClass   s    zTestSystemAPITypes.setUpClassTc                 C   s8   t |st|D ]"}t||s"t|r|dkstqd S )Nr   )r   r   
isinstance)r   nttype_Zgezeronr   r   r   assert_ntuple_of_nums   s
    z(TestSystemAPITypes.assert_ntuple_of_numsc                 C   s.   |  t  tjddD ]}|  | qd S )NT)Zpercpu)rZ   r   Z	cpu_times)r   rW   r   r   r   test_cpu_times   s    z!TestSystemAPITypes.test_cpu_timesc                 C   s0   t tjd dtstt tjddts,td S )Nintervalgh㈵>)rV   r   Zcpu_percentfloatr   r   r   r   r   test_cpu_percent   s    z#TestSystemAPITypes.test_cpu_percentc                 C   s(   |  tjd d |  tjdd d S )Nr\   g-C6?)rZ   r   Zcpu_times_percentr   r   r   r   test_cpu_times_percent   s    z)TestSystemAPITypes.test_cpu_times_percentc                 C   s   t t tstd S rR   )rV   r   	cpu_countintr   r   r   r   r   test_cpu_count   s    z!TestSystemAPITypes.test_cpu_countarm64zskipped due to #1892r'   znot supportedc                 C   s0   t  d krtd| jt  ttfd d S )Nzcpu_freq() returns NonerX   )r   r8   r   skiprZ   r^   rb   r   r   r   r   r9      s    
z TestSystemAPITypes.test_cpu_freqc                 C   s:   t jdd D ]$\}}t|ts&t| j|td qd S )NT)Zperdiskre   )r   Zdisk_io_countersitemsrV   strr   rZ   rb   )r   kvr   r   r   test_disk_io_counters   s    z(TestSystemAPITypes.test_disk_io_countersc                 C   sR   t  D ]D}t|jtstt|jts,tt|jts<tt|jtstqd S rR   )	r   Zdisk_partitionsrV   Zdevicerh   r   Z
mountpointZfstypeopts)r   Zdiskr   r   r   test_disk_partitions   s
    z'TestSystemAPITypes.test_disk_partitionszrequires rootc              	   C   sN   t  > td}t|tt|ks*t|D ]}t|s.tq.W 5 Q R X d S )Nall)r   r   Znet_connectionslensetr   r   )r   retconnr   r   r   test_net_connections   s
    
z'TestSystemAPITypes.test_net_connectionsc                 C   s   t   D ]r\}}t|ts"t|D ]V}t|jtjs<tt|j	tsLtt|j
ttd fsdtt|jttd fs&tq&qd S rR   )r   Znet_if_addrsrg   rV   rh   r   familyr   IntEnumaddressnetmasktype	broadcast)r   ifnameaddrsaddrr   r   r   test_net_if_addrs  s    z$TestSystemAPITypes.test_net_if_addrsc                 C   sj   t   D ]X\}}t|ts"tt|jts2tt|jt	j
sDtt|jtsTtt|jtstqd S rR   )r   Znet_if_statsrg   rV   rh   r   ZisupboolZduplexr   ru   speedrb   Zmtu)r   rz   infor   r   r   test_net_if_stats  s    z$TestSystemAPITypes.test_net_if_statsc                 C   s$   t jddD ]}t|tstqd S )NT)Zpernic)r   Znet_io_countersrV   rh   r   )r   rz   r   r   r   test_net_io_counters  s    z'TestSystemAPITypes.test_net_io_countersc                 C   s\   t   D ]J\}}t|ts"t|D ].}t|jts:tt|jtt	t
d fs&tq&qd S rR   )r   r<   rg   rV   rh   r   labelcurrentr^   rb   rx   r   nameZunitsunitr   r   r   r=     s
    z$TestSystemAPITypes.test_sensors_fansc                 C   s   t   D ]~\}}t|ts"t|D ]b}t|jts:tt|jtt	t
d fsTtt|jtt	t
d fsntt|jtt	t
d fs&tq&qd S rR   )r   r:   rg   rV   rh   r   r   r   r^   rb   rx   highcriticalr   r   r   r   r;   &  s    z,TestSystemAPITypes.test_sensors_temperaturesc                 C   s   t t tstd S rR   )rV   r   Z	boot_timer^   r   r   r   r   r   test_boot_time1  s    z!TestSystemAPITypes.test_boot_timec                 C   sj   t  D ]\}t|jtstt|jttd fs4tt|jttd fsLtt|j	t
td fstqd S rR   )r   ZusersrV   r   rh   r   rG   rx   hostpidrb   )r   userr   r   r   
test_users5  s
    zTestSystemAPITypes.test_usersN)"r/   r0   r1   __doc__classmethodrU   r^   rZ   r[   r_   r`   rc   r   r2   r3   r   platformmachiner   r9   rk   rm   r   rs   r}   r   r   r   r   r=   r   r;   r   r   r   r   r   r   rQ      s8   
 

	



rQ   c                   @   s&   e Zd Zejje dddd ZdS )TestProcessWaitTypez	not POSIXr'   c                 C   sD   t |  j}|  | }|tj ks0tt	|t
js@td S rR   )r   rA   Zspawn_testprocr   	terminatewaitsignalSIGTERMr   rV   r   ru   )r   pcoder   r   r   test_negative_signal?  s
    z(TestProcessWaitType.test_negative_signalN)r/   r0   r1   r   r2   r3   r   r   r   r   r   r   r   >  s   r   )r   r   r   r   r   r   r   r   r   r   r   r	   r
   Zpsutil.testsr   r   r   r   r   r   r   r   r   r   r   r   r   r4   r?   rQ   r   r   r   r   r   <module>   s:   ?>z