
    Xh.                        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e      Z G d de      Z G d de      Z G d de      Z G d  d!e      Zy)"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                   r    e Zd Zd Zd Zd Zd Zej                  j                  e
xr ed      d        Zy)	TestAvailConstantsAPIsc                 V    t        t        d      t        xs t        xs t        k(  sJ y )NPROCFS_PATH)hasattrpsutilr   r
   r   selfs    g/var/www/html/cjf29f/d23bf782/d32178f2/venv/lib/python3.12/site-packages/psutil/tests/test_contracts.pytest_PROCFS_PATHz'TestAvailConstantsAPIs.test_PROCFS_PATH0   s!    v}-%2G52GCHHH    c                 `   | 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               y )NABOVE_NORMAL_PRIORITY_CLASSBELOW_NORMAL_PRIORITY_CLASSHIGH_PRIORITY_CLASSIDLE_PRIORITY_CLASSNORMAL_PRIORITY_CLASSREALTIME_PRIORITY_CLASSassertEqualr   r   r   r   aes     r    test_win_priorityz(TestAvailConstantsAPIs.test_win_priority3   sy    
76897C
76897C
76017;
76017;
7623W=
7645w?r"   c                     | j                   } |t        t        d      t                |t        t        d      t                |t        t        d      t                |t        t        d      t               y )NIOPRIO_CLASS_NONEIOPRIO_CLASS_RTIOPRIO_CLASS_BEIOPRIO_CLASS_IDLE)r+   r   r   r   r,   s     r    test_linux_ioprio_linuxz.TestAvailConstantsAPIs.test_linux_ioprio_linux<   sU    
76./7
76,-u5
76,-u5
76./7r"   c                     | j                   } |t        t        d      t                |t        t        d      t                |t        t        d      t                |t        t        d      t               y )NIOPRIO_HIGHIOPRIO_NORMAL
IOPRIO_LOWIOPRIO_VERYLOWr*   r,   s     r    test_linux_ioprio_windowsz0TestAvailConstantsAPIs.test_linux_ioprio_windowsC   sR    
76=)73
76?+W5
76<('2
76+,g6r"   %unsupported on GITHUB_ACTIONS + LINUXreasonc                    | j                   } |t        t        d      t        xs t                |t        t        d      t        xs t                |t        t        d      t        xs t                |t        t        d      t        xs t                |t        t        d      t        xs t                |t        t        d      t        xs t                |t        t        d      t        xs t                |t        t        d      t        xs t                |t        t        d	      t        xs t                |t        t        d
      t        xs t                |t        t        d      t        xs t                |t        t        d      t               t
        rt               dk\  r |t        t        d      t               t               dk\  r |t        t        d      t               t               dk\  r |t        t        d      t               t               dk\  r |t        t        d      t               t               dk\  r |t        t        d      t                |t        t        d      t                |t        t        d      t                |t        t        d      t               y )NRLIM_INFINITY	RLIMIT_ASRLIMIT_CORE
RLIMIT_CPURLIMIT_DATARLIMIT_FSIZERLIMIT_MEMLOCKRLIMIT_NOFILERLIMIT_NPROC
RLIMIT_RSSRLIMIT_STACKRLIMIT_LOCKS)         RLIMIT_MSGQUEUE)rK   rL      RLIMIT_NICERLIMIT_RTPRIO)rK   rL      RLIMIT_RTTIMERLIMIT_SIGPENDINGRLIMIT_SWAPRLIMIT_SBSIZERLIMIT_NPTS)r+   r   r   r   r   r	   r   r,   s     r    test_rlimitz"TestAvailConstantsAPIs.test_rlimitJ   s   
 
76?+U-=g>
76;')9':
76=)5+;G<
76<(%*:7;
76=)5+;G<
76>*E,<W=
76+,e.>w?
76?+U-=g>
76>*E,<W=
76<(%*:7;
76>*E,<W=
76>*E29,76#45u=:-76=159:-76?3U;:-76?3U;9,76#67?
76=)73
76?+W5
76=)73r"   N)__name__
__module____qualname__r!   r.   r4   r:   r   markskipifr   r   rX    r"   r    r   r   /   sK    I@87 [[ 56  4	4r"   r   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)TestAvailSystemAPIsc                 6    t        t        d      t        k(  sJ y )Nwin_service_iterr   r   r   r   s    r    test_win_service_iterz)TestAvailSystemAPIs.test_win_service_itero   s    v12g===r"   c                 6    t        t        d      t        k(  sJ y )Nwin_service_getrc   r   s    r    test_win_service_getz(TestAvailSystemAPIs.test_win_service_getr   s    v01W<<<r"   c                 v    t        t        d      t        xs t        xs t        xs t
        xs t        k(  sJ y )Ncpu_freq)r   r   r   r   r   r   r   r   s    r    test_cpu_freqz!TestAvailSystemAPIs.test_cpu_frequ   s2    vz*;U;g;;G
 	
 
r"   c                 F    t        t        d      t        xs t        k(  sJ y )Nsensors_temperatures)r   r   r   r   r   s    r    test_sensors_temperaturesz-TestAvailSystemAPIs.test_sensors_temperaturesz   s    v565;KGLLLr"   c                 6    t        t        d      t        k(  sJ y )Nsensors_fans)r   r   r   r   s    r    test_sensors_fansz%TestAvailSystemAPIs.test_sensors_fans}   s    v~.%777r"   c                 f    t        t        d      t        xs t        xs t        xs t
        k(  sJ y )Nsensors_battery)r   r   r   r   r   r   r   s    r    test_batteryz TestAvailSystemAPIs.test_battery   s.    v010W005
 	
 
r"   N)	rY   rZ   r[   rd   rg   rj   rm   rp   rs   r^   r"   r    r`   r`   n   s!    >=

M8
r"   r`   c                       e Zd Zd Zd Zd Zd Zd Zej                  j                  exr ed      d        Zd	 Zd
 Zd Zd Zd Zd Zy)TestAvailProcessAPIsc                     t        t        j                  d      t        xs6 t        xs. t
        xs& t        xs t        xs t        xs t        xs t        k(  sJ y )Nenviron)r   r   Processr   r   r   r   r
   r   r   r   r   s    r    test_environz!TestAvailProcessAPIs.test_environ   sd    v~~y1   	
   	
 		
 	
r"   c                 J    t        t        j                  d      t        k(  sJ y Nuidsr   r   rx   r	   r   s    r    	test_uidszTestAvailProcessAPIs.test_uids       v~~v.%777r"   c                 J    t        t        j                  d      t        k(  sJ y r{   r}   r   s    r    	test_gidszTestAvailProcessAPIs.test_gids   r   r"   c                 J    t        t        j                  d      t        k(  sJ y )Nterminalr}   r   s    r    test_terminalz"TestAvailProcessAPIs.test_terminal   s    v~~z2e;;;r"   c                 Z    t        t        j                  d      t        xs t        k(  sJ y )Nionice)r   r   rx   r   r   r   s    r    test_ionicez TestAvailProcessAPIs.test_ionice   s     v~~x0U5EgFFFr"   r;   r<   c                 Z    t        t        j                  d      t        xs t        k(  sJ y )Nrlimit)r   r   rx   r   r   r   s    r    rX   z TestAvailProcessAPIs.test_rlimit   s"    
 v~~x0U5EgFFFr"   c                 `    t        t        j                  d      }|t        xs t         k(  sJ y )Nio_counters)r   r   rx   r   r
   r   hasits     r    test_io_countersz%TestAvailProcessAPIs.test_io_counters   s'    6enu-...r"   c                 J    t        t        j                  d      t        k(  sJ y )Nnum_fdsr}   r   s    r    test_num_fdsz!TestAvailProcessAPIs.test_num_fds   s    v~~y1U:::r"   c                 J    t        t        j                  d      t        k(  sJ y )Nnum_handles)r   r   rx   r   r   s    r    test_num_handlesz%TestAvailProcessAPIs.test_num_handles   s    v~~}5@@@r"   c                 j    t        t        j                  d      t        xs t        xs t
        k(  sJ y )Ncpu_affinity)r   r   rx   r   r   r   r   s    r    test_cpu_affinityz&TestAvailProcessAPIs.test_cpu_affinity   s,    v~~~6'W'
 	
 
r"   c                 j    t        t        j                  d      t        xs t        xs t
        k(  sJ y )Ncpu_num)r   r   rx   r   r   r
   r   s    r    test_cpu_numz!TestAvailProcessAPIs.test_cpu_num   s,    v~~y1%W%
 	
 
r"   c                     t        t        j                  d      }|t        xs t        xs t
        xs t         k(  sJ y )Nmemory_maps)r   r   rx   r   r   r   r   r   s     r    test_memory_mapsz%TestAvailProcessAPIs.test_memory_maps   s2    6g??3?%@AAAr"   N)rY   rZ   r[   ry   r~   r   r   r   r   r\   r]   r   r   rX   r   r   r   r   r   r   r^   r"   r    ru   ru      sq    

88<G [[ 56  G	G/;A



Br"   ru   c                   :   e Zd ZdZed        ZedfdZd Zd Z	d Z
d Zej                  j                  exr  ej"                         d	k(  d
      ej                  j                  e d      d               Zd Zd Zej                  j                  ed      d        Zd Zd Zej                  j                  e d      d        Zej                  j                  e d      d        Zej                  j                  e d      d        Zd Z d Z!y)TestSystemAPITypeszhCheck the return types of system related APIs.
    https://github.com/giampaolo/psutil/issues/1039.
    c                 6    t        j                         | _        y N)r   rx   proc)clss    r    
setUpClasszTestSystemAPITypes.setUpClass   s    >>#r"   Tc                 \    t        |      sJ |D ]  }t        ||      sJ |s|dk\  rJ  y )Nr   )r   
isinstance)r   nttype_gezerons        r    assert_ntuple_of_numsz(TestSystemAPITypes.assert_ntuple_of_nums   s=    R    	Aa'''Avv	r"   c                     | j                  t        j                                t        j                  d      D ]  }| j                  |        y )NT)percpu)r   r   	cpu_times)r   r   s     r    test_cpu_timesz!TestSystemAPITypes.test_cpu_times   sA    ""6#3#3#56""$/ 	+B&&r*	+r"   c                     t        t        j                  d       t              sJ t        t        j                  d      t              sJ y )Nintervalgh㈵>)r   r   cpu_percentfloatr   s    r    test_cpu_percentz#TestSystemAPITypes.test_cpu_percent   s8    &,,d;UCCC&,,g>FFFr"   c                     | j                  t        j                  d              | j                  t        j                  d             y )Nr   g-C6?)r   r   cpu_times_percentr   s    r    test_cpu_times_percentz)TestSystemAPITypes.test_cpu_times_percent   s4    ""6#;#;T#JK""6#;#;V#LMr"   c                 L    t        t        j                         t              sJ y r   )r   r   	cpu_countintr   s    r    test_cpu_countz!TestSystemAPITypes.test_cpu_count   s    &**,c222r"   arm64zskipped due to #1892r<   znot supportedc                     t        j                         t        j                  d      | j	                  t        j                         t
        t        f       y )Nzcpu_freq() returns Noner   )r   ri   r   skipr   r   r   r   s    r    rj   z TestSystemAPITypes.test_cpu_freq   s?    
 ??$++788""6??#4UCL"Ir"   c                     t        j                  d      j                         D ].  \  }}t        |t              sJ | j                  |t               0 y )NT)perdiskr   )r   disk_io_countersitemsr   strr   r   )r   kvs      r    test_disk_io_countersz(TestSystemAPITypes.test_disk_io_counters   sL    ++D9??A 	5DAqa%%%&&q&4	5r"   c                    t        j                         D ]r  }t        |j                  t              sJ t        |j
                  t              sJ t        |j                  t              sJ t        |j                  t              rrJ  y r   )r   disk_partitionsr   devicer   
mountpointfstypeopts)r   disks     r    test_disk_partitionsz'TestSystemAPITypes.test_disk_partitions   sj    **, 	.Ddkk3///doos333dkk3///dii---		.r"   zrequires rootc                     t               5  t        j                  d      }t        |      t        t	        |            k(  sJ |D ]  }t        |      rJ  	 d d d        y # 1 sw Y   y xY w)Nall)r   r   net_connectionslensetr   )r   retconns      r    test_net_connectionsz'TestSystemAPITypes.test_net_connections   sd     	+((/Cs8s3s8},,, +$T***+	+ 	+ 	+s   AA!A!!A*c           	         t        j                         j                         D ]  \  }}t        |t              sJ |D ]  }t        |j
                  t        j                        sJ t        |j                  t              sJ t        |j                  t        t        d       f      sJ t        |j                  t        t        d       f      rJ   y r   )r   net_if_addrsr   r   r   familyr   IntEnumaddressnetmasktype	broadcast)r   ifnameaddrsaddrs       r    test_net_if_addrsz$TestSystemAPITypes.test_net_if_addrs  s    #00288: 	EMFEfc*** E!$++t||<<<!$,,444!$,,d4j0ABBB!$..3T
2CDDD	E	Er"   c                 p   t        j                         j                         D ]  \  }}t        |t              sJ t        |j
                  t              sJ t        |j                  t        j                        sJ t        |j                  t              sJ t        |j                  t              rJ  y r   )r   net_if_statsr   r   r   isupboolduplexr   r   speedr   mtu)r   r   infos      r    test_net_if_statsz$TestSystemAPITypes.test_net_if_stats  s    "//1779 	-LFDfc***dii...dkk4<<888djj#...dhh,,,	-r"   c                 ^    t        j                  d      D ]  }t        |t              rJ  y )NT)pernic)r   net_io_countersr   r   )r   r   s     r    test_net_io_countersz'TestSystemAPITypes.test_net_io_counters  s.     ,,D9 	+Ffc***	+r"   c           
         t        j                         j                         D ]f  \  }}t        |t              sJ |D ]J  }t        |j
                  t              sJ t        |j                  t        t        t        d       f      rJJ  h y r   )
r   ro   r   r   r   labelcurrentr   r   r   r   nameunitsunits       r    rp   z$TestSystemAPITypes.test_sensors_fans  s     "..0668 	JKD%dC((( J!$**c222!$,,T$Z0HIIIJ	Jr"   c           
         t        j                         j                         D ]  \  }}t        |t              sJ |D ]  }t        |j
                  t              sJ t        |j                  t        t        t        d       f      sJ t        |j                  t        t        t        d       f      sJ t        |j                  t        t        t        d       f      rJ   y r   )r   rl   r   r   r   r   r   r   r   r   highcriticalr   s       r    rm   z,TestSystemAPITypes.test_sensors_temperatures&  s     "668>>@ 	KKD%dC((( K!$**c222!$,,T$Z0HIII!$))eS$t*-EFFF!$--%d4j1IJJJ	K	Kr"   c                 L    t        t        j                         t              sJ y r   )r   r   	boot_timer   r   s    r    test_boot_timez!TestSystemAPITypes.test_boot_time1  s    &**,e444r"   c                 X   t        j                         D ]  }t        |j                  t              sJ t        |j
                  t        t        d       f      sJ t        |j                  t        t        d       f      sJ t        |j                  t        t        d       f      rJ  y r   )
r   usersr   r   r   r   r   hostpidr   )r   users     r    
test_userszTestSystemAPITypes.test_users5  s    LLN 	;Ddii---dmmc4:->???dii#tDz):;;;dhhd4j(9:::		;r"   N)"rY   rZ   r[   __doc__classmethodr   r   r   r   r   r   r   r   r\   r]   r   platformmachiner   rj   r   r   r   r   r   r   r   r   r   rp   r   rm   r   r  r^   r"   r    r   r      sw    $ $ /4D +
GN3 [[/"(""$/8N   [[L(AJ BJ
5. [[_=+ >+E- [[//H+ I+
 [[,,_EJ FJ [[44_MK NK5;r"   r   c                   T    e Zd Zej                  j                  e d      d        Zy)TestProcessWaitTypez	not POSIXr<   c                    t        j                  | j                         j                        }|j	                          |j                         }|t        j                   k(  sJ t        |t        j                        sJ y r   )r   rx   spawn_testprocr  	terminatewaitsignalSIGTERMr   r   r   )r   pcodes      r    test_negative_signalz(TestProcessWaitType.test_negative_signal?  s[    NN4..0445	vvx&&&$---r"   N)rY   rZ   r[   r   r\   r]   r	   r  r^   r"   r    r
  r
  >  s*    [[E	+6. 7.r"   r
  )r  r  r  r   r   r   r   r   r   r   r	   r
   r   psutil.testsr   r   r   r   r   r   r   r   r   r   r   r   r   r`   ru   r   r
  r^   r"   r    <module>r     s   
             ' % , ) 1 % ' '  & ' <4^ <4~
. 
06B> 6B|w; w;t.. .r"   