py2docfx 0.1.11rc1981066__py3-none-any.whl → 0.1.11rc1996319__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 (126) hide show
  1. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/authorization_code.py +1 -1
  2. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azd_cli.py +20 -14
  3. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_arc.py +1 -1
  4. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_cli.py +36 -14
  5. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_powershell.py +1 -1
  6. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/chained.py +2 -2
  7. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/default.py +4 -3
  8. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/imds.py +2 -2
  9. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/managed_identity.py +1 -1
  10. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/__init__.py +2 -0
  11. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/auth_code_redirect_handler.py +1 -1
  12. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/decorators.py +15 -7
  13. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/interactive.py +1 -1
  14. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/managed_identity_client.py +0 -1
  15. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/msal_client.py +1 -1
  16. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/msal_managed_identity_client.py +2 -1
  17. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/shared_token_cache.py +3 -3
  18. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/utils.py +17 -2
  19. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_version.py +1 -1
  20. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azd_cli.py +14 -11
  21. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azure_cli.py +30 -12
  22. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/default.py +2 -2
  23. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/imds.py +3 -3
  24. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/managed_identity.py +1 -1
  25. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_internal/decorators.py +15 -7
  26. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_internal/managed_identity_client.py +1 -1
  27. py2docfx/venv/venv1/Lib/site-packages/cryptography/__about__.py +1 -1
  28. py2docfx/venv/venv1/Lib/site-packages/google/api/annotations_pb2.py +7 -4
  29. py2docfx/venv/venv1/Lib/site-packages/google/api/auth_pb2.py +6 -3
  30. py2docfx/venv/venv1/Lib/site-packages/google/api/backend_pb2.py +14 -7
  31. py2docfx/venv/venv1/Lib/site-packages/google/api/billing_pb2.py +6 -3
  32. py2docfx/venv/venv1/Lib/site-packages/google/api/client_pb2.py +47 -38
  33. py2docfx/venv/venv1/Lib/site-packages/google/api/config_change_pb2.py +6 -3
  34. py2docfx/venv/venv1/Lib/site-packages/google/api/consumer_pb2.py +6 -3
  35. py2docfx/venv/venv1/Lib/site-packages/google/api/context_pb2.py +6 -3
  36. py2docfx/venv/venv1/Lib/site-packages/google/api/control_pb2.py +6 -4
  37. py2docfx/venv/venv1/Lib/site-packages/google/api/distribution_pb2.py +7 -5
  38. py2docfx/venv/venv1/Lib/site-packages/google/api/documentation_pb2.py +6 -3
  39. py2docfx/venv/venv1/Lib/site-packages/google/api/endpoint_pb2.py +6 -3
  40. py2docfx/venv/venv1/Lib/site-packages/google/api/error_reason_pb2.py +6 -3
  41. py2docfx/venv/venv1/Lib/site-packages/google/api/field_behavior_pb2.py +8 -6
  42. py2docfx/venv/venv1/Lib/site-packages/google/api/field_info_pb2.py +6 -4
  43. py2docfx/venv/venv1/Lib/site-packages/google/api/http_pb2.py +7 -4
  44. py2docfx/venv/venv1/Lib/site-packages/google/api/httpbody_pb2.py +6 -4
  45. py2docfx/venv/venv1/Lib/site-packages/google/api/label_pb2.py +7 -4
  46. py2docfx/venv/venv1/Lib/site-packages/google/api/launch_stage_pb2.py +6 -3
  47. py2docfx/venv/venv1/Lib/site-packages/google/api/log_pb2.py +6 -4
  48. py2docfx/venv/venv1/Lib/site-packages/google/api/logging_pb2.py +6 -3
  49. py2docfx/venv/venv1/Lib/site-packages/google/api/metric_pb2.py +12 -9
  50. py2docfx/venv/venv1/Lib/site-packages/google/api/monitored_resource_pb2.py +15 -10
  51. py2docfx/venv/venv1/Lib/site-packages/google/api/monitoring_pb2.py +6 -3
  52. py2docfx/venv/venv1/Lib/site-packages/google/api/policy_pb2.py +7 -5
  53. py2docfx/venv/venv1/Lib/site-packages/google/api/quota_pb2.py +10 -7
  54. py2docfx/venv/venv1/Lib/site-packages/google/api/resource_pb2.py +7 -5
  55. py2docfx/venv/venv1/Lib/site-packages/google/api/routing_pb2.py +6 -4
  56. py2docfx/venv/venv1/Lib/site-packages/google/api/service_pb2.py +15 -12
  57. py2docfx/venv/venv1/Lib/site-packages/google/api/source_info_pb2.py +6 -4
  58. py2docfx/venv/venv1/Lib/site-packages/google/api/system_parameter_pb2.py +6 -3
  59. py2docfx/venv/venv1/Lib/site-packages/google/api/usage_pb2.py +6 -3
  60. py2docfx/venv/venv1/Lib/site-packages/google/api/visibility_pb2.py +7 -5
  61. py2docfx/venv/venv1/Lib/site-packages/google/cloud/extended_operations_pb2.py +6 -4
  62. py2docfx/venv/venv1/Lib/site-packages/google/cloud/location/locations_pb2.py +18 -13
  63. py2docfx/venv/venv1/Lib/site-packages/google/gapic/metadata/gapic_metadata_pb2.py +31 -26
  64. py2docfx/venv/venv1/Lib/site-packages/google/logging/type/http_request_pb2.py +6 -4
  65. py2docfx/venv/venv1/Lib/site-packages/google/logging/type/log_severity_pb2.py +6 -3
  66. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_grpc.py +2 -1
  67. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_grpc_pb2.py +11 -10
  68. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_pb2.py +20 -17
  69. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_pb2_grpc.py +1 -2
  70. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_proto.py +2 -1
  71. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_proto_pb2.py +22 -19
  72. py2docfx/venv/venv1/Lib/site-packages/google/rpc/code_pb2.py +6 -3
  73. py2docfx/venv/venv1/Lib/site-packages/google/rpc/context/attribute_context_pb2.py +20 -16
  74. py2docfx/venv/venv1/Lib/site-packages/google/rpc/context/audit_context_pb2.py +7 -5
  75. py2docfx/venv/venv1/Lib/site-packages/google/rpc/error_details_pb2.py +21 -19
  76. py2docfx/venv/venv1/Lib/site-packages/google/rpc/http_pb2.py +6 -3
  77. py2docfx/venv/venv1/Lib/site-packages/google/rpc/status_pb2.py +6 -4
  78. py2docfx/venv/venv1/Lib/site-packages/google/type/calendar_period_pb2.py +6 -3
  79. py2docfx/venv/venv1/Lib/site-packages/google/type/color_pb2.py +6 -4
  80. py2docfx/venv/venv1/Lib/site-packages/google/type/date_pb2.py +6 -3
  81. py2docfx/venv/venv1/Lib/site-packages/google/type/datetime_pb2.py +6 -4
  82. py2docfx/venv/venv1/Lib/site-packages/google/type/dayofweek_pb2.py +6 -3
  83. py2docfx/venv/venv1/Lib/site-packages/google/type/decimal_pb2.py +6 -3
  84. py2docfx/venv/venv1/Lib/site-packages/google/type/expr_pb2.py +6 -3
  85. py2docfx/venv/venv1/Lib/site-packages/google/type/fraction_pb2.py +6 -3
  86. py2docfx/venv/venv1/Lib/site-packages/google/type/interval_pb2.py +6 -4
  87. py2docfx/venv/venv1/Lib/site-packages/google/type/latlng_pb2.py +6 -3
  88. py2docfx/venv/venv1/Lib/site-packages/google/type/localized_text_pb2.py +6 -3
  89. py2docfx/venv/venv1/Lib/site-packages/google/type/money_pb2.py +6 -3
  90. py2docfx/venv/venv1/Lib/site-packages/google/type/month_pb2.py +6 -3
  91. py2docfx/venv/venv1/Lib/site-packages/google/type/phone_number_pb2.py +6 -3
  92. py2docfx/venv/venv1/Lib/site-packages/google/type/postal_address_pb2.py +6 -3
  93. py2docfx/venv/venv1/Lib/site-packages/google/type/quaternion_pb2.py +6 -3
  94. py2docfx/venv/venv1/Lib/site-packages/google/type/timeofday_pb2.py +6 -3
  95. py2docfx/venv/venv1/Lib/site-packages/psutil/__init__.py +122 -201
  96. py2docfx/venv/venv1/Lib/site-packages/psutil/_common.py +84 -128
  97. py2docfx/venv/venv1/Lib/site-packages/psutil/_psaix.py +24 -38
  98. py2docfx/venv/venv1/Lib/site-packages/psutil/_psbsd.py +44 -58
  99. py2docfx/venv/venv1/Lib/site-packages/psutil/_pslinux.py +170 -254
  100. py2docfx/venv/venv1/Lib/site-packages/psutil/_psosx.py +8 -16
  101. py2docfx/venv/venv1/Lib/site-packages/psutil/_psposix.py +13 -49
  102. py2docfx/venv/venv1/Lib/site-packages/psutil/_pssunos.py +41 -60
  103. py2docfx/venv/venv1/Lib/site-packages/psutil/_pswindows.py +75 -145
  104. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/__init__.py +105 -193
  105. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_aix.py +2 -2
  106. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_bsd.py +27 -26
  107. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_connections.py +16 -17
  108. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_contracts.py +5 -19
  109. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_linux.py +153 -211
  110. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_memleaks.py +0 -6
  111. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_misc.py +22 -207
  112. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_osx.py +9 -4
  113. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_posix.py +8 -15
  114. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_process.py +104 -184
  115. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_process_all.py +28 -36
  116. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_scripts.py +240 -0
  117. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_sunos.py +1 -1
  118. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_system.py +44 -50
  119. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_testutils.py +23 -33
  120. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_unicode.py +8 -67
  121. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_windows.py +32 -52
  122. {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1996319.dist-info}/METADATA +1 -1
  123. {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1996319.dist-info}/RECORD +125 -125
  124. py2docfx/venv/venv1/Lib/site-packages/psutil/_compat.py +0 -477
  125. {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1996319.dist-info}/WHEEL +0 -0
  126. {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1996319.dist-info}/top_level.txt +0 -0
@@ -6,13 +6,13 @@
6
6
 
7
7
  """Linux specific tests."""
8
8
 
9
- from __future__ import division
10
9
 
11
10
  import collections
12
11
  import contextlib
13
12
  import errno
14
13
  import io
15
14
  import os
15
+ import platform
16
16
  import re
17
17
  import shutil
18
18
  import socket
@@ -20,12 +20,10 @@ import struct
20
20
  import textwrap
21
21
  import time
22
22
  import warnings
23
+ from unittest import mock
23
24
 
24
25
  import psutil
25
26
  from psutil import LINUX
26
- from psutil._compat import PY3
27
- from psutil._compat import FileNotFoundError
28
- from psutil._compat import basestring
29
27
  from psutil.tests import AARCH64
30
28
  from psutil.tests import GITHUB_ACTIONS
31
29
  from psutil.tests import GLOBAL_TIMEOUT
@@ -35,20 +33,17 @@ from psutil.tests import HAS_GETLOADAVG
35
33
  from psutil.tests import HAS_RLIMIT
36
34
  from psutil.tests import PYPY
37
35
  from psutil.tests import PYTEST_PARALLEL
38
- from psutil.tests import QEMU_USER
39
36
  from psutil.tests import TOLERANCE_DISK_USAGE
40
37
  from psutil.tests import TOLERANCE_SYS_MEM
41
38
  from psutil.tests import PsutilTestCase
42
39
  from psutil.tests import ThreadTask
43
40
  from psutil.tests import call_until
44
- from psutil.tests import mock
45
41
  from psutil.tests import pytest
46
42
  from psutil.tests import reload_module
47
43
  from psutil.tests import retry_on_failure
48
44
  from psutil.tests import safe_rmpath
49
45
  from psutil.tests import sh
50
46
  from psutil.tests import skip_on_not_implemented
51
- from psutil.tests import which
52
47
 
53
48
 
54
49
  if LINUX:
@@ -73,11 +68,8 @@ if LINUX:
73
68
  def get_ipv4_address(ifname):
74
69
  import fcntl
75
70
 
76
- ifname = ifname[:15]
77
- if PY3:
78
- ifname = bytes(ifname, 'ascii')
79
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
80
- with contextlib.closing(s):
71
+ ifname = bytes(ifname[:15], "ascii")
72
+ with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
81
73
  return socket.inet_ntoa(
82
74
  fcntl.ioctl(s.fileno(), SIOCGIFADDR, struct.pack('256s', ifname))[
83
75
  20:24
@@ -88,11 +80,8 @@ def get_ipv4_address(ifname):
88
80
  def get_ipv4_netmask(ifname):
89
81
  import fcntl
90
82
 
91
- ifname = ifname[:15]
92
- if PY3:
93
- ifname = bytes(ifname, 'ascii')
94
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
95
- with contextlib.closing(s):
83
+ ifname = bytes(ifname[:15], "ascii")
84
+ with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
96
85
  return socket.inet_ntoa(
97
86
  fcntl.ioctl(
98
87
  s.fileno(), SIOCGIFNETMASK, struct.pack('256s', ifname)
@@ -103,11 +92,8 @@ def get_ipv4_netmask(ifname):
103
92
  def get_ipv4_broadcast(ifname):
104
93
  import fcntl
105
94
 
106
- ifname = ifname[:15]
107
- if PY3:
108
- ifname = bytes(ifname, 'ascii')
109
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
110
- with contextlib.closing(s):
95
+ ifname = bytes(ifname[:15], "ascii")
96
+ with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
111
97
  return socket.inet_ntoa(
112
98
  fcntl.ioctl(
113
99
  s.fileno(), SIOCGIFBRDADDR, struct.pack('256s', ifname)
@@ -124,13 +110,13 @@ def get_ipv6_addresses(ifname):
124
110
  all_fields.append(fields)
125
111
 
126
112
  if len(all_fields) == 0:
127
- raise ValueError("could not find interface %r" % ifname)
113
+ raise ValueError(f"could not find interface {ifname!r}")
128
114
 
129
115
  for i in range(len(all_fields)):
130
116
  unformatted = all_fields[i][0]
131
- groups = []
132
- for j in range(0, len(unformatted), 4):
133
- groups.append(unformatted[j : j + 4])
117
+ groups = [
118
+ unformatted[j : j + 4] for j in range(0, len(unformatted), 4)
119
+ ]
134
120
  formatted = ":".join(groups)
135
121
  packed = socket.inet_pton(socket.AF_INET6, formatted)
136
122
  all_fields[i] = socket.inet_ntop(socket.AF_INET6, packed)
@@ -140,24 +126,12 @@ def get_ipv6_addresses(ifname):
140
126
  def get_mac_address(ifname):
141
127
  import fcntl
142
128
 
143
- ifname = ifname[:15]
144
- if PY3:
145
- ifname = bytes(ifname, 'ascii')
146
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
147
- with contextlib.closing(s):
129
+ ifname = bytes(ifname[:15], "ascii")
130
+ with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
148
131
  info = fcntl.ioctl(
149
132
  s.fileno(), SIOCGIFHWADDR, struct.pack('256s', ifname)
150
133
  )
151
- if PY3:
152
-
153
- def ord(x):
154
- return x
155
-
156
- else:
157
- import __builtin__
158
-
159
- ord = __builtin__.ord
160
- return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
134
+ return "".join([f"{char:02x}:" for char in info[18:24]])[:-1]
161
135
 
162
136
 
163
137
  def free_swap():
@@ -171,9 +145,7 @@ def free_swap():
171
145
  _, total, used, free = line.split()
172
146
  nt = collections.namedtuple('free', 'total used free')
173
147
  return nt(int(total), int(used), int(free))
174
- raise ValueError(
175
- "can't find 'Swap' in 'free' output:\n%s" % '\n'.join(lines)
176
- )
148
+ raise ValueError(f"can't find 'Swap' in 'free' output:\n{out}")
177
149
 
178
150
 
179
151
  def free_physmem():
@@ -193,9 +165,7 @@ def free_physmem():
193
165
  'free', 'total used free shared output'
194
166
  )
195
167
  return nt(total, used, free, shared, out)
196
- raise ValueError(
197
- "can't find 'Mem' in 'free' output:\n%s" % '\n'.join(lines)
198
- )
168
+ raise ValueError(f"can't find 'Mem' in 'free' output:\n{out}")
199
169
 
200
170
 
201
171
  def vmstat(stat):
@@ -204,7 +174,7 @@ def vmstat(stat):
204
174
  line = line.strip()
205
175
  if stat in line:
206
176
  return int(line.split(' ')[0])
207
- raise ValueError("can't find %r in 'vmstat' output" % stat)
177
+ raise ValueError(f"can't find {stat!r} in 'vmstat' output")
208
178
 
209
179
 
210
180
  def get_free_version_info():
@@ -223,19 +193,15 @@ def mock_open_content(pairs):
223
193
  def open_mock(name, *args, **kwargs):
224
194
  if name in pairs:
225
195
  content = pairs[name]
226
- if PY3:
227
- if isinstance(content, basestring):
228
- return io.StringIO(content)
229
- else:
230
- return io.BytesIO(content)
196
+ if isinstance(content, str):
197
+ return io.StringIO(content)
231
198
  else:
232
199
  return io.BytesIO(content)
233
200
  else:
234
201
  return orig_open(name, *args, **kwargs)
235
202
 
236
203
  orig_open = open
237
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
238
- with mock.patch(patch_point, create=True, side_effect=open_mock) as m:
204
+ with mock.patch("builtins.open", create=True, side_effect=open_mock) as m:
239
205
  yield m
240
206
 
241
207
 
@@ -248,12 +214,10 @@ def mock_open_exception(for_path, exc):
248
214
  def open_mock(name, *args, **kwargs):
249
215
  if name == for_path:
250
216
  raise exc
251
- else:
252
- return orig_open(name, *args, **kwargs)
217
+ return orig_open(name, *args, **kwargs)
253
218
 
254
219
  orig_open = open
255
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
256
- with mock.patch(patch_point, create=True, side_effect=open_mock) as m:
220
+ with mock.patch("builtins.open", create=True, side_effect=open_mock) as m:
257
221
  yield m
258
222
 
259
223
 
@@ -302,7 +266,7 @@ class TestSystemVirtualMemoryAgainstFree(PsutilTestCase):
302
266
  psutil_value = psutil.virtual_memory().shared
303
267
  assert (
304
268
  abs(free_value - psutil_value) < TOLERANCE_SYS_MEM
305
- ), '%s %s \n%s' % (free_value, psutil_value, free.output)
269
+ ), f"{free_value} {psutil_value} \n{free.output}"
306
270
 
307
271
  @retry_on_failure()
308
272
  def test_available(self):
@@ -312,12 +276,9 @@ class TestSystemVirtualMemoryAgainstFree(PsutilTestCase):
312
276
  lines = out.split('\n')
313
277
  if 'available' not in lines[0]:
314
278
  raise pytest.skip("free does not support 'available' column")
315
- else:
316
- free_value = int(lines[1].split()[-1])
317
- psutil_value = psutil.virtual_memory().available
318
- assert (
319
- abs(free_value - psutil_value) < TOLERANCE_SYS_MEM
320
- ), '%s %s \n%s' % (free_value, psutil_value, out)
279
+ free_value = int(lines[1].split()[-1])
280
+ psutil_value = psutil.virtual_memory().available
281
+ assert abs(free_value - psutil_value) < TOLERANCE_SYS_MEM
321
282
 
322
283
 
323
284
  @pytest.mark.skipif(not LINUX, reason="LINUX only")
@@ -495,10 +456,7 @@ class TestSystemVirtualMemoryMocks(PsutilTestCase):
495
456
  SReclaimable: 346648 kB
496
457
  """).encode()
497
458
  with mock_open_content({"/proc/meminfo": content}):
498
- with mock_open_exception(
499
- "/proc/zoneinfo",
500
- IOError(errno.ENOENT, 'no such file or directory'),
501
- ):
459
+ with mock_open_exception("/proc/zoneinfo", FileNotFoundError):
502
460
  with warnings.catch_warnings(record=True) as ws:
503
461
  ret = psutil.virtual_memory()
504
462
  assert ret.available == 2057400 * 1024 + 4818144 * 1024
@@ -623,9 +581,7 @@ class TestSystemSwapMemory(PsutilTestCase):
623
581
 
624
582
  def test_no_vmstat_mocked(self):
625
583
  # see https://github.com/giampaolo/psutil/issues/722
626
- with mock_open_exception(
627
- "/proc/vmstat", IOError(errno.ENOENT, 'no such file or directory')
628
- ) as m:
584
+ with mock_open_exception("/proc/vmstat", FileNotFoundError) as m:
629
585
  with warnings.catch_warnings(record=True) as ws:
630
586
  warnings.simplefilter("always")
631
587
  ret = psutil.swap_memory()
@@ -714,14 +670,14 @@ class TestSystemCPUCountLogical(PsutilTestCase):
714
670
  assert psutil.cpu_count() == count
715
671
 
716
672
  @pytest.mark.skipif(
717
- not which("nproc"), reason="nproc utility not available"
673
+ not shutil.which("nproc"), reason="nproc utility not available"
718
674
  )
719
675
  def test_against_nproc(self):
720
676
  num = int(sh("nproc --all"))
721
677
  assert psutil.cpu_count(logical=True) == num
722
678
 
723
679
  @pytest.mark.skipif(
724
- not which("lscpu"), reason="lscpu utility not available"
680
+ not shutil.which("lscpu"), reason="lscpu utility not available"
725
681
  )
726
682
  def test_against_lscpu(self):
727
683
  out = sh("lscpu -p")
@@ -768,7 +724,7 @@ class TestSystemCPUCountLogical(PsutilTestCase):
768
724
  @pytest.mark.skipif(not LINUX, reason="LINUX only")
769
725
  class TestSystemCPUCountCores(PsutilTestCase):
770
726
  @pytest.mark.skipif(
771
- not which("lscpu"), reason="lscpu utility not available"
727
+ not shutil.which("lscpu"), reason="lscpu utility not available"
772
728
  )
773
729
  def test_against_lscpu(self):
774
730
  out = sh("lscpu -p")
@@ -779,6 +735,9 @@ class TestSystemCPUCountCores(PsutilTestCase):
779
735
  core_ids.add(fields[1])
780
736
  assert psutil.cpu_count(logical=False) == len(core_ids)
781
737
 
738
+ @pytest.mark.skipif(
739
+ platform.machine() not in {"x86_64", "i686"}, reason="x86_64/i686 only"
740
+ )
782
741
  def test_method_2(self):
783
742
  meth_1 = psutil._pslinux.cpu_count_cores()
784
743
  with mock.patch('glob.glob', return_value=[]) as m:
@@ -798,6 +757,9 @@ class TestSystemCPUCountCores(PsutilTestCase):
798
757
  @pytest.mark.skipif(not LINUX, reason="LINUX only")
799
758
  class TestSystemCPUFrequency(PsutilTestCase):
800
759
  @pytest.mark.skipif(not HAS_CPU_FREQ, reason="not supported")
760
+ @pytest.mark.skipif(
761
+ AARCH64, reason="aarch64 does not always expose frequency"
762
+ )
801
763
  def test_emulate_use_second_file(self):
802
764
  # https://github.com/giampaolo/psutil/issues/981
803
765
  def path_exists_mock(path):
@@ -861,8 +823,7 @@ class TestSystemCPUFrequency(PsutilTestCase):
861
823
  return orig_open(name, *args, **kwargs)
862
824
 
863
825
  orig_open = open
864
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
865
- with mock.patch(patch_point, side_effect=open_mock):
826
+ with mock.patch("builtins.open", side_effect=open_mock):
866
827
  with mock.patch('os.path.exists', return_value=True):
867
828
  freq = psutil.cpu_freq()
868
829
  assert freq.current == 500.0
@@ -907,8 +868,7 @@ class TestSystemCPUFrequency(PsutilTestCase):
907
868
  return orig_open(name, *args, **kwargs)
908
869
 
909
870
  orig_open = open
910
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
911
- with mock.patch(patch_point, side_effect=open_mock):
871
+ with mock.patch("builtins.open", side_effect=open_mock):
912
872
  with mock.patch('os.path.exists', return_value=True):
913
873
  with mock.patch(
914
874
  'psutil._pslinux.cpu_count_logical', return_value=2
@@ -930,8 +890,8 @@ class TestSystemCPUFrequency(PsutilTestCase):
930
890
  # See: https://github.com/giampaolo/psutil/issues/1071
931
891
  def open_mock(name, *args, **kwargs):
932
892
  if name.endswith('/scaling_cur_freq'):
933
- raise IOError(errno.ENOENT, "")
934
- elif name.endswith('/cpuinfo_cur_freq'):
893
+ raise FileNotFoundError
894
+ if name.endswith('/cpuinfo_cur_freq'):
935
895
  return io.BytesIO(b"200000")
936
896
  elif name == '/proc/cpuinfo':
937
897
  return io.BytesIO(b"cpu MHz : 200")
@@ -939,8 +899,7 @@ class TestSystemCPUFrequency(PsutilTestCase):
939
899
  return orig_open(name, *args, **kwargs)
940
900
 
941
901
  orig_open = open
942
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
943
- with mock.patch(patch_point, side_effect=open_mock):
902
+ with mock.patch("builtins.open", side_effect=open_mock):
944
903
  with mock.patch('os.path.exists', return_value=True):
945
904
  with mock.patch(
946
905
  'psutil._pslinux.cpu_count_logical', return_value=1
@@ -1007,7 +966,8 @@ class TestSystemNetIfAddrs(PsutilTestCase):
1007
966
  assert address in get_ipv6_addresses(name)
1008
967
 
1009
968
  # XXX - not reliable when having virtual NICs installed by Docker.
1010
- # @pytest.mark.skipif(not which('ip'), reason="'ip' utility not available")
969
+ # @pytest.mark.skipif(not shutil.which("ip"),
970
+ # reason="'ip' utility not available")
1011
971
  # def test_net_if_names(self):
1012
972
  # out = sh("ip addr").strip()
1013
973
  # nics = [x for x in psutil.net_if_addrs().keys() if ':' not in x]
@@ -1018,20 +978,19 @@ class TestSystemNetIfAddrs(PsutilTestCase):
1018
978
  # found += 1
1019
979
  # name = line.split(':')[1].strip()
1020
980
  # self.assertIn(name, nics)
1021
- # self.assertEqual(len(nics), found, msg="%s\n---\n%s" % (
981
+ # self.assertEqual(len(nics), found, msg="{}\n---\n{}".format(
1022
982
  # pprint.pformat(nics), out))
1023
983
 
1024
984
 
1025
985
  @pytest.mark.skipif(not LINUX, reason="LINUX only")
1026
- @pytest.mark.skipif(QEMU_USER, reason="QEMU user not supported")
1027
986
  class TestSystemNetIfStats(PsutilTestCase):
1028
987
  @pytest.mark.skipif(
1029
- not which("ifconfig"), reason="ifconfig utility not available"
988
+ not shutil.which("ifconfig"), reason="ifconfig utility not available"
1030
989
  )
1031
990
  def test_against_ifconfig(self):
1032
991
  for name, stats in psutil.net_if_stats().items():
1033
992
  try:
1034
- out = sh("ifconfig %s" % name)
993
+ out = sh(f"ifconfig {name}")
1035
994
  except RuntimeError:
1036
995
  pass
1037
996
  else:
@@ -1042,11 +1001,11 @@ class TestSystemNetIfStats(PsutilTestCase):
1042
1001
 
1043
1002
  def test_mtu(self):
1044
1003
  for name, stats in psutil.net_if_stats().items():
1045
- with open("/sys/class/net/%s/mtu" % name) as f:
1004
+ with open(f"/sys/class/net/{name}/mtu") as f:
1046
1005
  assert stats.mtu == int(f.read().strip())
1047
1006
 
1048
1007
  @pytest.mark.skipif(
1049
- not which("ifconfig"), reason="ifconfig utility not available"
1008
+ not shutil.which("ifconfig"), reason="ifconfig utility not available"
1050
1009
  )
1051
1010
  def test_flags(self):
1052
1011
  # first line looks like this:
@@ -1054,7 +1013,7 @@ class TestSystemNetIfStats(PsutilTestCase):
1054
1013
  matches_found = 0
1055
1014
  for name, stats in psutil.net_if_stats().items():
1056
1015
  try:
1057
- out = sh("ifconfig %s" % name)
1016
+ out = sh(f"ifconfig {name}")
1058
1017
  except RuntimeError:
1059
1018
  pass
1060
1019
  else:
@@ -1081,13 +1040,13 @@ class TestSystemNetIfStats(PsutilTestCase):
1081
1040
  @pytest.mark.skipif(not LINUX, reason="LINUX only")
1082
1041
  class TestSystemNetIOCounters(PsutilTestCase):
1083
1042
  @pytest.mark.skipif(
1084
- not which("ifconfig"), reason="ifconfig utility not available"
1043
+ not shutil.which("ifconfig"), reason="ifconfig utility not available"
1085
1044
  )
1086
1045
  @retry_on_failure()
1087
1046
  def test_against_ifconfig(self):
1088
1047
  def ifconfig(nic):
1089
1048
  ret = {}
1090
- out = sh("ifconfig %s" % nic)
1049
+ out = sh(f"ifconfig {nic}")
1091
1050
  ret['packets_recv'] = int(
1092
1051
  re.findall(r'RX packets[: ](\d+)', out)[0]
1093
1052
  )
@@ -1140,7 +1099,7 @@ class TestSystemNetConnections(PsutilTestCase):
1140
1099
  s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
1141
1100
  self.addCleanup(s.close)
1142
1101
  s.bind(("::1", 0))
1143
- except socket.error:
1102
+ except OSError:
1144
1103
  pass
1145
1104
  psutil.net_connections(kind='inet6')
1146
1105
 
@@ -1171,7 +1130,7 @@ class TestSystemDiskPartitions(PsutilTestCase):
1171
1130
  # test psutil.disk_usage() and psutil.disk_partitions()
1172
1131
  # against "df -a"
1173
1132
  def df(path):
1174
- out = sh('df -P -B 1 "%s"' % path).strip()
1133
+ out = sh(f'df -P -B 1 "{path}"').strip()
1175
1134
  lines = out.split('\n')
1176
1135
  lines.pop(0)
1177
1136
  line = lines.pop(0)
@@ -1198,7 +1157,7 @@ class TestSystemDiskPartitions(PsutilTestCase):
1198
1157
  return
1199
1158
 
1200
1159
  # No ZFS partitions on this system. Let's fake one.
1201
- fake_file = io.StringIO(u"nodev\tzfs\n")
1160
+ fake_file = io.StringIO("nodev\tzfs\n")
1202
1161
  with mock.patch(
1203
1162
  'psutil._common.open', return_value=fake_file, create=True
1204
1163
  ) as m1:
@@ -1375,9 +1334,7 @@ class TestRootFsDeviceFinder(PsutilTestCase):
1375
1334
  else:
1376
1335
  with pytest.raises(FileNotFoundError):
1377
1336
  finder.ask_proc_partitions()
1378
- if os.path.exists(
1379
- "/sys/dev/block/%s:%s/uevent" % (self.major, self.minor)
1380
- ):
1337
+ if os.path.exists(f"/sys/dev/block/{self.major}:{self.minor}/uevent"):
1381
1338
  finder.ask_sys_dev_block()
1382
1339
  else:
1383
1340
  with pytest.raises(FileNotFoundError):
@@ -1392,9 +1349,7 @@ class TestRootFsDeviceFinder(PsutilTestCase):
1392
1349
  a = b = c = None
1393
1350
  if os.path.exists("/proc/partitions"):
1394
1351
  a = finder.ask_proc_partitions()
1395
- if os.path.exists(
1396
- "/sys/dev/block/%s:%s/uevent" % (self.major, self.minor)
1397
- ):
1352
+ if os.path.exists(f"/sys/dev/block/{self.major}:{self.minor}/uevent"):
1398
1353
  b = finder.ask_sys_class_block()
1399
1354
  c = finder.ask_sys_dev_block()
1400
1355
 
@@ -1407,7 +1362,7 @@ class TestRootFsDeviceFinder(PsutilTestCase):
1407
1362
  assert base == c
1408
1363
 
1409
1364
  @pytest.mark.skipif(
1410
- not which("findmnt"), reason="findmnt utility not available"
1365
+ not shutil.which("findmnt"), reason="findmnt utility not available"
1411
1366
  )
1412
1367
  @pytest.mark.skipif(GITHUB_ACTIONS, reason="unsupported on GITHUB_ACTIONS")
1413
1368
  def test_against_findmnt(self):
@@ -1455,24 +1410,23 @@ class TestMisc(PsutilTestCase):
1455
1410
 
1456
1411
  def open_mock(name, *args, **kwargs):
1457
1412
  if name.startswith('/proc'):
1458
- raise IOError(errno.ENOENT, 'rejecting access for test')
1413
+ raise FileNotFoundError
1459
1414
  return orig_open(name, *args, **kwargs)
1460
1415
 
1461
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
1462
- with mock.patch(patch_point, side_effect=open_mock):
1416
+ with mock.patch("builtins.open", side_effect=open_mock):
1463
1417
  reload_module(psutil)
1464
1418
 
1465
- with pytest.raises(IOError):
1419
+ with pytest.raises(OSError):
1466
1420
  psutil.cpu_times()
1467
- with pytest.raises(IOError):
1421
+ with pytest.raises(OSError):
1468
1422
  psutil.cpu_times(percpu=True)
1469
- with pytest.raises(IOError):
1423
+ with pytest.raises(OSError):
1470
1424
  psutil.cpu_percent()
1471
- with pytest.raises(IOError):
1425
+ with pytest.raises(OSError):
1472
1426
  psutil.cpu_percent(percpu=True)
1473
- with pytest.raises(IOError):
1427
+ with pytest.raises(OSError):
1474
1428
  psutil.cpu_times_percent()
1475
- with pytest.raises(IOError):
1429
+ with pytest.raises(OSError):
1476
1430
  psutil.cpu_times_percent(percpu=True)
1477
1431
 
1478
1432
  psutil.PROCFS_PATH = my_procfs
@@ -1563,23 +1517,23 @@ class TestMisc(PsutilTestCase):
1563
1517
  os.mkdir(tdir)
1564
1518
  try:
1565
1519
  psutil.PROCFS_PATH = tdir
1566
- with pytest.raises(IOError):
1520
+ with pytest.raises(OSError):
1567
1521
  psutil.virtual_memory()
1568
- with pytest.raises(IOError):
1522
+ with pytest.raises(OSError):
1569
1523
  psutil.cpu_times()
1570
- with pytest.raises(IOError):
1524
+ with pytest.raises(OSError):
1571
1525
  psutil.cpu_times(percpu=True)
1572
- with pytest.raises(IOError):
1526
+ with pytest.raises(OSError):
1573
1527
  psutil.boot_time()
1574
- # self.assertRaises(IOError, psutil.pids)
1575
- with pytest.raises(IOError):
1528
+ # self.assertRaises(OSError, psutil.pids)
1529
+ with pytest.raises(OSError):
1576
1530
  psutil.net_connections()
1577
- with pytest.raises(IOError):
1531
+ with pytest.raises(OSError):
1578
1532
  psutil.net_io_counters()
1579
- with pytest.raises(IOError):
1533
+ with pytest.raises(OSError):
1580
1534
  psutil.net_if_stats()
1581
- # self.assertRaises(IOError, psutil.disk_io_counters)
1582
- with pytest.raises(IOError):
1535
+ # self.assertRaises(OSError, psutil.disk_io_counters)
1536
+ with pytest.raises(OSError):
1583
1537
  psutil.disk_partitions()
1584
1538
  with pytest.raises(psutil.NoSuchProcess):
1585
1539
  psutil.Process()
@@ -1597,7 +1551,7 @@ class TestMisc(PsutilTestCase):
1597
1551
  with ThreadTask():
1598
1552
  p = psutil.Process()
1599
1553
  threads = p.threads()
1600
- assert len(threads) == (3 if QEMU_USER else 2)
1554
+ assert len(threads) == 2
1601
1555
  tid = sorted(threads, key=lambda x: x.id)[1].id
1602
1556
  assert p.pid != tid
1603
1557
  pt = psutil.Process(tid)
@@ -1621,7 +1575,9 @@ class TestMisc(PsutilTestCase):
1621
1575
  @pytest.mark.skipif(not LINUX, reason="LINUX only")
1622
1576
  @pytest.mark.skipif(not HAS_BATTERY, reason="no battery")
1623
1577
  class TestSensorsBattery(PsutilTestCase):
1624
- @pytest.mark.skipif(not which("acpi"), reason="acpi utility not available")
1578
+ @pytest.mark.skipif(
1579
+ not shutil.which("acpi"), reason="acpi utility not available"
1580
+ )
1625
1581
  def test_percent(self):
1626
1582
  out = sh("acpi -b")
1627
1583
  acpi_value = int(out.split(",")[1].strip().replace('%', ''))
@@ -1637,8 +1593,7 @@ class TestSensorsBattery(PsutilTestCase):
1637
1593
  return orig_open(name, *args, **kwargs)
1638
1594
 
1639
1595
  orig_open = open
1640
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
1641
- with mock.patch(patch_point, side_effect=open_mock) as m:
1596
+ with mock.patch("builtins.open", side_effect=open_mock) as m:
1642
1597
  assert psutil.sensors_battery().power_plugged is True
1643
1598
  assert (
1644
1599
  psutil.sensors_battery().secsleft
@@ -1651,15 +1606,14 @@ class TestSensorsBattery(PsutilTestCase):
1651
1606
  # case code relies on /status file.
1652
1607
  def open_mock(name, *args, **kwargs):
1653
1608
  if name.endswith(('AC0/online', 'AC/online')):
1654
- raise IOError(errno.ENOENT, "")
1655
- elif name.endswith("/status"):
1656
- return io.StringIO(u"charging")
1609
+ raise FileNotFoundError
1610
+ if name.endswith("/status"):
1611
+ return io.StringIO("charging")
1657
1612
  else:
1658
1613
  return orig_open(name, *args, **kwargs)
1659
1614
 
1660
1615
  orig_open = open
1661
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
1662
- with mock.patch(patch_point, side_effect=open_mock) as m:
1616
+ with mock.patch("builtins.open", side_effect=open_mock) as m:
1663
1617
  assert psutil.sensors_battery().power_plugged is True
1664
1618
  assert m.called
1665
1619
 
@@ -1672,8 +1626,7 @@ class TestSensorsBattery(PsutilTestCase):
1672
1626
  return orig_open(name, *args, **kwargs)
1673
1627
 
1674
1628
  orig_open = open
1675
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
1676
- with mock.patch(patch_point, side_effect=open_mock) as m:
1629
+ with mock.patch("builtins.open", side_effect=open_mock) as m:
1677
1630
  assert psutil.sensors_battery().power_plugged is False
1678
1631
  assert m.called
1679
1632
 
@@ -1682,15 +1635,14 @@ class TestSensorsBattery(PsutilTestCase):
1682
1635
  # case code relies on /status file.
1683
1636
  def open_mock(name, *args, **kwargs):
1684
1637
  if name.endswith(('AC0/online', 'AC/online')):
1685
- raise IOError(errno.ENOENT, "")
1686
- elif name.endswith("/status"):
1687
- return io.StringIO(u"discharging")
1638
+ raise FileNotFoundError
1639
+ if name.endswith("/status"):
1640
+ return io.StringIO("discharging")
1688
1641
  else:
1689
1642
  return orig_open(name, *args, **kwargs)
1690
1643
 
1691
1644
  orig_open = open
1692
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
1693
- with mock.patch(patch_point, side_effect=open_mock) as m:
1645
+ with mock.patch("builtins.open", side_effect=open_mock) as m:
1694
1646
  assert psutil.sensors_battery().power_plugged is False
1695
1647
  assert m.called
1696
1648
 
@@ -1702,15 +1654,14 @@ class TestSensorsBattery(PsutilTestCase):
1702
1654
  '/sys/class/power_supply/AC0/online',
1703
1655
  '/sys/class/power_supply/AC/online',
1704
1656
  )):
1705
- raise IOError(errno.ENOENT, "")
1706
- elif name.startswith("/sys/class/power_supply/BAT0/status"):
1657
+ raise FileNotFoundError
1658
+ if name.startswith("/sys/class/power_supply/BAT0/status"):
1707
1659
  return io.BytesIO(b"???")
1708
1660
  else:
1709
1661
  return orig_open(name, *args, **kwargs)
1710
1662
 
1711
1663
  orig_open = open
1712
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
1713
- with mock.patch(patch_point, side_effect=open_mock) as m:
1664
+ with mock.patch("builtins.open", side_effect=open_mock) as m:
1714
1665
  assert psutil.sensors_battery().power_plugged is None
1715
1666
  assert m.called
1716
1667
 
@@ -1727,11 +1678,11 @@ class TestSensorsBattery(PsutilTestCase):
1727
1678
  # Expected fallback on /capacity.
1728
1679
  with mock_open_exception(
1729
1680
  "/sys/class/power_supply/BAT0/energy_full",
1730
- IOError(errno.ENOENT, ""),
1681
+ FileNotFoundError,
1731
1682
  ):
1732
1683
  with mock_open_exception(
1733
1684
  "/sys/class/power_supply/BAT0/charge_full",
1734
- IOError(errno.ENOENT, ""),
1685
+ FileNotFoundError,
1735
1686
  ):
1736
1687
  with mock_open_content(
1737
1688
  {"/sys/class/power_supply/BAT0/capacity": b"88"}
@@ -1741,14 +1692,14 @@ class TestSensorsBattery(PsutilTestCase):
1741
1692
  def test_emulate_no_power(self):
1742
1693
  # Emulate a case where /AC0/online file nor /BAT0/status exist.
1743
1694
  with mock_open_exception(
1744
- "/sys/class/power_supply/AC/online", IOError(errno.ENOENT, "")
1695
+ "/sys/class/power_supply/AC/online", FileNotFoundError
1745
1696
  ):
1746
1697
  with mock_open_exception(
1747
- "/sys/class/power_supply/AC0/online", IOError(errno.ENOENT, "")
1698
+ "/sys/class/power_supply/AC0/online", FileNotFoundError
1748
1699
  ):
1749
1700
  with mock_open_exception(
1750
1701
  "/sys/class/power_supply/BAT0/status",
1751
- IOError(errno.ENOENT, ""),
1702
+ FileNotFoundError,
1752
1703
  ):
1753
1704
  assert psutil.sensors_battery().power_plugged is None
1754
1705
 
@@ -1758,18 +1709,17 @@ class TestSensorsBatteryEmulated(PsutilTestCase):
1758
1709
  def test_it(self):
1759
1710
  def open_mock(name, *args, **kwargs):
1760
1711
  if name.endswith("/energy_now"):
1761
- return io.StringIO(u"60000000")
1712
+ return io.StringIO("60000000")
1762
1713
  elif name.endswith("/power_now"):
1763
- return io.StringIO(u"0")
1714
+ return io.StringIO("0")
1764
1715
  elif name.endswith("/energy_full"):
1765
- return io.StringIO(u"60000001")
1716
+ return io.StringIO("60000001")
1766
1717
  else:
1767
1718
  return orig_open(name, *args, **kwargs)
1768
1719
 
1769
1720
  orig_open = open
1770
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
1771
1721
  with mock.patch('os.listdir', return_value=["BAT0"]) as mlistdir:
1772
- with mock.patch(patch_point, side_effect=open_mock) as mopen:
1722
+ with mock.patch("builtins.open", side_effect=open_mock) as mopen:
1773
1723
  assert psutil.sensors_battery() is not None
1774
1724
  assert mlistdir.called
1775
1725
  assert mopen.called
@@ -1780,9 +1730,9 @@ class TestSensorsTemperatures(PsutilTestCase):
1780
1730
  def test_emulate_class_hwmon(self):
1781
1731
  def open_mock(name, *args, **kwargs):
1782
1732
  if name.endswith('/name'):
1783
- return io.StringIO(u"name")
1733
+ return io.StringIO("name")
1784
1734
  elif name.endswith('/temp1_label'):
1785
- return io.StringIO(u"label")
1735
+ return io.StringIO("label")
1786
1736
  elif name.endswith('/temp1_input'):
1787
1737
  return io.BytesIO(b"30000")
1788
1738
  elif name.endswith('/temp1_max'):
@@ -1793,8 +1743,7 @@ class TestSensorsTemperatures(PsutilTestCase):
1793
1743
  return orig_open(name, *args, **kwargs)
1794
1744
 
1795
1745
  orig_open = open
1796
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
1797
- with mock.patch(patch_point, side_effect=open_mock):
1746
+ with mock.patch("builtins.open", side_effect=open_mock):
1798
1747
  # Test case with /sys/class/hwmon
1799
1748
  with mock.patch(
1800
1749
  'glob.glob', return_value=['/sys/class/hwmon/hwmon0/temp1']
@@ -1812,16 +1761,17 @@ class TestSensorsTemperatures(PsutilTestCase):
1812
1761
  elif name.endswith('temp'):
1813
1762
  return io.BytesIO(b"30000")
1814
1763
  elif name.endswith('0_type'):
1815
- return io.StringIO(u"critical")
1764
+ return io.StringIO("critical")
1816
1765
  elif name.endswith('type'):
1817
- return io.StringIO(u"name")
1766
+ return io.StringIO("name")
1818
1767
  else:
1819
1768
  return orig_open(name, *args, **kwargs)
1820
1769
 
1821
1770
  def glob_mock(path):
1822
- if path == '/sys/class/hwmon/hwmon*/temp*_*': # noqa
1823
- return []
1824
- elif path == '/sys/class/hwmon/hwmon*/device/temp*_*':
1771
+ if path in {
1772
+ '/sys/class/hwmon/hwmon*/temp*_*',
1773
+ '/sys/class/hwmon/hwmon*/device/temp*_*',
1774
+ }:
1825
1775
  return []
1826
1776
  elif path == '/sys/class/thermal/thermal_zone*':
1827
1777
  return ['/sys/class/thermal/thermal_zone0']
@@ -1833,11 +1783,10 @@ class TestSensorsTemperatures(PsutilTestCase):
1833
1783
  return []
1834
1784
 
1835
1785
  orig_open = open
1836
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
1837
- with mock.patch(patch_point, side_effect=open_mock):
1786
+ with mock.patch("builtins.open", side_effect=open_mock):
1838
1787
  with mock.patch('glob.glob', create=True, side_effect=glob_mock):
1839
1788
  temp = psutil.sensors_temperatures()['name'][0]
1840
- assert temp.label == '' # noqa
1789
+ assert temp.label == ''
1841
1790
  assert temp.current == 30.0
1842
1791
  assert temp.high == 50.0
1843
1792
  assert temp.critical == 50.0
@@ -1848,17 +1797,16 @@ class TestSensorsFans(PsutilTestCase):
1848
1797
  def test_emulate_data(self):
1849
1798
  def open_mock(name, *args, **kwargs):
1850
1799
  if name.endswith('/name'):
1851
- return io.StringIO(u"name")
1800
+ return io.StringIO("name")
1852
1801
  elif name.endswith('/fan1_label'):
1853
- return io.StringIO(u"label")
1802
+ return io.StringIO("label")
1854
1803
  elif name.endswith('/fan1_input'):
1855
- return io.StringIO(u"2000")
1804
+ return io.StringIO("2000")
1856
1805
  else:
1857
1806
  return orig_open(name, *args, **kwargs)
1858
1807
 
1859
1808
  orig_open = open
1860
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
1861
- with mock.patch(patch_point, side_effect=open_mock):
1809
+ with mock.patch("builtins.open", side_effect=open_mock):
1862
1810
  with mock.patch(
1863
1811
  'glob.glob', return_value=['/sys/class/hwmon/hwmon2/fan1']
1864
1812
  ):
@@ -1880,11 +1828,11 @@ class TestProcess(PsutilTestCase):
1880
1828
  uss, pss, swap = psutil._pslinux.Process(sproc.pid)._parse_smaps()
1881
1829
  maps = psutil.Process(sproc.pid).memory_maps(grouped=False)
1882
1830
  assert (
1883
- abs(uss - sum([x.private_dirty + x.private_clean for x in maps]))
1831
+ abs(uss - sum(x.private_dirty + x.private_clean for x in maps))
1884
1832
  < 4096
1885
1833
  )
1886
- assert abs(pss - sum([x.pss for x in maps])) < 4096
1887
- assert abs(swap - sum([x.swap for x in maps])) < 4096
1834
+ assert abs(pss - sum(x.pss for x in maps)) < 4096
1835
+ assert abs(swap - sum(x.swap for x in maps)) < 4096
1888
1836
 
1889
1837
  def test_parse_smaps_mocked(self):
1890
1838
  # See: https://github.com/giampaolo/psutil/issues/1222
@@ -1911,7 +1859,7 @@ class TestProcess(PsutilTestCase):
1911
1859
  Locked: 19 kB
1912
1860
  VmFlags: rd ex
1913
1861
  """).encode()
1914
- with mock_open_content({"/proc/%s/smaps" % os.getpid(): content}) as m:
1862
+ with mock_open_content({f"/proc/{os.getpid()}/smaps": content}) as m:
1915
1863
  p = psutil._pslinux.Process(os.getpid())
1916
1864
  uss, pss, swap = p._parse_smaps()
1917
1865
  assert m.called
@@ -1946,14 +1894,13 @@ class TestProcess(PsutilTestCase):
1946
1894
  assert get_test_file(testfn).mode == "r+"
1947
1895
  with open(testfn, "a+"):
1948
1896
  assert get_test_file(testfn).mode == "a+"
1949
- # note: "x" bit is not supported
1950
- if PY3:
1951
- safe_rmpath(testfn)
1952
- with open(testfn, "x"):
1953
- assert get_test_file(testfn).mode == "w"
1954
- safe_rmpath(testfn)
1955
- with open(testfn, "x+"):
1956
- assert get_test_file(testfn).mode == "r+"
1897
+
1898
+ safe_rmpath(testfn)
1899
+ with open(testfn, "x"):
1900
+ assert get_test_file(testfn).mode == "w"
1901
+ safe_rmpath(testfn)
1902
+ with open(testfn, "x+"):
1903
+ assert get_test_file(testfn).mode == "r+"
1957
1904
 
1958
1905
  def test_open_files_file_gone(self):
1959
1906
  # simulates a file which gets deleted during open_files()
@@ -1965,7 +1912,7 @@ class TestProcess(PsutilTestCase):
1965
1912
  call_until(lambda: len(p.open_files()) != len(files))
1966
1913
  with mock.patch(
1967
1914
  'psutil._pslinux.os.readlink',
1968
- side_effect=OSError(errno.ENOENT, ""),
1915
+ side_effect=FileNotFoundError,
1969
1916
  ) as m:
1970
1917
  assert p.open_files() == []
1971
1918
  assert m.called
@@ -1987,9 +1934,8 @@ class TestProcess(PsutilTestCase):
1987
1934
  with open(self.get_testfn(), 'w'):
1988
1935
  # give the kernel some time to see the new file
1989
1936
  call_until(lambda: len(p.open_files()) != len(files))
1990
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
1991
1937
  with mock.patch(
1992
- patch_point, side_effect=IOError(errno.ENOENT, "")
1938
+ "builtins.open", side_effect=FileNotFoundError
1993
1939
  ) as m:
1994
1940
  assert p.open_files() == []
1995
1941
  assert m.called
@@ -2031,13 +1977,13 @@ class TestProcess(PsutilTestCase):
2031
1977
  def test_cmdline_mocked(self):
2032
1978
  # see: https://github.com/giampaolo/psutil/issues/639
2033
1979
  p = psutil.Process()
2034
- fake_file = io.StringIO(u'foo\x00bar\x00')
1980
+ fake_file = io.StringIO('foo\x00bar\x00')
2035
1981
  with mock.patch(
2036
1982
  'psutil._common.open', return_value=fake_file, create=True
2037
1983
  ) as m:
2038
1984
  assert p.cmdline() == ['foo', 'bar']
2039
1985
  assert m.called
2040
- fake_file = io.StringIO(u'foo\x00bar\x00\x00')
1986
+ fake_file = io.StringIO('foo\x00bar\x00\x00')
2041
1987
  with mock.patch(
2042
1988
  'psutil._common.open', return_value=fake_file, create=True
2043
1989
  ) as m:
@@ -2047,13 +1993,13 @@ class TestProcess(PsutilTestCase):
2047
1993
  def test_cmdline_spaces_mocked(self):
2048
1994
  # see: https://github.com/giampaolo/psutil/issues/1179
2049
1995
  p = psutil.Process()
2050
- fake_file = io.StringIO(u'foo bar ')
1996
+ fake_file = io.StringIO('foo bar ')
2051
1997
  with mock.patch(
2052
1998
  'psutil._common.open', return_value=fake_file, create=True
2053
1999
  ) as m:
2054
2000
  assert p.cmdline() == ['foo', 'bar']
2055
2001
  assert m.called
2056
- fake_file = io.StringIO(u'foo bar ')
2002
+ fake_file = io.StringIO('foo bar ')
2057
2003
  with mock.patch(
2058
2004
  'psutil._common.open', return_value=fake_file, create=True
2059
2005
  ) as m:
@@ -2064,7 +2010,7 @@ class TestProcess(PsutilTestCase):
2064
2010
  # https://github.com/giampaolo/psutil/issues/
2065
2011
  # 1179#issuecomment-552984549
2066
2012
  p = psutil.Process()
2067
- fake_file = io.StringIO(u'foo\x20bar\x00')
2013
+ fake_file = io.StringIO('foo\x20bar\x00')
2068
2014
  with mock.patch(
2069
2015
  'psutil._common.open', return_value=fake_file, create=True
2070
2016
  ) as m:
@@ -2084,14 +2030,12 @@ class TestProcess(PsutilTestCase):
2084
2030
  # condition). threads() is supposed to ignore that instead
2085
2031
  # of raising NSP.
2086
2032
  def open_mock_1(name, *args, **kwargs):
2087
- if name.startswith('/proc/%s/task' % os.getpid()):
2088
- raise IOError(errno.ENOENT, "")
2089
- else:
2090
- return orig_open(name, *args, **kwargs)
2033
+ if name.startswith(f"/proc/{os.getpid()}/task"):
2034
+ raise FileNotFoundError
2035
+ return orig_open(name, *args, **kwargs)
2091
2036
 
2092
2037
  orig_open = open
2093
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
2094
- with mock.patch(patch_point, side_effect=open_mock_1) as m:
2038
+ with mock.patch("builtins.open", side_effect=open_mock_1) as m:
2095
2039
  ret = psutil.Process().threads()
2096
2040
  assert m.called
2097
2041
  assert ret == []
@@ -2099,18 +2043,17 @@ class TestProcess(PsutilTestCase):
2099
2043
  # ...but if it bumps into something != ENOENT we want an
2100
2044
  # exception.
2101
2045
  def open_mock_2(name, *args, **kwargs):
2102
- if name.startswith('/proc/%s/task' % os.getpid()):
2103
- raise IOError(errno.EPERM, "")
2104
- else:
2105
- return orig_open(name, *args, **kwargs)
2046
+ if name.startswith(f"/proc/{os.getpid()}/task"):
2047
+ raise PermissionError
2048
+ return orig_open(name, *args, **kwargs)
2106
2049
 
2107
- with mock.patch(patch_point, side_effect=open_mock_2):
2050
+ with mock.patch("builtins.open", side_effect=open_mock_2):
2108
2051
  with pytest.raises(psutil.AccessDenied):
2109
2052
  psutil.Process().threads()
2110
2053
 
2111
2054
  def test_exe_mocked(self):
2112
2055
  with mock.patch(
2113
- 'psutil._pslinux.readlink', side_effect=OSError(errno.ENOENT, "")
2056
+ 'psutil._pslinux.readlink', side_effect=FileNotFoundError
2114
2057
  ) as m:
2115
2058
  # de-activate guessing from cmdline()
2116
2059
  with mock.patch(
@@ -2118,13 +2061,13 @@ class TestProcess(PsutilTestCase):
2118
2061
  ):
2119
2062
  ret = psutil.Process().exe()
2120
2063
  assert m.called
2121
- assert ret == "" # noqa
2064
+ assert ret == ""
2122
2065
 
2123
2066
  def test_issue_1014(self):
2124
2067
  # Emulates a case where smaps file does not exist. In this case
2125
2068
  # wrap_exception decorator should not raise NoSuchProcess.
2126
2069
  with mock_open_exception(
2127
- '/proc/%s/smaps' % os.getpid(), IOError(errno.ENOENT, "")
2070
+ f"/proc/{os.getpid()}/smaps", FileNotFoundError
2128
2071
  ) as m:
2129
2072
  p = psutil.Process()
2130
2073
  with pytest.raises(FileNotFoundError):
@@ -2134,7 +2077,7 @@ class TestProcess(PsutilTestCase):
2134
2077
  def test_issue_2418(self):
2135
2078
  p = psutil.Process()
2136
2079
  with mock_open_exception(
2137
- '/proc/%s/statm' % os.getpid(), FileNotFoundError
2080
+ f"/proc/{os.getpid()}/statm", FileNotFoundError
2138
2081
  ):
2139
2082
  with mock.patch("os.path.exists", return_value=False):
2140
2083
  with pytest.raises(psutil.NoSuchProcess):
@@ -2146,7 +2089,7 @@ class TestProcess(PsutilTestCase):
2146
2089
  # happen in case of zombie process:
2147
2090
  # https://travis-ci.org/giampaolo/psutil/jobs/51368273
2148
2091
  with mock.patch(
2149
- "psutil._pslinux.prlimit", side_effect=OSError(errno.ENOSYS, "")
2092
+ "resource.prlimit", side_effect=OSError(errno.ENOSYS, "")
2150
2093
  ) as m1:
2151
2094
  with mock.patch(
2152
2095
  "psutil._pslinux.Process._is_zombie", return_value=True
@@ -2206,7 +2149,7 @@ class TestProcess(PsutilTestCase):
2206
2149
  "7", # delayacct_blkio_ticks
2207
2150
  ]
2208
2151
  content = " ".join(args).encode()
2209
- with mock_open_content({"/proc/%s/stat" % os.getpid(): content}):
2152
+ with mock_open_content({f"/proc/{os.getpid()}/stat": content}):
2210
2153
  p = psutil.Process()
2211
2154
  assert p.name() == 'cat'
2212
2155
  assert p.status() == psutil.STATUS_ZOMBIE
@@ -2229,7 +2172,7 @@ class TestProcess(PsutilTestCase):
2229
2172
  Cpus_allowed_list:\t0-7
2230
2173
  voluntary_ctxt_switches:\t12
2231
2174
  nonvoluntary_ctxt_switches:\t13""").encode()
2232
- with mock_open_content({"/proc/%s/status" % os.getpid(): content}):
2175
+ with mock_open_content({f"/proc/{os.getpid()}/status": content}):
2233
2176
  p = psutil.Process()
2234
2177
  assert p.num_ctx_switches().voluntary == 12
2235
2178
  assert p.num_ctx_switches().involuntary == 13
@@ -2273,7 +2216,7 @@ class TestProcessAgainstStatus(PsutilTestCase):
2273
2216
 
2274
2217
  def read_status_file(self, linestart):
2275
2218
  with psutil._psplatform.open_text(
2276
- '/proc/%s/status' % self.proc.pid
2219
+ f"/proc/{self.proc.pid}/status"
2277
2220
  ) as f:
2278
2221
  for line in f:
2279
2222
  line = line.strip()
@@ -2283,13 +2226,12 @@ class TestProcessAgainstStatus(PsutilTestCase):
2283
2226
  return int(value)
2284
2227
  except ValueError:
2285
2228
  return value
2286
- raise ValueError("can't find %r" % linestart)
2229
+ raise ValueError(f"can't find {linestart!r}")
2287
2230
 
2288
2231
  def test_name(self):
2289
2232
  value = self.read_status_file("Name:")
2290
2233
  assert self.proc.name() == value
2291
2234
 
2292
- @pytest.mark.skipif(QEMU_USER, reason="QEMU user not supported")
2293
2235
  def test_status(self):
2294
2236
  value = self.read_status_file("State:")
2295
2237
  value = value[value.find('(') + 1 : value.rfind(')')]