U |f2@sdZddlZddlZddlZddlZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZGdddeZGdddeZGdddeZ Gd d!d!eZ!Gd"d#d#eZ"e#d$krdd%l$m%Z%e%e&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_versionc@sDeZdZddZddZddZddZee o2e d d d Z d S) TestAvailConstantsAPIscCs|ttdtptptdS)NZ PROCFS_PATH) assertEqualhasattrpsutilrr rselfrN/opt/alt/python38/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_CLASSrrrr rZaerrr test_win_priority6sz(TestAvailConstantsAPIs.test_win_prioritycCsJ|j}|ttdt|ttdt|ttdt|ttdtdS)NZIOPRIO_CLASS_NONEZIOPRIO_CLASS_RTZIOPRIO_CLASS_BEZIOPRIO_CLASS_IDLErrrrr#rrr 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#rrr test_linux_ioprio_windowsFs z0TestAvailConstantsAPIs.test_linux_ioprio_windows%unsupported on GITHUB_ACTIONS + LINUXcCs|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)rrrrrrrr#rrr test_rlimitMs6     z"TestAvailConstantsAPIs.test_rlimitN) __name__ __module__ __qualname__r!r$r&r'unittestskipIfr rr.rrrr r2s rc@s<eZdZddZddZddZddZd d Zd d Zd S)TestAvailSystemAPIscCs|ttdtdS)NZwin_service_iterr"rrrr test_win_service_iterqsz)TestAvailSystemAPIs.test_win_service_itercCs|ttdtdS)NZwin_service_getr"rrrr test_win_service_gettsz(TestAvailSystemAPIs.test_win_service_getcCs&|ttdtptptptptdS)Ncpu_freq)rrrrrr rrrrrr test_cpu_freqwsz!TestAvailSystemAPIs.test_cpu_freqcCs|ttdtptdS)Nsensors_temperatures)rrrrrrrrr test_sensors_temperatures}sz-TestAvailSystemAPIs.test_sensors_temperaturescCs|ttdtdS)N sensors_fansr%rrrr test_sensors_fanssz%TestAvailSystemAPIs.test_sensors_fanscCs"|ttdtptptptdS)NZsensors_battery)rrrrr rrrrrr test_batterysz TestAvailSystemAPIs.test_batteryN) r/r0r1r5r6r8r:r<r=rrrr r4ps r4c@s|eZdZddZddZddZddZd d Ze e o:e d d d Z ddZ ddZddZddZddZddZdS)TestAvailProcessAPIscCs4|ttjdtp,tp,tp,tp,tp,t p,t p,t dS)Nenviron) rrrProcessrrr rr rrrrrrr test_environs" z!TestAvailProcessAPIs.test_environcCs|ttjdtdSNZuidsrrrr@rrrrr test_uidsszTestAvailProcessAPIs.test_uidscCs|ttjdtdSrBrCrrrr test_gidsszTestAvailProcessAPIs.test_gidscCs|ttjdtdS)NterminalrCrrrr test_terminalsz"TestAvailProcessAPIs.test_terminalcCs|ttjdtptdS)NZionice)rrrr@rr rrrr test_ionicesz TestAvailProcessAPIs.test_ionicer(cCs|ttjdtptdS)NZrlimit)rrrr@rrrrrr r.sz TestAvailProcessAPIs.test_rlimitcCs"ttjd}||tpt dS)NZ io_counters)rrr@rrr rZhasitrrr test_io_counterss z%TestAvailProcessAPIs.test_io_counterscCs|ttjdtdS)NZnum_fdsrCrrrr test_num_fdssz!TestAvailProcessAPIs.test_num_fdscCs|ttjdtdS)NZ num_handles)rrrr@r rrrr test_num_handlessz%TestAvailProcessAPIs.test_num_handlescCs |ttjdtptptdS)NZ cpu_affinity)rrrr@rr rrrrr test_cpu_affinitys  z&TestAvailProcessAPIs.test_cpu_affinitycCs |ttjdtptptdS)NZcpu_num)rrrr@rrr rrrr test_cpu_nums z!TestAvailProcessAPIs.test_cpu_numcCs*ttjd}||tp tp tp t dS)NZ memory_maps)rrr@rrrrrrIrrr test_memory_mapss z%TestAvailProcessAPIs.test_memory_mapsN)r/r0r1rArDrErGrHr2r3r rr.rJrKrLrMrNrOrrrr r>s   r>c@s eZdZdZeddZedfddZddZd d Z d d Z d dZ e eoXedkde e dddZddZddZe edddZddZe edddZe e dd d!Ze e dd"d#Ze e dd$d%Zd&d'Z d(d)Z!d*S)+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. cCst|_dSN)rr@proc)clsrrr setUpClassszTestSystemAPITypes.setUpClassTcCs6t|s t|D] }||||r||dqdS)Nr)rAssertionErrorassertIsInstanceZassertGreaterEqual)rnttype_Zgezeronrrr assert_ntuple_of_numss   z(TestSystemAPITypes.assert_ntuple_of_numscCs.|ttjddD]}||qdS)NT)Zpercpu)rZrZ cpu_times)rrWrrr test_cpu_timessz!TestSystemAPITypes.test_cpu_timescCs,|tjddt|tjddtdS)Nintervalgh㈵>)rVrZ cpu_percentfloatrrrr test_cpu_percentsz#TestSystemAPITypes.test_cpu_percentcCs(|tjdd|tjdddS)Nr\g-C6?)rZrZcpu_times_percentrrrr test_cpu_times_percentsz)TestSystemAPITypes.test_cpu_times_percentcCs|ttdSrQ)rVr cpu_countintrrrr test_cpu_countsz!TestSystemAPITypes.test_cpu_countarm64zskipped due to #1892z not supportedcCs2tdkrtd|jttttfddS)Nzcpu_freq() returns NonerX)rr7r2ZSkipTestrZr^rbr rrrr r8s  z TestSystemAPITypes.test_cpu_freqcCs<tjddD]&\}}||t|j|ttfdqdS)NT)Zperdiskre)rZdisk_io_countersitemsrVstrrZrbr )rkvrrr test_disk_io_counterss z(TestSystemAPITypes.test_disk_io_counterscCsJtD]<}||jt||jt||jt||jtqdSrQ)rZdisk_partitionsrVZdevicergZ mountpointZfstypeopts)rZdiskrrr test_disk_partitionss  z'TestSystemAPITypes.test_disk_partitionsz requires rootc CsNt>td}|t|tt||D]}t|s.tq.W5QRXdS)Nall)rrZnet_connectionsrlensetrrU)rretconnrrr test_net_connectionss  z'TestSystemAPITypes.test_net_connectionscCstD]\}}||t|D]j}tdk rFtsF||jtjn||jt ||j t||j tt df||j tt dfq$q dSrQ)rZ net_if_addrsrfrVrgrrfamilyIntEnumrbaddressnetmasktype broadcast)rifnameaddrsaddrrrr test_net_if_addrs s  z$TestSystemAPITypes.test_net_if_addrszQEMU user not supportedcCsxtD]f\}}||t||jttdk rH||jtj n||jt ||j t ||j t q dSrQ) rZ net_if_statsrfrVrgZisupboolrZduplexrtrbspeedZmtu)rryinforrr test_net_if_statss z$TestSystemAPITypes.test_net_if_statscCs"tjddD]}||tq dS)NT)Zpernic)rZnet_io_countersrVrg)rryrrr test_net_io_counters&sz'TestSystemAPITypes.test_net_io_countersc CsVtD]D\}}||t|D]*}||jt||jttt dfq$q dSrQ) rr;rfrVrglabelcurrentr^rbrwrnameZunitsunitrrr r<,s  z$TestSystemAPITypes.test_sensors_fansc CstD]t\}}||t|D]Z}||jt||jttt df||j ttt df||j ttt dfq$q dSrQ) rr9rfrVrgrrr^rbrwhighcriticalrrrr r:5s z,TestSystemAPITypes.test_sensors_temperaturescCs|ttdSrQ)rVrZ boot_timer^rrrr test_boot_time@sz!TestSystemAPITypes.test_boot_timecCsbtD]T}||jt||jttdf||jttdf||jt tdfqdSrQ) rZusersrVrrgrFrwhostpidrb)ruserrrr test_usersDs  zTestSystemAPITypes.test_usersN)"r/r0r1__doc__ classmethodrTr^rZr[r_r`rcr2r3rplatformmachiner r8rjrlrrrr|rrrrrr<rr:rrrrrr rPs:            rPc@s"eZdZee dddZdS)TestProcessWaitTypez not POSIXcCsXt|j}||}||tj t dk rH| |t j n | |t dSrQ) rr@Zspawn_testprocr terminatewaitrsignalSIGTERMrrVrtrb)rpcoderrr test_negative_signalNsz(TestProcessWaitType.test_negative_signalN)r/r0r1r2r3rrrrrr rMs r__main__) run_from_name)'rrrr2rrrrrrrrr r Zpsutil._compatr Z psutil.testsr r rrrrrrrrrrrrr4r>rPrr/Zpsutil.tests.runnerr__file__rrrr sH                       >?