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
@@ -27,13 +27,8 @@ from psutil import OPENBSD
27
27
  from psutil import OSX
28
28
  from psutil import POSIX
29
29
  from psutil import WINDOWS
30
- from psutil._compat import PY3
31
- from psutil._compat import FileNotFoundError
32
- from psutil._compat import long
33
- from psutil._compat import unicode
34
30
  from psutil.tests import CI_TESTING
35
31
  from psutil.tests import PYTEST_PARALLEL
36
- from psutil.tests import QEMU_USER
37
32
  from psutil.tests import VALID_PROC_STATUSES
38
33
  from psutil.tests import PsutilTestCase
39
34
  from psutil.tests import check_connection_ntuple
@@ -125,9 +120,7 @@ class TestFetchAllProcesses(PsutilTestCase):
125
120
  if USE_PROC_POOL:
126
121
  return self.pool.imap_unordered(proc_info, psutil.pids())
127
122
  else:
128
- ls = []
129
- for pid in psutil.pids():
130
- ls.append(proc_info(pid))
123
+ ls = [proc_info(pid) for pid in psutil.pids()]
131
124
  return ls
132
125
 
133
126
  def test_all(self):
@@ -139,14 +132,16 @@ class TestFetchAllProcesses(PsutilTestCase):
139
132
  meth(value, info)
140
133
  except Exception: # noqa: BLE001
141
134
  s = '\n' + '=' * 70 + '\n'
142
- s += "FAIL: name=test_%s, pid=%s, ret=%s\ninfo=%s\n" % (
143
- name,
144
- info['pid'],
145
- repr(value),
146
- info,
135
+ s += (
136
+ "FAIL: name=test_{}, pid={}, ret={}\ninfo={}\n".format(
137
+ name,
138
+ info['pid'],
139
+ repr(value),
140
+ info,
141
+ )
147
142
  )
148
143
  s += '-' * 70
149
- s += "\n%s" % traceback.format_exc()
144
+ s += f"\n{traceback.format_exc()}"
150
145
  s = "\n".join((" " * 4) + i for i in s.splitlines()) + "\n"
151
146
  failures.append(s)
152
147
  else:
@@ -161,7 +156,7 @@ class TestFetchAllProcesses(PsutilTestCase):
161
156
  assert isinstance(part, str)
162
157
 
163
158
  def exe(self, ret, info):
164
- assert isinstance(ret, (str, unicode))
159
+ assert isinstance(ret, str)
165
160
  assert ret.strip() == ret
166
161
  if ret:
167
162
  if WINDOWS and not ret.endswith('.exe'):
@@ -184,12 +179,12 @@ class TestFetchAllProcesses(PsutilTestCase):
184
179
  assert ret >= 0
185
180
 
186
181
  def ppid(self, ret, info):
187
- assert isinstance(ret, (int, long))
182
+ assert isinstance(ret, int)
188
183
  assert ret >= 0
189
184
  proc_info(ret)
190
185
 
191
186
  def name(self, ret, info):
192
- assert isinstance(ret, (str, unicode))
187
+ assert isinstance(ret, str)
193
188
  if WINDOWS and not ret and is_win_secure_system_proc(info['pid']):
194
189
  # https://github.com/giampaolo/psutil/issues/2338
195
190
  return
@@ -236,16 +231,13 @@ class TestFetchAllProcesses(PsutilTestCase):
236
231
  def status(self, ret, info):
237
232
  assert isinstance(ret, str)
238
233
  assert ret, ret
239
- if QEMU_USER:
240
- # status does not work under qemu user
241
- return
242
234
  assert ret != '?' # XXX
243
235
  assert ret in VALID_PROC_STATUSES
244
236
 
245
237
  def io_counters(self, ret, info):
246
238
  assert is_namedtuple(ret)
247
239
  for field in ret:
248
- assert isinstance(field, (int, long))
240
+ assert isinstance(field, int)
249
241
  if field != -1:
250
242
  assert field >= 0
251
243
 
@@ -306,7 +298,7 @@ class TestFetchAllProcesses(PsutilTestCase):
306
298
  def memory_info(self, ret, info):
307
299
  assert is_namedtuple(ret)
308
300
  for value in ret:
309
- assert isinstance(value, (int, long))
301
+ assert isinstance(value, int)
310
302
  assert value >= 0
311
303
  if WINDOWS:
312
304
  assert ret.peak_wset >= ret.wset
@@ -319,7 +311,7 @@ class TestFetchAllProcesses(PsutilTestCase):
319
311
  total = psutil.virtual_memory().total
320
312
  for name in ret._fields:
321
313
  value = getattr(ret, name)
322
- assert isinstance(value, (int, long))
314
+ assert isinstance(value, int)
323
315
  assert value >= 0
324
316
  if LINUX or (OSX and name in {'vms', 'data'}):
325
317
  # On Linux there are processes (e.g. 'goa-daemon') whose
@@ -368,7 +360,7 @@ class TestFetchAllProcesses(PsutilTestCase):
368
360
  check_connection_ntuple(conn)
369
361
 
370
362
  def cwd(self, ret, info):
371
- assert isinstance(ret, (str, unicode))
363
+ assert isinstance(ret, str)
372
364
  assert ret.strip() == ret
373
365
  if ret:
374
366
  assert os.path.isabs(ret), ret
@@ -412,18 +404,21 @@ class TestFetchAllProcesses(PsutilTestCase):
412
404
  for fname in nt._fields:
413
405
  value = getattr(nt, fname)
414
406
  if fname == 'path':
415
- if not value.startswith(("[", "anon_inode:")):
416
- assert os.path.isabs(nt.path), nt.path
417
- # commented as on Linux we might get
418
- # '/foo/bar (deleted)'
419
- # assert os.path.exists(nt.path), nt.path
407
+ if value.startswith(("[", "anon_inode:")): # linux
408
+ continue
409
+ if BSD and value == "pvclock": # seen on FreeBSD
410
+ continue
411
+ assert os.path.isabs(nt.path), nt.path
412
+ # commented as on Linux we might get
413
+ # '/foo/bar (deleted)'
414
+ # assert os.path.exists(nt.path), nt.path
420
415
  elif fname == 'addr':
421
416
  assert value, repr(value)
422
417
  elif fname == 'perms':
423
418
  if not WINDOWS:
424
419
  assert value, repr(value)
425
420
  else:
426
- assert isinstance(value, (int, long))
421
+ assert isinstance(value, int)
427
422
  assert value >= 0
428
423
 
429
424
  def num_handles(self, ret, info):
@@ -441,15 +436,12 @@ class TestFetchAllProcesses(PsutilTestCase):
441
436
  if x.endswith('_PRIORITY_CLASS')
442
437
  ]
443
438
  assert ret in priorities
444
- if PY3:
445
- assert isinstance(ret, enum.IntEnum)
446
- else:
447
- assert isinstance(ret, int)
439
+ assert isinstance(ret, enum.IntEnum)
448
440
 
449
441
  def num_ctx_switches(self, ret, info):
450
442
  assert is_namedtuple(ret)
451
443
  for value in ret:
452
- assert isinstance(value, (int, long))
444
+ assert isinstance(value, int)
453
445
  assert value >= 0
454
446
 
455
447
  def rlimit(self, ret, info):
@@ -491,7 +483,7 @@ class TestPidsRange(PsutilTestCase):
491
483
  def test_it(self):
492
484
  def is_linux_tid(pid):
493
485
  try:
494
- f = open("/proc/%s/status" % pid, "rb")
486
+ f = open(f"/proc/{pid}/status", "rb") # noqa: SIM115
495
487
  except FileNotFoundError:
496
488
  return False
497
489
  else:
@@ -0,0 +1,240 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
4
+ # Use of this source code is governed by a BSD-style license that can be
5
+ # found in the LICENSE file.
6
+
7
+ """Test various scripts."""
8
+
9
+ import ast
10
+ import os
11
+ import shutil
12
+ import stat
13
+ import subprocess
14
+
15
+ import pytest
16
+
17
+ from psutil import POSIX
18
+ from psutil import WINDOWS
19
+ from psutil.tests import CI_TESTING
20
+ from psutil.tests import HAS_BATTERY
21
+ from psutil.tests import HAS_MEMORY_MAPS
22
+ from psutil.tests import HAS_SENSORS_BATTERY
23
+ from psutil.tests import HAS_SENSORS_FANS
24
+ from psutil.tests import HAS_SENSORS_TEMPERATURES
25
+ from psutil.tests import PYTHON_EXE
26
+ from psutil.tests import PYTHON_EXE_ENV
27
+ from psutil.tests import ROOT_DIR
28
+ from psutil.tests import SCRIPTS_DIR
29
+ from psutil.tests import PsutilTestCase
30
+ from psutil.tests import import_module_by_path
31
+ from psutil.tests import psutil
32
+ from psutil.tests import sh
33
+
34
+
35
+ INTERNAL_SCRIPTS_DIR = os.path.join(SCRIPTS_DIR, "internal")
36
+ SETUP_PY = os.path.join(ROOT_DIR, 'setup.py')
37
+
38
+
39
+ # ===================================================================
40
+ # --- Tests scripts in scripts/ directory
41
+ # ===================================================================
42
+
43
+
44
+ @pytest.mark.skipif(
45
+ CI_TESTING and not os.path.exists(SCRIPTS_DIR),
46
+ reason="can't find scripts/ directory",
47
+ )
48
+ class TestExampleScripts(PsutilTestCase):
49
+ @staticmethod
50
+ def assert_stdout(exe, *args, **kwargs):
51
+ kwargs.setdefault("env", PYTHON_EXE_ENV)
52
+ exe = os.path.join(SCRIPTS_DIR, exe)
53
+ cmd = [PYTHON_EXE, exe]
54
+ for arg in args:
55
+ cmd.append(arg)
56
+ try:
57
+ out = sh(cmd, **kwargs).strip()
58
+ except RuntimeError as err:
59
+ if 'AccessDenied' in str(err):
60
+ return str(err)
61
+ else:
62
+ raise
63
+ assert out, out
64
+ return out
65
+
66
+ @staticmethod
67
+ def assert_syntax(exe):
68
+ exe = os.path.join(SCRIPTS_DIR, exe)
69
+ with open(exe, encoding="utf8") as f:
70
+ src = f.read()
71
+ ast.parse(src)
72
+
73
+ def test_coverage(self):
74
+ # make sure all example scripts have a test method defined
75
+ meths = dir(self)
76
+ for name in os.listdir(SCRIPTS_DIR):
77
+ if name.endswith('.py'):
78
+ if 'test_' + os.path.splitext(name)[0] not in meths:
79
+ # self.assert_stdout(name)
80
+ raise self.fail(
81
+ "no test defined for"
82
+ f" {os.path.join(SCRIPTS_DIR, name)!r} script"
83
+ )
84
+
85
+ @pytest.mark.skipif(not POSIX, reason="POSIX only")
86
+ def test_executable(self):
87
+ for root, dirs, files in os.walk(SCRIPTS_DIR):
88
+ for file in files:
89
+ if file.endswith('.py'):
90
+ path = os.path.join(root, file)
91
+ if not stat.S_IXUSR & os.stat(path)[stat.ST_MODE]:
92
+ raise self.fail(f"{path!r} is not executable")
93
+
94
+ def test_disk_usage(self):
95
+ self.assert_stdout('disk_usage.py')
96
+
97
+ def test_free(self):
98
+ self.assert_stdout('free.py')
99
+
100
+ def test_meminfo(self):
101
+ self.assert_stdout('meminfo.py')
102
+
103
+ def test_procinfo(self):
104
+ self.assert_stdout('procinfo.py', str(os.getpid()))
105
+
106
+ @pytest.mark.skipif(CI_TESTING and not psutil.users(), reason="no users")
107
+ def test_who(self):
108
+ self.assert_stdout('who.py')
109
+
110
+ def test_ps(self):
111
+ self.assert_stdout('ps.py')
112
+
113
+ def test_pstree(self):
114
+ self.assert_stdout('pstree.py')
115
+
116
+ def test_netstat(self):
117
+ self.assert_stdout('netstat.py')
118
+
119
+ def test_ifconfig(self):
120
+ self.assert_stdout('ifconfig.py')
121
+
122
+ @pytest.mark.skipif(not HAS_MEMORY_MAPS, reason="not supported")
123
+ def test_pmap(self):
124
+ self.assert_stdout('pmap.py', str(os.getpid()))
125
+
126
+ def test_procsmem(self):
127
+ if 'uss' not in psutil.Process().memory_full_info()._fields:
128
+ raise pytest.skip("not supported")
129
+ self.assert_stdout('procsmem.py')
130
+
131
+ def test_killall(self):
132
+ self.assert_syntax('killall.py')
133
+
134
+ def test_nettop(self):
135
+ self.assert_syntax('nettop.py')
136
+
137
+ def test_top(self):
138
+ self.assert_syntax('top.py')
139
+
140
+ def test_iotop(self):
141
+ self.assert_syntax('iotop.py')
142
+
143
+ def test_pidof(self):
144
+ output = self.assert_stdout('pidof.py', psutil.Process().name())
145
+ assert str(os.getpid()) in output
146
+
147
+ @pytest.mark.skipif(not WINDOWS, reason="WINDOWS only")
148
+ def test_winservices(self):
149
+ self.assert_stdout('winservices.py')
150
+
151
+ def test_cpu_distribution(self):
152
+ self.assert_syntax('cpu_distribution.py')
153
+
154
+ @pytest.mark.skipif(not HAS_SENSORS_TEMPERATURES, reason="not supported")
155
+ def test_temperatures(self):
156
+ if not psutil.sensors_temperatures():
157
+ raise pytest.skip("no temperatures")
158
+ self.assert_stdout('temperatures.py')
159
+
160
+ @pytest.mark.skipif(not HAS_SENSORS_FANS, reason="not supported")
161
+ def test_fans(self):
162
+ if not psutil.sensors_fans():
163
+ raise pytest.skip("no fans")
164
+ self.assert_stdout('fans.py')
165
+
166
+ @pytest.mark.skipif(not HAS_SENSORS_BATTERY, reason="not supported")
167
+ @pytest.mark.skipif(not HAS_BATTERY, reason="no battery")
168
+ def test_battery(self):
169
+ self.assert_stdout('battery.py')
170
+
171
+ @pytest.mark.skipif(not HAS_SENSORS_BATTERY, reason="not supported")
172
+ @pytest.mark.skipif(not HAS_BATTERY, reason="no battery")
173
+ def test_sensors(self):
174
+ self.assert_stdout('sensors.py')
175
+
176
+
177
+ # ===================================================================
178
+ # --- Tests scripts in scripts/internal/ directory
179
+ # ===================================================================
180
+
181
+
182
+ @pytest.mark.skipif(
183
+ CI_TESTING and not os.path.exists(INTERNAL_SCRIPTS_DIR),
184
+ reason="can't find scripts/internal/ directory",
185
+ )
186
+ class TestInternalScripts(PsutilTestCase):
187
+ @staticmethod
188
+ def ls():
189
+ for name in os.listdir(INTERNAL_SCRIPTS_DIR):
190
+ if name.endswith(".py"):
191
+ yield os.path.join(INTERNAL_SCRIPTS_DIR, name)
192
+
193
+ def test_syntax_all(self):
194
+ for path in self.ls():
195
+ with open(path, encoding="utf8") as f:
196
+ data = f.read()
197
+ ast.parse(data)
198
+
199
+ @pytest.mark.skipif(CI_TESTING, reason="not on CI")
200
+ def test_import_all(self):
201
+ for path in self.ls():
202
+ try:
203
+ import_module_by_path(path)
204
+ except SystemExit:
205
+ pass
206
+
207
+
208
+ # ===================================================================
209
+ # --- Tests for setup.py script
210
+ # ===================================================================
211
+
212
+
213
+ @pytest.mark.skipif(
214
+ CI_TESTING and not os.path.exists(SETUP_PY), reason="can't find setup.py"
215
+ )
216
+ class TestSetupScript(PsutilTestCase):
217
+ def test_invocation(self):
218
+ module = import_module_by_path(SETUP_PY)
219
+ with pytest.raises(SystemExit):
220
+ module.setup()
221
+ assert module.get_version() == psutil.__version__
222
+
223
+ @pytest.mark.skipif(
224
+ not shutil.which("python2.7"), reason="python2.7 not installed"
225
+ )
226
+ def test_python2(self):
227
+ # There's a duplicate of this test in scripts/internal
228
+ # directory, which is only executed by CI. We replicate it here
229
+ # to run it when developing locally.
230
+ p = subprocess.Popen(
231
+ [shutil.which("python2.7"), SETUP_PY],
232
+ stdout=subprocess.PIPE,
233
+ stderr=subprocess.PIPE,
234
+ universal_newlines=True,
235
+ )
236
+ stdout, stderr = p.communicate()
237
+ assert p.wait() == 1
238
+ assert not stdout
239
+ assert "psutil no longer supports Python 2.7" in stderr
240
+ assert "Latest version supporting Python 2.7 is" in stderr
@@ -18,7 +18,7 @@ from psutil.tests import sh
18
18
  @pytest.mark.skipif(not SUNOS, reason="SUNOS only")
19
19
  class SunOSSpecificTestCase(PsutilTestCase):
20
20
  def test_swap_memory(self):
21
- out = sh('env PATH=/usr/sbin:/sbin:%s swap -l' % os.environ['PATH'])
21
+ out = sh(f"env PATH=/usr/sbin:/sbin:{os.environ['PATH']} swap -l")
22
22
  lines = out.strip().split('\n')[1:]
23
23
  if not lines:
24
24
  raise ValueError('no swap device(s) configured')