py2docfx 0.1.20.dev2245077__py3-none-any.whl → 0.1.20.dev2245492__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. py2docfx/convert_prepare/get_source.py +1 -1
  2. py2docfx/convert_prepare/package_info.py +37 -27
  3. py2docfx/convert_prepare/tests/test_get_source.py +3 -1
  4. py2docfx/convert_prepare/tests/test_package_info.py +159 -1
  5. py2docfx/docfx_yaml/build_finished.py +1 -1
  6. py2docfx/venv/venv1/Lib/site-packages/psutil/__init__.py +39 -19
  7. py2docfx/venv/venv1/Lib/site-packages/psutil/_common.py +3 -5
  8. py2docfx/venv/venv1/Lib/site-packages/psutil/_psaix.py +1 -2
  9. py2docfx/venv/venv1/Lib/site-packages/psutil/_psbsd.py +53 -78
  10. py2docfx/venv/venv1/Lib/site-packages/psutil/_pslinux.py +55 -38
  11. py2docfx/venv/venv1/Lib/site-packages/psutil/_psosx.py +40 -12
  12. py2docfx/venv/venv1/Lib/site-packages/psutil/_psposix.py +0 -1
  13. py2docfx/venv/venv1/Lib/site-packages/psutil/_pssunos.py +1 -2
  14. py2docfx/venv/venv1/Lib/site-packages/psutil/_pswindows.py +33 -13
  15. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/__init__.py +185 -122
  16. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/__main__.py +2 -3
  17. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_bsd.py +5 -10
  18. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_connections.py +3 -4
  19. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_contracts.py +41 -45
  20. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_linux.py +35 -38
  21. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_memleaks.py +4 -8
  22. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_misc.py +6 -12
  23. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_osx.py +17 -8
  24. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_posix.py +29 -17
  25. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_process.py +74 -75
  26. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_process_all.py +11 -13
  27. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_scripts.py +2 -3
  28. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_sudo.py +117 -0
  29. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_system.py +21 -31
  30. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_testutils.py +23 -23
  31. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_unicode.py +15 -8
  32. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_windows.py +65 -33
  33. {py2docfx-0.1.20.dev2245077.dist-info → py2docfx-0.1.20.dev2245492.dist-info}/METADATA +1 -1
  34. {py2docfx-0.1.20.dev2245077.dist-info → py2docfx-0.1.20.dev2245492.dist-info}/RECORD +36 -35
  35. {py2docfx-0.1.20.dev2245077.dist-info → py2docfx-0.1.20.dev2245492.dist-info}/WHEEL +0 -0
  36. {py2docfx-0.1.20.dev2245077.dist-info → py2docfx-0.1.20.dev2245492.dist-info}/top_level.txt +0 -0
@@ -9,7 +9,6 @@ returned types and APIs availability.
9
9
  Some of these are duplicates of tests test_system.py and test_process.py.
10
10
  """
11
11
 
12
- import platform
13
12
  import signal
14
13
 
15
14
  import psutil
@@ -22,6 +21,7 @@ from psutil import OPENBSD
22
21
  from psutil import POSIX
23
22
  from psutil import SUNOS
24
23
  from psutil import WINDOWS
24
+ from psutil.tests import AARCH64
25
25
  from psutil.tests import GITHUB_ACTIONS
26
26
  from psutil.tests import HAS_CPU_FREQ
27
27
  from psutil.tests import HAS_NET_IO_COUNTERS
@@ -35,7 +35,6 @@ from psutil.tests import is_namedtuple
35
35
  from psutil.tests import kernel_version
36
36
  from psutil.tests import pytest
37
37
 
38
-
39
38
  # ===================================================================
40
39
  # --- APIs availability
41
40
  # ===================================================================
@@ -49,62 +48,58 @@ class TestAvailConstantsAPIs(PsutilTestCase):
49
48
  assert hasattr(psutil, "PROCFS_PATH") == (LINUX or SUNOS or AIX)
50
49
 
51
50
  def test_win_priority(self):
52
- ae = self.assertEqual
53
- ae(hasattr(psutil, "ABOVE_NORMAL_PRIORITY_CLASS"), WINDOWS)
54
- ae(hasattr(psutil, "BELOW_NORMAL_PRIORITY_CLASS"), WINDOWS)
55
- ae(hasattr(psutil, "HIGH_PRIORITY_CLASS"), WINDOWS)
56
- ae(hasattr(psutil, "IDLE_PRIORITY_CLASS"), WINDOWS)
57
- ae(hasattr(psutil, "NORMAL_PRIORITY_CLASS"), WINDOWS)
58
- ae(hasattr(psutil, "REALTIME_PRIORITY_CLASS"), WINDOWS)
51
+ assert hasattr(psutil, "ABOVE_NORMAL_PRIORITY_CLASS") == WINDOWS
52
+ assert hasattr(psutil, "BELOW_NORMAL_PRIORITY_CLASS") == WINDOWS
53
+ assert hasattr(psutil, "HIGH_PRIORITY_CLASS") == WINDOWS
54
+ assert hasattr(psutil, "IDLE_PRIORITY_CLASS") == WINDOWS
55
+ assert hasattr(psutil, "NORMAL_PRIORITY_CLASS") == WINDOWS
56
+ assert hasattr(psutil, "REALTIME_PRIORITY_CLASS") == WINDOWS
59
57
 
60
58
  def test_linux_ioprio_linux(self):
61
- ae = self.assertEqual
62
- ae(hasattr(psutil, "IOPRIO_CLASS_NONE"), LINUX)
63
- ae(hasattr(psutil, "IOPRIO_CLASS_RT"), LINUX)
64
- ae(hasattr(psutil, "IOPRIO_CLASS_BE"), LINUX)
65
- ae(hasattr(psutil, "IOPRIO_CLASS_IDLE"), LINUX)
59
+ assert hasattr(psutil, "IOPRIO_CLASS_NONE") == LINUX
60
+ assert hasattr(psutil, "IOPRIO_CLASS_RT") == LINUX
61
+ assert hasattr(psutil, "IOPRIO_CLASS_BE") == LINUX
62
+ assert hasattr(psutil, "IOPRIO_CLASS_IDLE") == LINUX
66
63
 
67
64
  def test_linux_ioprio_windows(self):
68
- ae = self.assertEqual
69
- ae(hasattr(psutil, "IOPRIO_HIGH"), WINDOWS)
70
- ae(hasattr(psutil, "IOPRIO_NORMAL"), WINDOWS)
71
- ae(hasattr(psutil, "IOPRIO_LOW"), WINDOWS)
72
- ae(hasattr(psutil, "IOPRIO_VERYLOW"), WINDOWS)
65
+ assert hasattr(psutil, "IOPRIO_HIGH") == WINDOWS
66
+ assert hasattr(psutil, "IOPRIO_NORMAL") == WINDOWS
67
+ assert hasattr(psutil, "IOPRIO_LOW") == WINDOWS
68
+ assert hasattr(psutil, "IOPRIO_VERYLOW") == WINDOWS
73
69
 
74
70
  @pytest.mark.skipif(
75
71
  GITHUB_ACTIONS and LINUX,
76
72
  reason="unsupported on GITHUB_ACTIONS + LINUX",
77
73
  )
78
74
  def test_rlimit(self):
79
- ae = self.assertEqual
80
- ae(hasattr(psutil, "RLIM_INFINITY"), LINUX or FREEBSD)
81
- ae(hasattr(psutil, "RLIMIT_AS"), LINUX or FREEBSD)
82
- ae(hasattr(psutil, "RLIMIT_CORE"), LINUX or FREEBSD)
83
- ae(hasattr(psutil, "RLIMIT_CPU"), LINUX or FREEBSD)
84
- ae(hasattr(psutil, "RLIMIT_DATA"), LINUX or FREEBSD)
85
- ae(hasattr(psutil, "RLIMIT_FSIZE"), LINUX or FREEBSD)
86
- ae(hasattr(psutil, "RLIMIT_MEMLOCK"), LINUX or FREEBSD)
87
- ae(hasattr(psutil, "RLIMIT_NOFILE"), LINUX or FREEBSD)
88
- ae(hasattr(psutil, "RLIMIT_NPROC"), LINUX or FREEBSD)
89
- ae(hasattr(psutil, "RLIMIT_RSS"), LINUX or FREEBSD)
90
- ae(hasattr(psutil, "RLIMIT_STACK"), LINUX or FREEBSD)
91
-
92
- ae(hasattr(psutil, "RLIMIT_LOCKS"), LINUX)
75
+ assert hasattr(psutil, "RLIM_INFINITY") == LINUX or FREEBSD
76
+ assert hasattr(psutil, "RLIMIT_AS") == LINUX or FREEBSD
77
+ assert hasattr(psutil, "RLIMIT_CORE") == LINUX or FREEBSD
78
+ assert hasattr(psutil, "RLIMIT_CPU") == LINUX or FREEBSD
79
+ assert hasattr(psutil, "RLIMIT_DATA") == LINUX or FREEBSD
80
+ assert hasattr(psutil, "RLIMIT_FSIZE") == LINUX or FREEBSD
81
+ assert hasattr(psutil, "RLIMIT_MEMLOCK") == LINUX or FREEBSD
82
+ assert hasattr(psutil, "RLIMIT_NOFILE") == LINUX or FREEBSD
83
+ assert hasattr(psutil, "RLIMIT_NPROC") == LINUX or FREEBSD
84
+ assert hasattr(psutil, "RLIMIT_RSS") == LINUX or FREEBSD
85
+ assert hasattr(psutil, "RLIMIT_STACK") == LINUX or FREEBSD
86
+
87
+ assert hasattr(psutil, "RLIMIT_LOCKS") == LINUX
93
88
  if POSIX:
94
89
  if kernel_version() >= (2, 6, 8):
95
- ae(hasattr(psutil, "RLIMIT_MSGQUEUE"), LINUX)
90
+ assert hasattr(psutil, "RLIMIT_MSGQUEUE") == LINUX
96
91
  if kernel_version() >= (2, 6, 12):
97
- ae(hasattr(psutil, "RLIMIT_NICE"), LINUX)
92
+ assert hasattr(psutil, "RLIMIT_NICE") == LINUX
98
93
  if kernel_version() >= (2, 6, 12):
99
- ae(hasattr(psutil, "RLIMIT_RTPRIO"), LINUX)
94
+ assert hasattr(psutil, "RLIMIT_RTPRIO") == LINUX
100
95
  if kernel_version() >= (2, 6, 25):
101
- ae(hasattr(psutil, "RLIMIT_RTTIME"), LINUX)
96
+ assert hasattr(psutil, "RLIMIT_RTTIME") == LINUX
102
97
  if kernel_version() >= (2, 6, 8):
103
- ae(hasattr(psutil, "RLIMIT_SIGPENDING"), LINUX)
98
+ assert hasattr(psutil, "RLIMIT_SIGPENDING") == LINUX
104
99
 
105
- ae(hasattr(psutil, "RLIMIT_SWAP"), FREEBSD)
106
- ae(hasattr(psutil, "RLIMIT_SBSIZE"), FREEBSD)
107
- ae(hasattr(psutil, "RLIMIT_NPTS"), FREEBSD)
100
+ assert hasattr(psutil, "RLIMIT_SWAP") == FREEBSD
101
+ assert hasattr(psutil, "RLIMIT_SBSIZE") == FREEBSD
102
+ assert hasattr(psutil, "RLIMIT_NPTS") == FREEBSD
108
103
 
109
104
 
110
105
  class TestAvailSystemAPIs(PsutilTestCase):
@@ -114,6 +109,7 @@ class TestAvailSystemAPIs(PsutilTestCase):
114
109
  def test_win_service_get(self):
115
110
  assert hasattr(psutil, "win_service_get") == WINDOWS
116
111
 
112
+ @pytest.mark.skipif(MACOS and AARCH64, reason="skipped due to #1892")
117
113
  def test_cpu_freq(self):
118
114
  assert hasattr(psutil, "cpu_freq") == (
119
115
  LINUX or MACOS or WINDOWS or FREEBSD or OPENBSD
@@ -226,9 +222,7 @@ class TestSystemAPITypes(PsutilTestCase):
226
222
  assert isinstance(psutil.cpu_count(), int)
227
223
 
228
224
  # TODO: remove this once 1892 is fixed
229
- @pytest.mark.skipif(
230
- MACOS and platform.machine() == 'arm64', reason="skipped due to #1892"
231
- )
225
+ @pytest.mark.skipif(MACOS and AARCH64, reason="skipped due to #1892")
232
226
  @pytest.mark.skipif(not HAS_CPU_FREQ, reason="not supported")
233
227
  def test_cpu_freq(self):
234
228
  if psutil.cpu_freq() is None:
@@ -313,12 +307,14 @@ class TestSystemAPITypes(PsutilTestCase):
313
307
  assert isinstance(user.terminal, (str, type(None)))
314
308
  assert isinstance(user.host, (str, type(None)))
315
309
  assert isinstance(user.pid, (int, type(None)))
310
+ if isinstance(user.pid, int):
311
+ assert user.pid > 0
316
312
 
317
313
 
318
314
  class TestProcessWaitType(PsutilTestCase):
319
315
  @pytest.mark.skipif(not POSIX, reason="not POSIX")
320
316
  def test_negative_signal(self):
321
- p = psutil.Process(self.spawn_testproc().pid)
317
+ p = psutil.Process(self.spawn_subproc().pid)
322
318
  p.terminate()
323
319
  code = p.wait()
324
320
  assert code == -signal.SIGTERM
@@ -31,8 +31,7 @@ from psutil.tests import HAS_BATTERY
31
31
  from psutil.tests import HAS_CPU_FREQ
32
32
  from psutil.tests import HAS_GETLOADAVG
33
33
  from psutil.tests import HAS_RLIMIT
34
- from psutil.tests import PYPY
35
- from psutil.tests import PYTEST_PARALLEL
34
+ from psutil.tests import RISCV64
36
35
  from psutil.tests import TOLERANCE_DISK_USAGE
37
36
  from psutil.tests import TOLERANCE_SYS_MEM
38
37
  from psutil.tests import PsutilTestCase
@@ -45,7 +44,6 @@ from psutil.tests import safe_rmpath
45
44
  from psutil.tests import sh
46
45
  from psutil.tests import skip_on_not_implemented
47
46
 
48
-
49
47
  if LINUX:
50
48
  from psutil._pslinux import CLOCK_TICKS
51
49
  from psutil._pslinux import RootFsDeviceFinder
@@ -243,10 +241,8 @@ class TestSystemVirtualMemoryAgainstFree(PsutilTestCase):
243
241
  # memory.
244
242
  # https://gitlab.com/procps-ng/procps/commit/
245
243
  # 2184e90d2e7cdb582f9a5b706b47015e56707e4d
246
- if get_free_version_info() < (3, 3, 12):
244
+ if get_free_version_info() < (4, 0, 0):
247
245
  raise pytest.skip("free version too old")
248
- if get_free_version_info() >= (4, 0, 0):
249
- raise pytest.skip("free version too recent")
250
246
  cli_value = free_physmem().used
251
247
  psutil_value = psutil.virtual_memory().used
252
248
  assert abs(cli_value - psutil_value) < TOLERANCE_SYS_MEM
@@ -298,10 +294,8 @@ class TestSystemVirtualMemoryAgainstVmstat(PsutilTestCase):
298
294
  # memory.
299
295
  # https://gitlab.com/procps-ng/procps/commit/
300
296
  # 2184e90d2e7cdb582f9a5b706b47015e56707e4d
301
- if get_free_version_info() < (3, 3, 12):
297
+ if get_free_version_info() < (4, 0, 0):
302
298
  raise pytest.skip("free version too old")
303
- if get_free_version_info() >= (4, 0, 0):
304
- raise pytest.skip("free version too recent")
305
299
  vmstat_value = vmstat('used memory') * 1024
306
300
  psutil_value = psutil.virtual_memory().used
307
301
  assert abs(vmstat_value - psutil_value) < TOLERANCE_SYS_MEM
@@ -776,7 +770,8 @@ class TestSystemCPUFrequency(PsutilTestCase):
776
770
 
777
771
  @pytest.mark.skipif(not HAS_CPU_FREQ, reason="not supported")
778
772
  @pytest.mark.skipif(
779
- AARCH64, reason="aarch64 does not report mhz in /proc/cpuinfo"
773
+ AARCH64 or RISCV64,
774
+ reason=f"{platform.machine()} does not report mhz in /proc/cpuinfo",
780
775
  )
781
776
  def test_emulate_use_cpuinfo(self):
782
777
  # Emulate a case where /sys/devices/system/cpu/cpufreq* does not
@@ -915,7 +910,7 @@ class TestSystemCPUStats(PsutilTestCase):
915
910
  # def test_ctx_switches(self):
916
911
  # vmstat_value = vmstat("context switches")
917
912
  # psutil_value = psutil.cpu_stats().ctx_switches
918
- # self.assertAlmostEqual(vmstat_value, psutil_value, delta=500)
913
+ # assert abs(vmstat_value - psutil_value) < 500
919
914
 
920
915
  def test_interrupts(self):
921
916
  vmstat_value = vmstat("interrupts")
@@ -977,9 +972,8 @@ class TestSystemNetIfAddrs(PsutilTestCase):
977
972
  # if re.search(r"^\d+:", line):
978
973
  # found += 1
979
974
  # name = line.split(':')[1].strip()
980
- # self.assertIn(name, nics)
981
- # self.assertEqual(len(nics), found, msg="{}\n---\n{}".format(
982
- # pprint.pformat(nics), out))
975
+ # assert name in nics
976
+ # assert len(nics) == found
983
977
 
984
978
 
985
979
  @pytest.mark.skipif(not LINUX, reason="LINUX only")
@@ -1034,7 +1028,7 @@ class TestSystemNetIfStats(PsutilTestCase):
1034
1028
  assert ifconfig_flags == psutil_flags
1035
1029
 
1036
1030
  if not matches_found:
1037
- raise self.fail("no matches were found")
1031
+ raise pytest.fail("no matches were found")
1038
1032
 
1039
1033
 
1040
1034
  @pytest.mark.skipif(not LINUX, reason="LINUX only")
@@ -1095,13 +1089,12 @@ class TestSystemNetConnections(PsutilTestCase):
1095
1089
  @mock.patch('psutil._pslinux.supports_ipv6', return_value=False)
1096
1090
  def test_emulate_ipv6_unsupported(self, supports_ipv6, inet_ntop):
1097
1091
  # see: https://github.com/giampaolo/psutil/issues/623
1098
- try:
1099
- s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
1100
- self.addCleanup(s.close)
1101
- s.bind(("::1", 0))
1102
- except OSError:
1103
- pass
1104
- psutil.net_connections(kind='inet6')
1092
+ with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s:
1093
+ try:
1094
+ s.bind(("::1", 0))
1095
+ except OSError:
1096
+ pass
1097
+ psutil.net_connections(kind='inet6')
1105
1098
 
1106
1099
  def test_emulate_unix(self):
1107
1100
  content = textwrap.dedent("""\
@@ -1525,14 +1518,12 @@ class TestMisc(PsutilTestCase):
1525
1518
  psutil.cpu_times(percpu=True)
1526
1519
  with pytest.raises(OSError):
1527
1520
  psutil.boot_time()
1528
- # self.assertRaises(OSError, psutil.pids)
1529
1521
  with pytest.raises(OSError):
1530
1522
  psutil.net_connections()
1531
1523
  with pytest.raises(OSError):
1532
1524
  psutil.net_io_counters()
1533
1525
  with pytest.raises(OSError):
1534
1526
  psutil.net_if_stats()
1535
- # self.assertRaises(OSError, psutil.disk_io_counters)
1536
1527
  with pytest.raises(OSError):
1537
1528
  psutil.disk_partitions()
1538
1529
  with pytest.raises(psutil.NoSuchProcess):
@@ -1541,17 +1532,19 @@ class TestMisc(PsutilTestCase):
1541
1532
  psutil.PROCFS_PATH = "/proc"
1542
1533
 
1543
1534
  @retry_on_failure()
1544
- @pytest.mark.skipif(PYTEST_PARALLEL, reason="skip if pytest-parallel")
1535
+ @pytest.mark.xdist_group(name="serial")
1545
1536
  def test_issue_687(self):
1546
1537
  # In case of thread ID:
1547
1538
  # - pid_exists() is supposed to return False
1548
1539
  # - Process(tid) is supposed to work
1549
1540
  # - pids() should not return the TID
1550
1541
  # See: https://github.com/giampaolo/psutil/issues/687
1542
+
1543
+ p = psutil.Process()
1544
+ nthreads = len(p.threads())
1551
1545
  with ThreadTask():
1552
- p = psutil.Process()
1553
1546
  threads = p.threads()
1554
- assert len(threads) == 2
1547
+ assert len(threads) == nthreads + 1
1555
1548
  tid = sorted(threads, key=lambda x: x.id)[1].id
1556
1549
  assert p.pid != tid
1557
1550
  pt = psutil.Process(tid)
@@ -1824,7 +1817,7 @@ class TestSensorsFans(PsutilTestCase):
1824
1817
  class TestProcess(PsutilTestCase):
1825
1818
  @retry_on_failure()
1826
1819
  def test_parse_smaps_vs_memory_maps(self):
1827
- sproc = self.spawn_testproc()
1820
+ sproc = self.spawn_subproc()
1828
1821
  uss, pss, swap = psutil._pslinux.Process(sproc.pid)._parse_smaps()
1829
1822
  maps = psutil.Process(sproc.pid).memory_maps(grouped=False)
1830
1823
  assert (
@@ -1867,8 +1860,6 @@ class TestProcess(PsutilTestCase):
1867
1860
  assert pss == 3 * 1024
1868
1861
  assert swap == 15 * 1024
1869
1862
 
1870
- # On PYPY file descriptors are not closed fast enough.
1871
- @pytest.mark.skipif(PYPY, reason="unreliable on PYPY")
1872
1863
  def test_open_files_mode(self):
1873
1864
  def get_test_file(fname):
1874
1865
  p = psutil.Process()
@@ -1966,14 +1957,6 @@ class TestProcess(PsutilTestCase):
1966
1957
  assert psutil._pslinux.Process(os.getpid()).terminal() is None
1967
1958
  assert m.called
1968
1959
 
1969
- # TODO: re-enable this test.
1970
- # def test_num_ctx_switches_mocked(self):
1971
- # with mock.patch('psutil._common.open', create=True) as m:
1972
- # self.assertRaises(
1973
- # NotImplementedError,
1974
- # psutil._pslinux.Process(os.getpid()).num_ctx_switches)
1975
- # assert m.called
1976
-
1977
1960
  def test_cmdline_mocked(self):
1978
1961
  # see: https://github.com/giampaolo/psutil/issues/639
1979
1962
  p = psutil.Process()
@@ -2063,6 +2046,15 @@ class TestProcess(PsutilTestCase):
2063
2046
  assert m.called
2064
2047
  assert ret == ""
2065
2048
 
2049
+ def test_cwd_mocked(self):
2050
+ # https://github.com/giampaolo/psutil/issues/2514
2051
+ with mock.patch(
2052
+ 'psutil._pslinux.readlink', side_effect=FileNotFoundError
2053
+ ) as m:
2054
+ ret = psutil.Process().cwd()
2055
+ assert m.called
2056
+ assert ret == ""
2057
+
2066
2058
  def test_issue_1014(self):
2067
2059
  # Emulates a case where smaps file does not exist. In this case
2068
2060
  # wrap_exception decorator should not raise NoSuchProcess.
@@ -2200,6 +2192,11 @@ class TestProcess(PsutilTestCase):
2200
2192
  assert p.net_connections() == []
2201
2193
  assert m.called
2202
2194
 
2195
+ def test_create_time_monotonic(self):
2196
+ p = psutil.Process()
2197
+ assert p._proc.create_time() != p._proc.create_time(monotonic=True)
2198
+ assert p._get_ident()[1] == p._proc.create_time(monotonic=True)
2199
+
2203
2200
 
2204
2201
  @pytest.mark.skipif(not LINUX, reason="LINUX only")
2205
2202
  class TestProcessAgainstStatus(PsutilTestCase):
@@ -14,10 +14,8 @@ PyPy appears to be completely unstable for this framework, probably
14
14
  because of how its JIT handles memory, so tests are skipped.
15
15
  """
16
16
 
17
-
18
17
  import functools
19
18
  import os
20
- import platform
21
19
 
22
20
  import psutil
23
21
  import psutil._common
@@ -27,6 +25,7 @@ from psutil import OPENBSD
27
25
  from psutil import POSIX
28
26
  from psutil import SUNOS
29
27
  from psutil import WINDOWS
28
+ from psutil.tests import AARCH64
30
29
  from psutil.tests import HAS_CPU_AFFINITY
31
30
  from psutil.tests import HAS_CPU_FREQ
32
31
  from psutil.tests import HAS_ENVIRON
@@ -45,11 +44,10 @@ from psutil.tests import get_testfn
45
44
  from psutil.tests import process_namespace
46
45
  from psutil.tests import pytest
47
46
  from psutil.tests import skip_on_access_denied
48
- from psutil.tests import spawn_testproc
47
+ from psutil.tests import spawn_subproc
49
48
  from psutil.tests import system_namespace
50
49
  from psutil.tests import terminate
51
50
 
52
-
53
51
  cext = psutil._psplatform.cext
54
52
  thisproc = psutil.Process()
55
53
  FEW_TIMES = 5
@@ -274,7 +272,7 @@ class TestTerminatedProcessLeaks(TestProcessObjectLeaks):
274
272
  @classmethod
275
273
  def setUpClass(cls):
276
274
  super().setUpClass()
277
- cls.subp = spawn_testproc()
275
+ cls.subp = spawn_subproc()
278
276
  cls.proc = psutil.Process(cls.subp.pid)
279
277
  cls.proc.kill()
280
278
  cls.proc.wait()
@@ -363,9 +361,7 @@ class TestModuleFunctionsLeaks(TestMemoryLeak):
363
361
 
364
362
  @fewtimes_if_linux()
365
363
  # TODO: remove this once 1892 is fixed
366
- @pytest.mark.skipif(
367
- MACOS and platform.machine() == 'arm64', reason="skipped due to #1892"
368
- )
364
+ @pytest.mark.skipif(MACOS and AARCH64, reason="skipped due to #1892")
369
365
  @pytest.mark.skipif(not HAS_CPU_FREQ, reason="not supported")
370
366
  def test_cpu_freq(self):
371
367
  self.execute(psutil.cpu_freq)
@@ -35,7 +35,6 @@ from psutil.tests import pytest
35
35
  from psutil.tests import reload_module
36
36
  from psutil.tests import system_namespace
37
37
 
38
-
39
38
  # ===================================================================
40
39
  # --- Test classes' repr(), str(), ...
41
40
  # ===================================================================
@@ -49,7 +48,7 @@ class TestSpecialMethods(PsutilTestCase):
49
48
  psutil.Process(2**128)
50
49
 
51
50
  def test_process__repr__(self, func=repr):
52
- p = psutil.Process(self.spawn_testproc().pid)
51
+ p = psutil.Process(self.spawn_subproc().pid)
53
52
  r = func(p)
54
53
  assert "psutil.Process" in r
55
54
  assert f"pid={p.pid}" in r
@@ -218,7 +217,9 @@ class TestMisc(PsutilTestCase):
218
217
  fun.__doc__ is not None
219
218
  and 'deprecated' not in fun.__doc__.lower()
220
219
  ):
221
- raise self.fail(f"{name!r} not in psutil.__all__")
220
+ raise pytest.fail(
221
+ f"{name!r} not in psutil.__all__"
222
+ )
222
223
 
223
224
  # Import 'star' will break if __all__ is inconsistent, see:
224
225
  # https://github.com/giampaolo/psutil/issues/656
@@ -254,7 +255,7 @@ class TestMisc(PsutilTestCase):
254
255
 
255
256
  ns = process_namespace(proc)
256
257
  for fun, name in ns.iter(ns.getters, clear_cache=True):
257
- with self.subTest(proc=proc, name=name):
258
+ with self.subTest(proc=str(proc), name=name):
258
259
  try:
259
260
  ret = fun()
260
261
  except psutil.Error:
@@ -342,7 +343,7 @@ class TestMisc(PsutilTestCase):
342
343
  with mock.patch.object(
343
344
  psutil.Process, '_get_ident', side_effect=psutil.NoSuchProcess(1)
344
345
  ) as meth:
345
- with self.assertRaises(psutil.NoSuchProcess):
346
+ with pytest.raises(psutil.NoSuchProcess):
346
347
  psutil.Process()
347
348
  assert meth.called
348
349
 
@@ -545,35 +546,28 @@ class TestCommonModule(PsutilTestCase):
545
546
  assert parse_environ_block("a=1\0b=2") == {k("a"): "1"}
546
547
 
547
548
  def test_supports_ipv6(self):
548
- self.addCleanup(supports_ipv6.cache_clear)
549
549
  if supports_ipv6():
550
550
  with mock.patch('psutil._common.socket') as s:
551
551
  s.has_ipv6 = False
552
- supports_ipv6.cache_clear()
553
552
  assert not supports_ipv6()
554
553
 
555
- supports_ipv6.cache_clear()
556
554
  with mock.patch(
557
555
  'psutil._common.socket.socket', side_effect=OSError
558
556
  ) as s:
559
557
  assert not supports_ipv6()
560
558
  assert s.called
561
559
 
562
- supports_ipv6.cache_clear()
563
560
  with mock.patch(
564
561
  'psutil._common.socket.socket', side_effect=socket.gaierror
565
562
  ) as s:
566
563
  assert not supports_ipv6()
567
- supports_ipv6.cache_clear()
568
564
  assert s.called
569
565
 
570
- supports_ipv6.cache_clear()
571
566
  with mock.patch(
572
567
  'psutil._common.socket.socket.bind',
573
568
  side_effect=socket.gaierror,
574
569
  ) as s:
575
570
  assert not supports_ipv6()
576
- supports_ipv6.cache_clear()
577
571
  assert s.called
578
572
  else:
579
573
  with pytest.raises(OSError):
@@ -6,13 +6,13 @@
6
6
 
7
7
  """macOS specific tests."""
8
8
 
9
- import platform
10
9
  import re
11
10
  import time
12
11
 
13
12
  import psutil
14
13
  from psutil import MACOS
15
14
  from psutil import POSIX
15
+ from psutil.tests import AARCH64
16
16
  from psutil.tests import CI_TESTING
17
17
  from psutil.tests import HAS_BATTERY
18
18
  from psutil.tests import TOLERANCE_DISK_USAGE
@@ -21,10 +21,9 @@ from psutil.tests import PsutilTestCase
21
21
  from psutil.tests import pytest
22
22
  from psutil.tests import retry_on_failure
23
23
  from psutil.tests import sh
24
- from psutil.tests import spawn_testproc
24
+ from psutil.tests import spawn_subproc
25
25
  from psutil.tests import terminate
26
26
 
27
-
28
27
  if POSIX:
29
28
  from psutil._psutil_posix import getpagesize
30
29
 
@@ -56,7 +55,7 @@ def vm_stat(field):
56
55
  class TestProcess(PsutilTestCase):
57
56
  @classmethod
58
57
  def setUpClass(cls):
59
- cls.pid = spawn_testproc().pid
58
+ cls.pid = spawn_subproc().pid
60
59
 
61
60
  @classmethod
62
61
  def tearDownClass(cls):
@@ -115,9 +114,7 @@ class TestSystemAPIs(PsutilTestCase):
115
114
  assert num == psutil.cpu_count(logical=False)
116
115
 
117
116
  # TODO: remove this once 1892 is fixed
118
- @pytest.mark.skipif(
119
- MACOS and platform.machine() == 'arm64', reason="skipped due to #1892"
120
- )
117
+ @pytest.mark.skipif(MACOS and AARCH64, reason="skipped due to #1892")
121
118
  def test_cpu_freq(self):
122
119
  freq = psutil.cpu_freq()
123
120
  assert freq.current * 1000 * 1000 == sysctl("sysctl hw.cpufrequency")
@@ -131,7 +128,7 @@ class TestSystemAPIs(PsutilTestCase):
131
128
  assert sysctl_hwphymem == psutil.virtual_memory().total
132
129
 
133
130
  @pytest.mark.skipif(
134
- CI_TESTING and MACOS and platform.machine() == 'arm64',
131
+ CI_TESTING and MACOS and AARCH64,
135
132
  reason="skipped on MACOS + ARM64 + CI_TESTING",
136
133
  )
137
134
  @retry_on_failure()
@@ -140,6 +137,10 @@ class TestSystemAPIs(PsutilTestCase):
140
137
  psutil_val = psutil.virtual_memory().free
141
138
  assert abs(psutil_val - vmstat_val) < TOLERANCE_SYS_MEM
142
139
 
140
+ @pytest.mark.skipif(
141
+ CI_TESTING and MACOS and AARCH64,
142
+ reason="skipped on MACOS + ARM64 + CI_TESTING",
143
+ )
143
144
  @retry_on_failure()
144
145
  def test_vmem_active(self):
145
146
  vmstat_val = vm_stat("active")
@@ -195,3 +196,11 @@ class TestSystemAPIs(PsutilTestCase):
195
196
  psutil_result = psutil.sensors_battery()
196
197
  assert psutil_result.power_plugged == power_plugged
197
198
  assert psutil_result.percent == int(percent)
199
+
200
+ # --- others
201
+
202
+ def test_boot_time(self):
203
+ out = sh('sysctl kern.boottime')
204
+ a = float(re.search(r"sec\s*=\s*(\d+)", out).groups(0)[0])
205
+ b = psutil.boot_time()
206
+ assert a == b
@@ -31,10 +31,9 @@ from psutil.tests import pytest
31
31
  from psutil.tests import retry_on_failure
32
32
  from psutil.tests import sh
33
33
  from psutil.tests import skip_on_access_denied
34
- from psutil.tests import spawn_testproc
34
+ from psutil.tests import spawn_subproc
35
35
  from psutil.tests import terminate
36
36
 
37
-
38
37
  if POSIX:
39
38
  import mmap
40
39
  import resource
@@ -151,7 +150,7 @@ class TestProcess(PsutilTestCase):
151
150
 
152
151
  @classmethod
153
152
  def setUpClass(cls):
154
- cls.pid = spawn_testproc(
153
+ cls.pid = spawn_subproc(
155
154
  [PYTHON_EXE, "-E", "-O"], stdin=subprocess.PIPE
156
155
  ).pid
157
156
 
@@ -338,7 +337,7 @@ class TestSystemAPIs(PsutilTestCase):
338
337
  difference = [x for x in pids_psutil if x not in pids_ps] + [
339
338
  x for x in pids_ps if x not in pids_psutil
340
339
  ]
341
- raise self.fail("difference: " + str(difference))
340
+ raise pytest.fail("difference: " + str(difference))
342
341
 
343
342
  # for some reason ifconfig -a does not report all interfaces
344
343
  # returned by psutil
@@ -352,28 +351,41 @@ class TestSystemAPIs(PsutilTestCase):
352
351
  if line.startswith(nic):
353
352
  break
354
353
  else:
355
- raise self.fail(
354
+ raise pytest.fail(
356
355
  f"couldn't find {nic} nic in 'ifconfig -a'"
357
356
  f" output\n{output}"
358
357
  )
359
358
 
360
- # @pytest.mark.skipif(CI_TESTING and not psutil.users(),
361
- # reason="unreliable on CI")
362
359
  @retry_on_failure()
363
360
  def test_users(self):
364
361
  out = sh("who -u")
365
362
  if not out.strip():
366
363
  raise pytest.skip("no users on this system")
367
- lines = out.split('\n')
368
- users = [x.split()[0] for x in lines]
369
- terminals = [x.split()[1] for x in lines]
370
- assert len(users) == len(psutil.users())
371
- with self.subTest(psutil=psutil.users(), who=out):
372
- for idx, u in enumerate(psutil.users()):
373
- assert u.name == users[idx]
374
- assert u.terminal == terminals[idx]
375
- if u.pid is not None: # None on OpenBSD
376
- psutil.Process(u.pid)
364
+
365
+ susers = []
366
+ for line in out.splitlines():
367
+ user = line.split()[0]
368
+ terminal = line.split()[1]
369
+ if LINUX or MACOS:
370
+ try:
371
+ pid = int(line.split()[-2])
372
+ except ValueError:
373
+ pid = int(line.split()[-1])
374
+ susers.append((user, terminal, pid))
375
+ else:
376
+ susers.append((user, terminal))
377
+
378
+ if LINUX or MACOS:
379
+ pusers = [(u.name, u.terminal, u.pid) for u in psutil.users()]
380
+ else:
381
+ pusers = [(u.name, u.terminal) for u in psutil.users()]
382
+
383
+ assert len(susers) == len(pusers)
384
+ assert sorted(susers) == sorted(pusers)
385
+
386
+ for user in psutil.users():
387
+ if user.pid is not None:
388
+ assert user.pid > 0
377
389
 
378
390
  @retry_on_failure()
379
391
  def test_users_started(self):