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.
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/authorization_code.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azd_cli.py +20 -14
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_arc.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_cli.py +36 -14
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_powershell.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/chained.py +2 -2
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/default.py +4 -3
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/imds.py +2 -2
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/managed_identity.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/__init__.py +2 -0
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/auth_code_redirect_handler.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/decorators.py +15 -7
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/interactive.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/managed_identity_client.py +0 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/msal_client.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/msal_managed_identity_client.py +2 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/shared_token_cache.py +3 -3
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/utils.py +17 -2
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_version.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azd_cli.py +14 -11
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azure_cli.py +30 -12
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/default.py +2 -2
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/imds.py +3 -3
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/managed_identity.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_internal/decorators.py +15 -7
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_internal/managed_identity_client.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/cryptography/__about__.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/google/api/annotations_pb2.py +7 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/auth_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/backend_pb2.py +14 -7
- py2docfx/venv/venv1/Lib/site-packages/google/api/billing_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/client_pb2.py +47 -38
- py2docfx/venv/venv1/Lib/site-packages/google/api/config_change_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/consumer_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/context_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/control_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/distribution_pb2.py +7 -5
- py2docfx/venv/venv1/Lib/site-packages/google/api/documentation_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/endpoint_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/error_reason_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/field_behavior_pb2.py +8 -6
- py2docfx/venv/venv1/Lib/site-packages/google/api/field_info_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/http_pb2.py +7 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/httpbody_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/label_pb2.py +7 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/launch_stage_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/log_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/logging_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/metric_pb2.py +12 -9
- py2docfx/venv/venv1/Lib/site-packages/google/api/monitored_resource_pb2.py +15 -10
- py2docfx/venv/venv1/Lib/site-packages/google/api/monitoring_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/policy_pb2.py +7 -5
- py2docfx/venv/venv1/Lib/site-packages/google/api/quota_pb2.py +10 -7
- py2docfx/venv/venv1/Lib/site-packages/google/api/resource_pb2.py +7 -5
- py2docfx/venv/venv1/Lib/site-packages/google/api/routing_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/service_pb2.py +15 -12
- py2docfx/venv/venv1/Lib/site-packages/google/api/source_info_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/system_parameter_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/usage_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/visibility_pb2.py +7 -5
- py2docfx/venv/venv1/Lib/site-packages/google/cloud/extended_operations_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/cloud/location/locations_pb2.py +18 -13
- py2docfx/venv/venv1/Lib/site-packages/google/gapic/metadata/gapic_metadata_pb2.py +31 -26
- py2docfx/venv/venv1/Lib/site-packages/google/logging/type/http_request_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/logging/type/log_severity_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_grpc.py +2 -1
- py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_grpc_pb2.py +11 -10
- py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_pb2.py +20 -17
- py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_pb2_grpc.py +1 -2
- py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_proto.py +2 -1
- py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_proto_pb2.py +22 -19
- py2docfx/venv/venv1/Lib/site-packages/google/rpc/code_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/rpc/context/attribute_context_pb2.py +20 -16
- py2docfx/venv/venv1/Lib/site-packages/google/rpc/context/audit_context_pb2.py +7 -5
- py2docfx/venv/venv1/Lib/site-packages/google/rpc/error_details_pb2.py +21 -19
- py2docfx/venv/venv1/Lib/site-packages/google/rpc/http_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/rpc/status_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/type/calendar_period_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/color_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/type/date_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/datetime_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/type/dayofweek_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/decimal_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/expr_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/fraction_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/interval_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/type/latlng_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/localized_text_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/money_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/month_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/phone_number_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/postal_address_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/quaternion_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/timeofday_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/psutil/__init__.py +122 -201
- py2docfx/venv/venv1/Lib/site-packages/psutil/_common.py +84 -128
- py2docfx/venv/venv1/Lib/site-packages/psutil/_psaix.py +24 -38
- py2docfx/venv/venv1/Lib/site-packages/psutil/_psbsd.py +44 -58
- py2docfx/venv/venv1/Lib/site-packages/psutil/_pslinux.py +170 -254
- py2docfx/venv/venv1/Lib/site-packages/psutil/_psosx.py +8 -16
- py2docfx/venv/venv1/Lib/site-packages/psutil/_psposix.py +13 -49
- py2docfx/venv/venv1/Lib/site-packages/psutil/_pssunos.py +41 -60
- py2docfx/venv/venv1/Lib/site-packages/psutil/_pswindows.py +75 -145
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/__init__.py +105 -193
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_aix.py +2 -2
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_bsd.py +27 -26
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_connections.py +16 -17
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_contracts.py +5 -19
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_linux.py +153 -211
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_memleaks.py +0 -6
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_misc.py +22 -207
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_osx.py +9 -4
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_posix.py +8 -15
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_process.py +104 -184
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_process_all.py +28 -36
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_scripts.py +240 -0
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_sunos.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_system.py +44 -50
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_testutils.py +23 -33
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_unicode.py +8 -67
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_windows.py +32 -52
- {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1996319.dist-info}/METADATA +1 -1
- {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1996319.dist-info}/RECORD +125 -125
- py2docfx/venv/venv1/Lib/site-packages/psutil/_compat.py +0 -477
- {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1996319.dist-info}/WHEEL +0 -0
- {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1996319.dist-info}/top_level.txt +0 -0
@@ -7,8 +7,10 @@
|
|
7
7
|
"""Tests for psutil.Process class."""
|
8
8
|
|
9
9
|
import collections
|
10
|
+
import contextlib
|
10
11
|
import errno
|
11
12
|
import getpass
|
13
|
+
import io
|
12
14
|
import itertools
|
13
15
|
import os
|
14
16
|
import signal
|
@@ -19,7 +21,7 @@ import subprocess
|
|
19
21
|
import sys
|
20
22
|
import textwrap
|
21
23
|
import time
|
22
|
-
import
|
24
|
+
from unittest import mock
|
23
25
|
|
24
26
|
import psutil
|
25
27
|
from psutil import AIX
|
@@ -32,12 +34,6 @@ from psutil import OSX
|
|
32
34
|
from psutil import POSIX
|
33
35
|
from psutil import WINDOWS
|
34
36
|
from psutil._common import open_text
|
35
|
-
from psutil._compat import PY3
|
36
|
-
from psutil._compat import FileNotFoundError
|
37
|
-
from psutil._compat import long
|
38
|
-
from psutil._compat import redirect_stderr
|
39
|
-
from psutil._compat import super
|
40
|
-
from psutil.tests import APPVEYOR
|
41
37
|
from psutil.tests import CI_TESTING
|
42
38
|
from psutil.tests import GITHUB_ACTIONS
|
43
39
|
from psutil.tests import GLOBAL_TIMEOUT
|
@@ -53,14 +49,12 @@ from psutil.tests import MACOS_11PLUS
|
|
53
49
|
from psutil.tests import PYPY
|
54
50
|
from psutil.tests import PYTHON_EXE
|
55
51
|
from psutil.tests import PYTHON_EXE_ENV
|
56
|
-
from psutil.tests import QEMU_USER
|
57
52
|
from psutil.tests import PsutilTestCase
|
58
53
|
from psutil.tests import ThreadTask
|
59
54
|
from psutil.tests import call_until
|
60
55
|
from psutil.tests import copyload_shared_lib
|
61
56
|
from psutil.tests import create_c_exe
|
62
57
|
from psutil.tests import create_py_exe
|
63
|
-
from psutil.tests import mock
|
64
58
|
from psutil.tests import process_namespace
|
65
59
|
from psutil.tests import pytest
|
66
60
|
from psutil.tests import reap_children
|
@@ -130,16 +124,12 @@ class TestProcess(PsutilTestCase):
|
|
130
124
|
def test_send_signal_mocked(self):
|
131
125
|
sig = signal.SIGTERM
|
132
126
|
p = self.spawn_psproc()
|
133
|
-
with mock.patch(
|
134
|
-
'psutil.os.kill', side_effect=OSError(errno.ESRCH, "")
|
135
|
-
):
|
127
|
+
with mock.patch('psutil.os.kill', side_effect=ProcessLookupError):
|
136
128
|
with pytest.raises(psutil.NoSuchProcess):
|
137
129
|
p.send_signal(sig)
|
138
130
|
|
139
131
|
p = self.spawn_psproc()
|
140
|
-
with mock.patch(
|
141
|
-
'psutil.os.kill', side_effect=OSError(errno.EPERM, "")
|
142
|
-
):
|
132
|
+
with mock.patch('psutil.os.kill', side_effect=PermissionError):
|
143
133
|
with pytest.raises(psutil.AccessDenied):
|
144
134
|
p.send_signal(sig)
|
145
135
|
|
@@ -266,7 +256,6 @@ class TestProcess(PsutilTestCase):
|
|
266
256
|
psutil.Process().cpu_percent()
|
267
257
|
assert m.called
|
268
258
|
|
269
|
-
@pytest.mark.skipif(QEMU_USER, reason="QEMU user not supported")
|
270
259
|
def test_cpu_times(self):
|
271
260
|
times = psutil.Process().cpu_times()
|
272
261
|
assert times.user >= 0.0, times
|
@@ -279,19 +268,18 @@ class TestProcess(PsutilTestCase):
|
|
279
268
|
for name in times._fields:
|
280
269
|
time.strftime("%H:%M:%S", time.localtime(getattr(times, name)))
|
281
270
|
|
282
|
-
@pytest.mark.skipif(QEMU_USER, reason="QEMU user not supported")
|
283
271
|
def test_cpu_times_2(self):
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
272
|
+
def waste_cpu():
|
273
|
+
stop_at = os.times().user + 0.2
|
274
|
+
while os.times().user < stop_at:
|
275
|
+
for x in range(100000):
|
276
|
+
x **= 2
|
277
|
+
|
278
|
+
waste_cpu()
|
279
|
+
a = psutil.Process().cpu_times()
|
280
|
+
b = os.times()
|
281
|
+
self.assertAlmostEqual(a.user, b.user, delta=0.1)
|
282
|
+
self.assertAlmostEqual(a.system, b.system, delta=0.1)
|
295
283
|
|
296
284
|
@pytest.mark.skipif(not HAS_PROC_CPU_NUM, reason="not supported")
|
297
285
|
def test_cpu_num(self):
|
@@ -313,8 +301,8 @@ class TestProcess(PsutilTestCase):
|
|
313
301
|
difference = abs(create_time - now)
|
314
302
|
if difference > 2:
|
315
303
|
raise self.fail(
|
316
|
-
"expected:
|
317
|
-
|
304
|
+
f"expected: {now}, found: {create_time}, difference:"
|
305
|
+
f" {difference}"
|
318
306
|
)
|
319
307
|
|
320
308
|
# make sure returned value can be pretty printed with strftime
|
@@ -354,10 +342,7 @@ class TestProcess(PsutilTestCase):
|
|
354
342
|
# test writes
|
355
343
|
io1 = p.io_counters()
|
356
344
|
with open(self.get_testfn(), 'wb') as f:
|
357
|
-
|
358
|
-
f.write(bytes("x" * 1000000, 'ascii'))
|
359
|
-
else:
|
360
|
-
f.write("x" * 1000000)
|
345
|
+
f.write(bytes("x" * 1000000, 'ascii'))
|
361
346
|
io2 = p.io_counters()
|
362
347
|
assert io2.write_count >= io1.write_count
|
363
348
|
assert io2.write_bytes >= io1.write_bytes
|
@@ -498,10 +483,10 @@ class TestProcess(PsutilTestCase):
|
|
498
483
|
f.write(b"X" * 1024)
|
499
484
|
# write() or flush() doesn't always cause the exception
|
500
485
|
# but close() will.
|
501
|
-
with pytest.raises(
|
486
|
+
with pytest.raises(OSError) as exc:
|
502
487
|
with open(testfn, "wb") as f:
|
503
488
|
f.write(b"X" * 1025)
|
504
|
-
assert
|
489
|
+
assert exc.value.errno == errno.EFBIG
|
505
490
|
finally:
|
506
491
|
p.rlimit(psutil.RLIMIT_FSIZE, (soft, hard))
|
507
492
|
assert p.rlimit(psutil.RLIMIT_FSIZE) == (soft, hard)
|
@@ -587,14 +572,11 @@ class TestProcess(PsutilTestCase):
|
|
587
572
|
except psutil.AccessDenied:
|
588
573
|
raise pytest.skip("on OpenBSD this requires root access")
|
589
574
|
assert (
|
590
|
-
abs(p.cpu_times().user - sum(
|
575
|
+
abs(p.cpu_times().user - sum(x.user_time for x in p.threads()))
|
591
576
|
< 0.1
|
592
577
|
)
|
593
578
|
assert (
|
594
|
-
abs(
|
595
|
-
p.cpu_times().system
|
596
|
-
- sum([x.system_time for x in p.threads()])
|
597
|
-
)
|
579
|
+
abs(p.cpu_times().system - sum(x.system_time for x in p.threads()))
|
598
580
|
< 0.1
|
599
581
|
)
|
600
582
|
|
@@ -636,7 +618,7 @@ class TestProcess(PsutilTestCase):
|
|
636
618
|
for name in mem._fields:
|
637
619
|
value = getattr(mem, name)
|
638
620
|
assert value >= 0
|
639
|
-
if name ==
|
621
|
+
if (name == "vms" and OSX) or LINUX:
|
640
622
|
continue
|
641
623
|
assert value <= total
|
642
624
|
if LINUX or WINDOWS or MACOS:
|
@@ -653,34 +635,36 @@ class TestProcess(PsutilTestCase):
|
|
653
635
|
ext_maps = p.memory_maps(grouped=False)
|
654
636
|
|
655
637
|
for nt in maps:
|
656
|
-
if
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
638
|
+
if nt.path.startswith('['):
|
639
|
+
continue
|
640
|
+
if BSD and nt.path == "pvclock":
|
641
|
+
continue
|
642
|
+
assert os.path.isabs(nt.path), nt.path
|
643
|
+
|
644
|
+
if POSIX:
|
645
|
+
try:
|
646
|
+
assert os.path.exists(nt.path) or os.path.islink(
|
647
|
+
nt.path
|
648
|
+
), nt.path
|
649
|
+
except AssertionError:
|
650
|
+
if not LINUX:
|
651
|
+
raise
|
652
|
+
# https://github.com/giampaolo/psutil/issues/759
|
653
|
+
with open_text('/proc/self/smaps') as f:
|
654
|
+
data = f.read()
|
655
|
+
if f"{nt.path} (deleted)" not in data:
|
656
|
+
raise
|
657
|
+
elif '64' not in os.path.basename(nt.path):
|
658
|
+
# XXX - On Windows we have this strange behavior with
|
659
|
+
# 64 bit dlls: they are visible via explorer but cannot
|
660
|
+
# be accessed via os.stat() (wtf?).
|
661
|
+
try:
|
662
|
+
st = os.stat(nt.path)
|
663
|
+
except FileNotFoundError:
|
664
|
+
pass
|
665
|
+
else:
|
666
|
+
assert stat.S_ISREG(st.st_mode), nt.path
|
667
|
+
|
684
668
|
for nt in ext_maps:
|
685
669
|
for fname in nt._fields:
|
686
670
|
value = getattr(nt, fname)
|
@@ -689,7 +673,7 @@ class TestProcess(PsutilTestCase):
|
|
689
673
|
if fname in {'addr', 'perms'}:
|
690
674
|
assert value, value
|
691
675
|
else:
|
692
|
-
assert isinstance(value,
|
676
|
+
assert isinstance(value, int)
|
693
677
|
assert value >= 0, value
|
694
678
|
|
695
679
|
@pytest.mark.skipif(not HAS_MEMORY_MAPS, reason="not supported")
|
@@ -721,7 +705,6 @@ class TestProcess(PsutilTestCase):
|
|
721
705
|
assert not p.is_running()
|
722
706
|
assert not p.is_running()
|
723
707
|
|
724
|
-
@pytest.mark.skipif(QEMU_USER, reason="QEMU user not supported")
|
725
708
|
def test_exe(self):
|
726
709
|
p = self.spawn_psproc()
|
727
710
|
exe = p.exe()
|
@@ -734,12 +717,12 @@ class TestProcess(PsutilTestCase):
|
|
734
717
|
assert normcase(exe) == normcase(PYTHON_EXE)
|
735
718
|
else:
|
736
719
|
# certain platforms such as BSD are more accurate returning:
|
737
|
-
# "/usr/local/bin/
|
720
|
+
# "/usr/local/bin/python3.7"
|
738
721
|
# ...instead of:
|
739
722
|
# "/usr/local/bin/python"
|
740
723
|
# We do not want to consider this difference in accuracy
|
741
724
|
# an error.
|
742
|
-
ver = "
|
725
|
+
ver = f"{sys.version_info[0]}.{sys.version_info[1]}"
|
743
726
|
try:
|
744
727
|
assert exe.replace(ver, '') == PYTHON_EXE.replace(ver, '')
|
745
728
|
except AssertionError:
|
@@ -774,9 +757,6 @@ class TestProcess(PsutilTestCase):
|
|
774
757
|
if pyexe != PYTHON_EXE:
|
775
758
|
assert ' '.join(p.cmdline()[1:]) == ' '.join(cmdline[1:])
|
776
759
|
return
|
777
|
-
if QEMU_USER:
|
778
|
-
assert ' '.join(p.cmdline()[2:]) == ' '.join(cmdline)
|
779
|
-
return
|
780
760
|
assert ' '.join(p.cmdline()) == ' '.join(cmdline)
|
781
761
|
|
782
762
|
@pytest.mark.skipif(PYPY, reason="broken on PYPY")
|
@@ -794,8 +774,6 @@ class TestProcess(PsutilTestCase):
|
|
794
774
|
assert p.cmdline() == cmdline
|
795
775
|
except psutil.ZombieProcess:
|
796
776
|
raise pytest.skip("OPENBSD: process turned into zombie")
|
797
|
-
elif QEMU_USER:
|
798
|
-
assert p.cmdline()[2:] == cmdline
|
799
777
|
else:
|
800
778
|
ret = p.cmdline()
|
801
779
|
if NETBSD and ret == []:
|
@@ -809,9 +787,7 @@ class TestProcess(PsutilTestCase):
|
|
809
787
|
pyexe = os.path.basename(os.path.realpath(sys.executable)).lower()
|
810
788
|
assert pyexe.startswith(name), (pyexe, name)
|
811
789
|
|
812
|
-
@pytest.mark.skipif(PYPY
|
813
|
-
@pytest.mark.skipif(QEMU_USER, reason="unreliable on QEMU user")
|
814
|
-
@pytest.mark.skipif(MACOS and not PY3, reason="broken MACOS + PY2")
|
790
|
+
@pytest.mark.skipif(PYPY, reason="unreliable on PYPY")
|
815
791
|
def test_long_name(self):
|
816
792
|
pyexe = create_py_exe(self.get_testfn(suffix=string.digits * 2))
|
817
793
|
cmdline = [
|
@@ -842,9 +818,6 @@ class TestProcess(PsutilTestCase):
|
|
842
818
|
# @pytest.mark.skipif(SUNOS, reason="broken on SUNOS")
|
843
819
|
# @pytest.mark.skipif(AIX, reason="broken on AIX")
|
844
820
|
# @pytest.mark.skipif(PYPY, reason="broken on PYPY")
|
845
|
-
# @pytest.mark.skipif(SUNOS, reason="broken on SUNOS")
|
846
|
-
# @pytest.mark.skipif(MACOS and not PY3, reason="broken MACOS + PY2")
|
847
|
-
# @retry_on_failure()
|
848
821
|
# def test_prog_w_funky_name(self):
|
849
822
|
# # Test that name(), exe() and cmdline() correctly handle programs
|
850
823
|
# # with funky chars such as spaces and ")", see:
|
@@ -868,9 +841,8 @@ class TestProcess(PsutilTestCase):
|
|
868
841
|
assert real == os.getuid()
|
869
842
|
# os.geteuid() refers to "effective" uid
|
870
843
|
assert effective == os.geteuid()
|
871
|
-
# No such thing as os.getsuid() ("saved" uid), but
|
872
|
-
#
|
873
|
-
# of them.
|
844
|
+
# No such thing as os.getsuid() ("saved" uid), but we have
|
845
|
+
# os.getresuid() which returns all of them.
|
874
846
|
if hasattr(os, "getresuid"):
|
875
847
|
assert os.getresuid() == p.uids()
|
876
848
|
|
@@ -882,9 +854,8 @@ class TestProcess(PsutilTestCase):
|
|
882
854
|
assert real == os.getgid()
|
883
855
|
# os.geteuid() refers to "effective" uid
|
884
856
|
assert effective == os.getegid()
|
885
|
-
# No such thing as os.getsgid() ("saved" gid), but
|
886
|
-
#
|
887
|
-
# of them.
|
857
|
+
# No such thing as os.getsgid() ("saved" gid), but we have
|
858
|
+
# os.getresgid() which returns all of them.
|
888
859
|
if hasattr(os, "getresuid"):
|
889
860
|
assert os.getresgid() == p.gids()
|
890
861
|
|
@@ -954,7 +925,6 @@ class TestProcess(PsutilTestCase):
|
|
954
925
|
except psutil.AccessDenied:
|
955
926
|
pass
|
956
927
|
|
957
|
-
@pytest.mark.skipif(QEMU_USER, reason="QEMU user not supported")
|
958
928
|
def test_status(self):
|
959
929
|
p = psutil.Process()
|
960
930
|
assert p.status() == psutil.STATUS_RUNNING
|
@@ -1039,7 +1009,7 @@ class TestProcess(PsutilTestCase):
|
|
1039
1009
|
p.cpu_affinity(invalid_cpu)
|
1040
1010
|
with pytest.raises(ValueError):
|
1041
1011
|
p.cpu_affinity(range(10000, 11000))
|
1042
|
-
with pytest.raises(TypeError):
|
1012
|
+
with pytest.raises((TypeError, ValueError)):
|
1043
1013
|
p.cpu_affinity([0, "1"])
|
1044
1014
|
with pytest.raises(ValueError):
|
1045
1015
|
p.cpu_affinity([0, -1])
|
@@ -1056,9 +1026,11 @@ class TestProcess(PsutilTestCase):
|
|
1056
1026
|
initial = initial[:12] # ...otherwise it will take forever
|
1057
1027
|
combos = []
|
1058
1028
|
for i in range(len(initial) + 1):
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1029
|
+
combos.extend(
|
1030
|
+
list(subset)
|
1031
|
+
for subset in itertools.combinations(initial, i)
|
1032
|
+
if subset
|
1033
|
+
)
|
1062
1034
|
|
1063
1035
|
for combo in combos:
|
1064
1036
|
p.cpu_affinity(combo)
|
@@ -1066,8 +1038,6 @@ class TestProcess(PsutilTestCase):
|
|
1066
1038
|
|
1067
1039
|
# TODO: #595
|
1068
1040
|
@pytest.mark.skipif(BSD, reason="broken on BSD")
|
1069
|
-
# can't find any process file on Appveyor
|
1070
|
-
@pytest.mark.skipif(APPVEYOR, reason="unreliable on APPVEYOR")
|
1071
1041
|
def test_open_files(self):
|
1072
1042
|
p = psutil.Process()
|
1073
1043
|
testfn = self.get_testfn()
|
@@ -1090,8 +1060,8 @@ class TestProcess(PsutilTestCase):
|
|
1090
1060
|
|
1091
1061
|
# another process
|
1092
1062
|
cmdline = (
|
1093
|
-
"import time; f = open(r'
|
1094
|
-
" range(100)];"
|
1063
|
+
f"import time; f = open(r'{testfn}', 'r'); [time.sleep(0.1) for x"
|
1064
|
+
" in range(100)];"
|
1095
1065
|
)
|
1096
1066
|
p = self.spawn_psproc([PYTHON_EXE, "-c", cmdline])
|
1097
1067
|
|
@@ -1107,8 +1077,6 @@ class TestProcess(PsutilTestCase):
|
|
1107
1077
|
|
1108
1078
|
# TODO: #595
|
1109
1079
|
@pytest.mark.skipif(BSD, reason="broken on BSD")
|
1110
|
-
# can't find any process file on Appveyor
|
1111
|
-
@pytest.mark.skipif(APPVEYOR, reason="unreliable on APPVEYOR")
|
1112
1080
|
def test_open_files_2(self):
|
1113
1081
|
# test fd and path fields
|
1114
1082
|
p = psutil.Process()
|
@@ -1122,9 +1090,7 @@ class TestProcess(PsutilTestCase):
|
|
1122
1090
|
):
|
1123
1091
|
break
|
1124
1092
|
else:
|
1125
|
-
raise self.fail(
|
1126
|
-
"no file found; files=%s" % (repr(p.open_files()))
|
1127
|
-
)
|
1093
|
+
raise self.fail(f"no file found; files={p.open_files()!r}")
|
1128
1094
|
assert normcase(file.path) == normcase(fileobj.name)
|
1129
1095
|
if WINDOWS:
|
1130
1096
|
assert file.fd == -1
|
@@ -1142,7 +1108,7 @@ class TestProcess(PsutilTestCase):
|
|
1142
1108
|
p = psutil.Process()
|
1143
1109
|
testfn = self.get_testfn()
|
1144
1110
|
start = p.num_fds()
|
1145
|
-
file = open(testfn, 'w')
|
1111
|
+
file = open(testfn, 'w') # noqa: SIM115
|
1146
1112
|
self.addCleanup(file.close)
|
1147
1113
|
assert p.num_fds() == start + 1
|
1148
1114
|
sock = socket.socket()
|
@@ -1186,7 +1152,6 @@ class TestProcess(PsutilTestCase):
|
|
1186
1152
|
assert grandchild.parent() == child
|
1187
1153
|
assert child.parent() == parent
|
1188
1154
|
|
1189
|
-
@pytest.mark.skipif(QEMU_USER, reason="QEMU user not supported")
|
1190
1155
|
@retry_on_failure()
|
1191
1156
|
def test_parents(self):
|
1192
1157
|
parent = psutil.Process()
|
@@ -1198,8 +1163,8 @@ class TestProcess(PsutilTestCase):
|
|
1198
1163
|
|
1199
1164
|
def test_children(self):
|
1200
1165
|
parent = psutil.Process()
|
1201
|
-
assert parent.children()
|
1202
|
-
assert parent.children(recursive=True)
|
1166
|
+
assert not parent.children()
|
1167
|
+
assert not parent.children(recursive=True)
|
1203
1168
|
# On Windows we set the flag to 0 in order to cancel out the
|
1204
1169
|
# CREATE_NO_WINDOW flag (enabled by default) which creates
|
1205
1170
|
# an extra "conhost.exe" child.
|
@@ -1222,7 +1187,7 @@ class TestProcess(PsutilTestCase):
|
|
1222
1187
|
# children() to recursively find it.
|
1223
1188
|
child.terminate()
|
1224
1189
|
child.wait()
|
1225
|
-
assert parent.children(recursive=True)
|
1190
|
+
assert not parent.children(recursive=True)
|
1226
1191
|
|
1227
1192
|
def test_children_duplicates(self):
|
1228
1193
|
# find the process which has the highest number of children
|
@@ -1233,7 +1198,7 @@ class TestProcess(PsutilTestCase):
|
|
1233
1198
|
except psutil.Error:
|
1234
1199
|
pass
|
1235
1200
|
# this is the one, now let's make sure there are no duplicates
|
1236
|
-
pid =
|
1201
|
+
pid = max(table.items(), key=lambda x: x[1])[0]
|
1237
1202
|
if LINUX and pid == 0:
|
1238
1203
|
raise pytest.skip("PID 0")
|
1239
1204
|
p = psutil.Process(pid)
|
@@ -1397,7 +1362,7 @@ class TestProcess(PsutilTestCase):
|
|
1397
1362
|
if WINDOWS and fun_name in {'exe', 'name'}:
|
1398
1363
|
return
|
1399
1364
|
raise self.fail(
|
1400
|
-
"
|
1365
|
+
f"{fun!r} didn't raise NSP and returned {ret!r} instead"
|
1401
1366
|
)
|
1402
1367
|
|
1403
1368
|
p = self.spawn_psproc()
|
@@ -1441,11 +1406,6 @@ class TestProcess(PsutilTestCase):
|
|
1441
1406
|
|
1442
1407
|
def test_reused_pid(self):
|
1443
1408
|
# Emulate a case where PID has been reused by another process.
|
1444
|
-
if PY3:
|
1445
|
-
from io import StringIO
|
1446
|
-
else:
|
1447
|
-
from StringIO import StringIO
|
1448
|
-
|
1449
1409
|
subp = self.spawn_testproc()
|
1450
1410
|
p = psutil.Process(subp.pid)
|
1451
1411
|
p._ident = (p.pid, p.create_time() + 100)
|
@@ -1457,10 +1417,10 @@ class TestProcess(PsutilTestCase):
|
|
1457
1417
|
# make sure is_running() removed PID from process_iter()
|
1458
1418
|
# internal cache
|
1459
1419
|
with mock.patch.object(psutil._common, "PSUTIL_DEBUG", True):
|
1460
|
-
with redirect_stderr(StringIO()) as f:
|
1420
|
+
with contextlib.redirect_stderr(io.StringIO()) as f:
|
1461
1421
|
list(psutil.process_iter())
|
1462
1422
|
assert (
|
1463
|
-
"refreshing Process instance for reused PID
|
1423
|
+
f"refreshing Process instance for reused PID {p.pid}"
|
1464
1424
|
in f.getvalue()
|
1465
1425
|
)
|
1466
1426
|
assert p.pid not in psutil._pmap
|
@@ -1544,13 +1504,12 @@ class TestProcess(PsutilTestCase):
|
|
1544
1504
|
])
|
1545
1505
|
for name in exclude:
|
1546
1506
|
d.pop(name, None)
|
1547
|
-
return
|
1548
|
-
(
|
1549
|
-
|
1550
|
-
|
1551
|
-
)
|
1507
|
+
return {
|
1508
|
+
k.replace("\r", "").replace("\n", ""): v.replace(
|
1509
|
+
"\r", ""
|
1510
|
+
).replace("\n", "")
|
1552
1511
|
for k, v in d.items()
|
1553
|
-
|
1512
|
+
}
|
1554
1513
|
|
1555
1514
|
self.maxDiff = None
|
1556
1515
|
p = psutil.Process()
|
@@ -1608,62 +1567,6 @@ class TestProcess(PsutilTestCase):
|
|
1608
1567
|
assert sproc.returncode == 0
|
1609
1568
|
|
1610
1569
|
|
1611
|
-
# ===================================================================
|
1612
|
-
# --- Limited user tests
|
1613
|
-
# ===================================================================
|
1614
|
-
|
1615
|
-
|
1616
|
-
if POSIX and os.getuid() == 0:
|
1617
|
-
|
1618
|
-
class LimitedUserTestCase(TestProcess):
|
1619
|
-
"""Repeat the previous tests by using a limited user.
|
1620
|
-
Executed only on UNIX and only if the user who run the test script
|
1621
|
-
is root.
|
1622
|
-
"""
|
1623
|
-
|
1624
|
-
# the uid/gid the test suite runs under
|
1625
|
-
if hasattr(os, 'getuid'):
|
1626
|
-
PROCESS_UID = os.getuid()
|
1627
|
-
PROCESS_GID = os.getgid()
|
1628
|
-
|
1629
|
-
def __init__(self, *args, **kwargs):
|
1630
|
-
super().__init__(*args, **kwargs)
|
1631
|
-
# re-define all existent test methods in order to
|
1632
|
-
# ignore AccessDenied exceptions
|
1633
|
-
for attr in [x for x in dir(self) if x.startswith('test')]:
|
1634
|
-
meth = getattr(self, attr)
|
1635
|
-
|
1636
|
-
def test_(self):
|
1637
|
-
try:
|
1638
|
-
meth() # noqa
|
1639
|
-
except psutil.AccessDenied:
|
1640
|
-
pass
|
1641
|
-
|
1642
|
-
setattr(self, attr, types.MethodType(test_, self))
|
1643
|
-
|
1644
|
-
def setUp(self):
|
1645
|
-
super().setUp()
|
1646
|
-
os.setegid(1000)
|
1647
|
-
os.seteuid(1000)
|
1648
|
-
|
1649
|
-
def tearDown(self):
|
1650
|
-
os.setegid(self.PROCESS_UID)
|
1651
|
-
os.seteuid(self.PROCESS_GID)
|
1652
|
-
super().tearDown()
|
1653
|
-
|
1654
|
-
def test_nice(self):
|
1655
|
-
try:
|
1656
|
-
psutil.Process().nice(-1)
|
1657
|
-
except psutil.AccessDenied:
|
1658
|
-
pass
|
1659
|
-
else:
|
1660
|
-
raise self.fail("exception not raised")
|
1661
|
-
|
1662
|
-
@pytest.mark.skipif(True, reason="causes problem as root")
|
1663
|
-
def test_zombie_process(self):
|
1664
|
-
pass
|
1665
|
-
|
1666
|
-
|
1667
1570
|
# ===================================================================
|
1668
1571
|
# --- psutil.Popen tests
|
1669
1572
|
# ===================================================================
|
@@ -1677,7 +1580,7 @@ class TestPopen(PsutilTestCase):
|
|
1677
1580
|
reap_children()
|
1678
1581
|
|
1679
1582
|
def test_misc(self):
|
1680
|
-
# XXX this test causes a ResourceWarning
|
1583
|
+
# XXX this test causes a ResourceWarning because
|
1681
1584
|
# psutil.__subproc instance doesn't get properly freed.
|
1682
1585
|
# Not sure what to do though.
|
1683
1586
|
cmd = [
|
@@ -1693,10 +1596,10 @@ class TestPopen(PsutilTestCase):
|
|
1693
1596
|
) as proc:
|
1694
1597
|
proc.name()
|
1695
1598
|
proc.cpu_times()
|
1696
|
-
proc.stdin # noqa
|
1599
|
+
proc.stdin # noqa: B018
|
1697
1600
|
assert dir(proc)
|
1698
1601
|
with pytest.raises(AttributeError):
|
1699
|
-
proc.foo # noqa
|
1602
|
+
proc.foo # noqa: B018
|
1700
1603
|
proc.terminate()
|
1701
1604
|
if POSIX:
|
1702
1605
|
assert proc.wait(5) == -signal.SIGTERM
|
@@ -1745,3 +1648,20 @@ class TestPopen(PsutilTestCase):
|
|
1745
1648
|
proc.send_signal(signal.CTRL_C_EVENT)
|
1746
1649
|
with pytest.raises(psutil.NoSuchProcess):
|
1747
1650
|
proc.send_signal(signal.CTRL_BREAK_EVENT)
|
1651
|
+
|
1652
|
+
def test__getattribute__(self):
|
1653
|
+
cmd = [
|
1654
|
+
PYTHON_EXE,
|
1655
|
+
"-c",
|
1656
|
+
"import time; [time.sleep(0.1) for x in range(100)];",
|
1657
|
+
]
|
1658
|
+
with psutil.Popen(
|
1659
|
+
cmd,
|
1660
|
+
stdout=subprocess.PIPE,
|
1661
|
+
stderr=subprocess.PIPE,
|
1662
|
+
env=PYTHON_EXE_ENV,
|
1663
|
+
) as proc:
|
1664
|
+
proc.terminate()
|
1665
|
+
proc.wait()
|
1666
|
+
with pytest.raises(AttributeError):
|
1667
|
+
proc.foo # noqa: B018
|