U 1g!1@sdZddlZddlZddlZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lm Z dd lm Z dd l mZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZGdddeZGdddeZGdd d eZ Gd!d"d"eZ!Gd#d$d$eZ"dS)%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_version)pytestc@sHeZdZddZddZddZddZejj e o4e d d d d Z d S)TestAvailConstantsAPIscCsttdtptptkstdS)NZ PROCFS_PATH)hasattrpsutilrr rAssertionErrorselfr K/opt/hc_python/lib64/python3.8/site-packages/psutil/tests/test_contracts.pytest_PROCFS_PATH3sz'TestAvailConstantsAPIs.test_PROCFS_PATHcCsj|j}|ttdt|ttdt|ttdt|ttdt|ttdt|ttdtdS)NZABOVE_NORMAL_PRIORITY_CLASSZBELOW_NORMAL_PRIORITY_CLASSZHIGH_PRIORITY_CLASSZIDLE_PRIORITY_CLASSZNORMAL_PRIORITY_CLASSZREALTIME_PRIORITY_CLASS assertEqualrrr rZaer r r!test_win_priority6sz(TestAvailConstantsAPIs.test_win_prioritycCsJ|j}|ttdt|ttdt|ttdt|ttdtdS)NZIOPRIO_CLASS_NONEZIOPRIO_CLASS_RTZIOPRIO_CLASS_BEZIOPRIO_CLASS_IDLE)r$rrrr%r r r!test_linux_ioprio_linux?s z.TestAvailConstantsAPIs.test_linux_ioprio_linuxcCsJ|j}|ttdt|ttdt|ttdt|ttdtdS)NZ IOPRIO_HIGHZ IOPRIO_NORMALZ IOPRIO_LOWZIOPRIO_VERYLOWr#r%r r r!test_linux_ioprio_windowsFs z0TestAvailConstantsAPIs.test_linux_ioprio_windows%unsupported on GITHUB_ACTIONS + LINUXreasoncCs|j}|ttdtpt|ttdtp*t|ttdtp>t|ttdtpRt|ttdtpft|ttdtpzt|ttdtpt|ttdtpt|ttd tpt|ttd tpt|ttd tpt|ttd ttrtd kr|ttdttdkr0|ttdttdkrL|ttdttdkrh|ttdttd kr|ttdt|ttdt|ttdt|ttdtdS)NZ RLIM_INFINITYZ RLIMIT_ASZ RLIMIT_COREZ RLIMIT_CPUZ RLIMIT_DATAZ RLIMIT_FSIZEZRLIMIT_MEMLOCKZ RLIMIT_NOFILEZ RLIMIT_NPROCZ RLIMIT_RSSZ RLIMIT_STACKZ RLIMIT_LOCKS)ZRLIMIT_MSGQUEUE)r,r- Z RLIMIT_NICEZ RLIMIT_RTPRIO)r,r-Z RLIMIT_RTTIMEZRLIMIT_SIGPENDINGZ RLIMIT_SWAPZ RLIMIT_SBSIZEZ RLIMIT_NPTS)r$rrrrrrr%r r r! test_rlimitMs6     z"TestAvailConstantsAPIs.test_rlimitN) __name__ __module__ __qualname__r"r&r'r(rmarkskipifr rr1r r r r!r2s rc@s<eZdZddZddZddZddZd d Zd d Zd S)TestAvailSystemAPIscCsttdtkstdS)NZwin_service_iterrrr rrr r r!test_win_service_iterrsz)TestAvailSystemAPIs.test_win_service_itercCsttdtkstdS)NZwin_service_getr8rr r r!test_win_service_getusz(TestAvailSystemAPIs.test_win_service_getcCs&ttdtptptptptks"tdS)Ncpu_freq)rrrrr rrrrr r r! test_cpu_freqxsz!TestAvailSystemAPIs.test_cpu_freqcCsttdtptkstdS)Nsensors_temperatures)rrrrrrr r r!test_sensors_temperatures}sz-TestAvailSystemAPIs.test_sensors_temperaturescCsttdtkstdS)N sensors_fans)rrrrrr r r!test_sensors_fanssz%TestAvailSystemAPIs.test_sensors_fanscCs"ttdtptptptkstdS)NZsensors_battery)rrrr rrrrr r r! test_batterysz TestAvailSystemAPIs.test_batteryN) r2r3r4r9r:r<r>r@rAr r r r!r7qs r7c@seZdZddZddZddZddZd d Zej j e o)rYrZ cpu_percentfloatrrr r r!test_cpu_percentsz#TestSystemAPITypes.test_cpu_percentcCs(|tjdd|tjdddS)Nr_g-C6?)r]rZcpu_times_percentrr r r!test_cpu_times_percentsz)TestSystemAPITypes.test_cpu_times_percentcCstttstdSrU)rYr cpu_countintrrr r r!test_cpu_countsz!TestSystemAPITypes.test_cpu_countarm64zskipped due to #1892r*z not supportedcCs2tdkrtd|jttttfddS)Nzcpu_freq() returns Noner[)rr;rskipr]rarer rr r r!r<s  z TestSystemAPITypes.test_cpu_freqcCs>tjddD](\}}t|ts&t|j|ttfdqdS)NT)Zperdiskrh) rZdisk_io_countersitemsrYstrrr]rer )rkvr r r!test_disk_io_counterssz(TestSystemAPITypes.test_disk_io_counterscCsRtD]D}t|jtstt|jts,tt|jtstd}t|tt|ks*t|D]}t|s.tq.W5QRXdS)Nall)rrZnet_connectionslensetrr)rretconnr r r!test_net_connectionss  z'TestSystemAPITypes.test_net_connectionscCstD]\}}t|ts"t|D]t}tdk rJtsJt|jtj sZtnt|jt sZtt|j tsjtt|j tt dfstt|jtt dfs&tq&q dSrU)rZ net_if_addrsrjrYrkrrrfamilyIntEnumreaddressnetmasktype broadcast)rifnameaddrsaddrr r r!test_net_if_addrss z$TestSystemAPITypes.test_net_if_addrszQEMU user not supportedcCstD]r\}}t|ts"tt|jts2ttdk rNt|j tj s^tnt|j t s^tt|j t sntt|j t s tq dSrU)rZ net_if_statsrjrYrkrZisupboolrZduplexrxrespeedZmtu)rr}infor r r!test_net_if_statssz$TestSystemAPITypes.test_net_if_statscCs$tjddD]}t|ts tq dS)NT)Zpernic)rZnet_io_countersrYrkr)rr}r r r!test_net_io_counters"sz'TestSystemAPITypes.test_net_io_counterscCs\tD]J\}}t|ts"t|D].}t|jts:tt|jtt t dfs&tq&q dSrU) rr?rjrYrkrlabelcurrentrarer{rnameZunitsunitr r r!r@(s z$TestSystemAPITypes.test_sensors_fanscCstD]~\}}t|ts"t|D]b}t|jts:tt|jtt t dfsTtt|j tt t dfsntt|j tt t dfs&tq&q dSrU) rr=rjrYrkrrrrarer{highcriticalrr r r!r>1sz,TestSystemAPITypes.test_sensors_temperaturescCstttstdSrU)rYrZ boot_timerarrr r r!test_boot_time<sz!TestSystemAPITypes.test_boot_timecCsjtD]\}t|jtstt|jttdfs4tt|jttdfsLtt|j t tdfstqdSrU) rZusersrYrrkrrJr{hostpidre)ruserr r r! test_users@s  zTestSystemAPITypes.test_usersN)#r2r3r4__doc__ classmethodrXrar]r^rbrcrfrr5r6rplatformmachiner r<rnrprrvrrrrrrr@rr>rrr r r r!rTs:        rTc@s&eZdZejje ddddZdS)TestProcessWaitTypez not POSIXr*cCs\t|j}||}|tj ks0tt dk rJt |t j sXtnt |t sXtdSrU) rrDZspawn_testprocr terminatewaitsignalSIGTERMrrrYrxre)rpcoder r r!test_negative_signalJsz(TestProcessWaitType.test_negative_signalN)r2r3r4rr5r6rrr r r r!rIsr)#rrrrrrrrrrrr r Zpsutil._compatr Z psutil.testsr r rrrrrrrrrrrrrr7rBrTrr r r r!sB                        ?>