
    ztf2                        d Z ddl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 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"e#d$k(  rdd%l$m%Z%  e%e&       y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)long)GITHUB_ACTIONS)HAS_CPU_FREQ)HAS_NET_IO_COUNTERS)HAS_SENSORS_FANS)HAS_SENSORS_TEMPERATURES)PYPY)	QEMU_USER)SKIP_SYSCONS)PsutilTestCase)create_sockets)enum)is_namedtuple)kernel_versionc                   ^    e Zd Zd Zd Zd Zd Z ej                  e	xr e
d      d        Zy)TestAvailConstantsAPIsc                 l    | j                  t        t        d      t        xs t        xs t
               y )NPROCFS_PATH)assertEqualhasattrpsutilr   r
   r   selfs    e/var/www/html/software/conda/envs/higlass/lib/python3.12/site-packages/psutil/tests/test_contracts.pytest_PROCFS_PATHz'TestAvailConstantsAPIs.test_PROCFS_PATH3   s#    79N%9N3O    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r   r   r    r   r"   aes     r#   test_win_priorityz(TestAvailConstantsAPIs.test_win_priority6   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_windowsF   sR    
76=)73
76?+W5
76<('2
76+,g6r%   %unsupported on GITHUB_ACTIONS + LINUXc                    | 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)rL   rM      RLIMIT_NICERLIMIT_RTPRIO)rL   rM      RLIMIT_RTTIMERLIMIT_SIGPENDINGRLIMIT_SWAPRLIMIT_SBSIZERLIMIT_NPTS)r   r   r    r   r   r	   r   r.   s     r#   test_rlimitz"TestAvailConstantsAPIs.test_rlimitM   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$   r0   r7   r=   unittestskipIfr   r   rY    r%   r#   r   r   2   sB    P@87 X__ 5"I44r%   r   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)TestAvailSystemAPIsc                 L    | j                  t        t        d      t               y )Nwin_service_iterr-   r!   s    r#   test_win_service_iterz)TestAvailSystemAPIs.test_win_service_iterq   s    );<gFr%   c                 L    | j                  t        t        d      t               y )Nwin_service_getr-   r!   s    r#   test_win_service_getz(TestAvailSystemAPIs.test_win_service_gett   s    ):;WEr%   c                     | j                  t        t        d      t        xs t        xs t
        xs t        xs t               y )Ncpu_freq)r   r   r    r   r   r   r   r   r!   s    r#   test_cpu_freqz!TestAvailSystemAPIs.test_cpu_freqw   s1    FJ';U;g;;G	
r%   c                 \    | j                  t        t        d      t        xs t               y )Nsensors_temperatures)r   r   r    r   r   r!   s    r#   test_sensors_temperaturesz-TestAvailSystemAPIs.test_sensors_temperatures}   s"    F23U5Eg	
r%   c                 L    | j                  t        t        d      t               y )Nsensors_fansr6   r!   s    r#   test_sensors_fansz%TestAvailSystemAPIs.test_sensors_fans   s    8%@r%   c                 |    | j                  t        t        d      t        xs t        xs t
        xs t               y )Nsensors_battery)r   r   r    r   r   r   r   r!   s    r#   test_batteryz TestAvailSystemAPIs.test_battery   s-    F-.0W005	
r%   N)	rZ   r[   r\   rd   rg   rj   rm   rp   rs   r_   r%   r#   ra   ra   p   s#    GF


A
r%   ra   c                       e Zd Zd Zd Zd Zd Zd Z ej                  e
xr ed      d        Zd Zd	 Zd
 Zd Zd Zd Zy)TestAvailProcessAPIsc                     | j                  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               y )Nenviron)r   r   r    Processr   r   r   r   r
   r   r   r   r!   s    r#   test_environz!TestAvailProcessAPIs.test_environ   sc    FNNI.   	
   
	
r%   c                 `    | j                  t        t        j                  d      t               y Nuidsr   r   r    rx   r	   r!   s    r#   	test_uidszTestAvailProcessAPIs.test_uids       8%@r%   c                 `    | j                  t        t        j                  d      t               y r{   r}   r!   s    r#   	test_gidszTestAvailProcessAPIs.test_gids   r   r%   c                 `    | j                  t        t        j                  d      t               y )Nterminalr}   r!   s    r#   test_terminalz"TestAvailProcessAPIs.test_terminal   s    <eDr%   c                 p    | j                  t        t        j                  d      t        xs t
               y )Nionice)r   r   r    rx   r   r   r!   s    r#   test_ionicez TestAvailProcessAPIs.test_ionice   s"    :E<LWMr%   r>   c                 p    | j                  t        t        j                  d      t        xs t
               y )Nrlimit)r   r   r    rx   r   r   r!   s    r#   rY   z TestAvailProcessAPIs.test_rlimit   s$     	:E<LWMr%   c                 v    t        t        j                  d      }| j                  |t        xs t
                y )Nio_counters)r   r    rx   r   r   r
   r"   hasits     r#   test_io_countersz%TestAvailProcessAPIs.test_io_counters   s)    6U^e 45r%   c                 `    | j                  t        t        j                  d      t               y )Nnum_fdsr}   r!   s    r#   test_num_fdsz!TestAvailProcessAPIs.test_num_fds   s    ;UCr%   c                 `    | j                  t        t        j                  d      t               y )Nnum_handles)r   r   r    rx   r   r!   s    r#   test_num_handlesz%TestAvailProcessAPIs.test_num_handles   s    ?Ir%   c                     | j                  t        t        j                  d      t        xs t
        xs t               y )Ncpu_affinity)r   r   r    rx   r   r   r   r!   s    r#   test_cpu_affinityz&TestAvailProcessAPIs.test_cpu_affinity   s+    FNNN3'W'	
r%   c                     | j                  t        t        j                  d      t        xs t
        xs t               y )Ncpu_num)r   r   r    rx   r   r   r
   r!   s    r#   test_cpu_numz!TestAvailProcessAPIs.test_cpu_num   s*    FNNI.0I0IE	
r%   c                     t        t        j                  d      }| j                  |t        xs t
        xs t        xs t                y )Nmemory_maps)r   r    rx   r   r   r   r   r   r   s     r#   test_memory_mapsz%TestAvailProcessAPIs.test_memory_maps   s4    6W%F%F#%F GHr%   N)rZ   r[   r\   ry   r~   r   r   r   r]   r^   r   r   rY   r   r   r   r   r   r   r_   r%   r#   ru   ru      sl    
AAEN X__ 5"INN6DJ


I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                  exr  ej                          d	k(  d
       ej                  e d      d               Zd Zd Z ej                  ed      d        Zd Z ej                  ed      d        Z ej                  e d      d        Z ej                  e d      d        Z ej                  e d      d        Zd Z d Z!y)TestSystemAPITypeszCheck the return types of system related APIs.
    Mainly we want to test we never return unicode on Python 2, see:
    https://github.com/giampaolo/psutil/issues/1039.
    c                 6    t        j                         | _        y N)r    rx   proc)clss    r#   
setUpClasszTestSystemAPITypes.setUpClass   s    >>#r%   Tc                 z    t        |      sJ |D ])  }| j                  ||       |s| j                  |d       + y )Nr   )r   assertIsInstanceassertGreaterEqual)r"   nttype_gezerons        r#   assert_ntuple_of_numsz(TestSystemAPITypes.assert_ntuple_of_nums   sB    R    	.A!!!U+''1-	.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                     | j                  t        j                  d       t               | j                  t        j                  d      t               y )Nintervalgh㈵>)r   r    cpu_percentfloatr!   s    r#   test_cpu_percentz#TestSystemAPITypes.test_cpu_percent   s8    f00$?Gf00'BEJr%   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                 T    | j                  t        j                         t               y r   )r   r    	cpu_countintr!   s    r#   test_cpu_countz!TestSystemAPITypes.test_cpu_count   s    f..0#6r%   arm64zskipped due to #1892znot supportedc                     t        j                         t        j                  d      | j	                  t        j                         t
        t        t        f       y )Nzcpu_freq() returns Noner   )r    ri   r]   SkipTestr   r   r   r   r!   s    r#   rj   z TestSystemAPITypes.test_cpu_freq   sD    
 ??$##$=>>""6??#4UC<N"Or%   c                     t        j                  d      j                         D ]8  \  }}| j                  |t               | j                  |t        t        f       : y )NT)perdiskr   )r    disk_io_countersitemsr   strr   r   r   )r"   kvs      r#   test_disk_io_countersz(TestSystemAPITypes.test_disk_io_counters   sP    ++D9??A 	=DAq!!!S)&&qd&<	=r%   c                 6   t        j                         D ]  }| j                  |j                  t               | j                  |j
                  t               | j                  |j                  t               | j                  |j                  t                y r   )r    disk_partitionsr   devicer   
mountpointfstypeopts)r"   disks     r#   test_disk_partitionsz'TestSystemAPITypes.test_disk_partitions   sj    **, 	2D!!$++s3!!$//37!!$++s3!!$))S1		2r%   zrequires rootc           	          t               5  t        j                  d      }| j                  t	        |      t	        t        |                   |D ]  }t        |      rJ  	 d d d        y # 1 sw Y   y xY w)Nall)r   r    net_connectionsr   lensetr   )r"   retconns      r#   test_net_connectionsz'TestSystemAPITypes.test_net_connections  sf     	+((/CSXs3s8}5 +$T***+	+ 	+ 	+s   AA,A,,A5c           	      ,   t        j                         j                         D ]  \  }}| j                  |t               |D ]  }t
        1t        s+| j                  |j                  t
        j                         n | j                  |j                  t               | j                  |j                  t               | j                  |j                  t        t        d       f       | j                  |j                  t        t        d       f         y r   )r    net_if_addrsr   r   r   r   r   familyIntEnumr   addressnetmasktype	broadcast)r"   ifnameaddrsaddrs       r#   test_net_if_addrsz$TestSystemAPITypes.test_net_if_addrs  s    #00288: 		IMFE!!&#. I#D))$++t||D))$++s;%%dllC8%%dllS$t*4EF%%dnnsDJ6GHI		Ir%   zQEMU user not supportedc                    t        j                         j                         D ]  \  }}| j                  |t               | j                  |j
                  t               t        +| j                  |j                  t        j                         n | j                  |j                  t               | j                  |j                  t               | j                  |j                  t                y r   )r    net_if_statsr   r   r   isupboolr   duplexr   r   speedmtu)r"   r   infos      r#   test_net_if_statsz$TestSystemAPITypes.test_net_if_stats  s     #//1779 	1LFD!!&#.!!$))T2%%dkk4<<@%%dkk37!!$**c2!!$((C0	1r%   c                 f    t        j                  d      D ]  }| j                  |t                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!!&#.	/r%   c           
      2   t        j                         j                         D ]r  \  }}| j                  |t               |D ]R  }| j                  |j
                  t               | j                  |j                  t        t        t        d       f       T t 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 	NKD%!!$, N%%djj#6%%dllUCd4LMN	Nr%   c           
         t        j                         j                         D ]  \  }}| j                  |t               |D ]  }| j                  |j
                  t               | j                  |j                  t        t        t        d       f       | j                  |j                  t        t        t        d       f       | j                  |j                  t        t        t        d       f         y r   )r    rl   r   r   r   r   r   r   r   r   highcriticalr   s       r#   rm   z,TestSystemAPITypes.test_sensors_temperatures5  s     "668>>@ 	OKD%!!$, O%%djj#6%%dllUCd4LM%%dii%d4j1IJ%%dmmeS$t*5MN	O	Or%   c                 T    | j                  t        j                         t               y r   )r   r    	boot_timer   r!   s    r#   test_boot_timez!TestSystemAPITypes.test_boot_time@  s    f..0%8r%   c                 x   t        j                         D ]  }| j                  |j                  t               | j                  |j
                  t        t        d       f       | j                  |j                  t        t        d       f       | j                  |j                  t        t        d       f        y r   )
r    usersr   r   r   r   r   hostpidr   )r"   users     r#   
test_userszTestSystemAPITypes.test_usersD  s    LLN 	?D!!$))S1!!$--#tDz1BC!!$))c4:->?!!$((S$t*,=>		?r%   N)"rZ   r[   r\   __doc__classmethodr   r   r   r   r   r   r   r]   r^   r   platformmachiner   rj   r   r   r   r   r   r   r   r   r   r   rp   r   rm   r   r  r_   r%   r#   r   r      se   
 $ $ /4D .+
KN7 X__/"(""$/1G X__%7P 8P
=2 X__\?3+ 4+I X__Y 9:
1 ;
1 X__,,o>/ ?/
 X__))?;N <N X__11?CO DO9?r%   r   c                   @    e Zd Z ej                  e d      d        Zy)TestProcessWaitTypez	not POSIXc                 Z   t        j                  | j                         j                        }|j	                          |j                         }| j                  |t        j                          t        !| j                  |t        j                         y | j                  |t               y r   )r    rx   spawn_testprocr  	terminatewaitr   signalSIGTERMr   r   r   r   )r"   pcodes      r#   test_negative_signalz(TestProcessWaitType.test_negative_signalN  ss    NN4..0445	vvx/!!$5!!$,r%   N)rZ   r[   r\   r]   r^   r	   r  r_   r%   r#   r  r  M  s#    X__Y,- --r%   r  __main__)run_from_name)'r  r  r  r]   r    r   r   r   r   r   r   r	   r
   r   psutil._compatr   psutil.testsr   r   r   r   r   r   r   r   r   r   r   r   r   r   ra   ru   r   r  rZ   psutil.tests.runnerr  __file__r_   r%   r#   <module>r     s   
               ' % , ) 1  " % ' '  & ';4^ ;4|
. 
87I> 7I~? ?D
-. 
- z1( r%   