summaryrefslogtreecommitdiff
path: root/psutil/tests
diff options
context:
space:
mode:
Diffstat (limited to 'psutil/tests')
-rw-r--r--psutil/tests/__init__.py7
-rwxr-xr-xpsutil/tests/test_misc.py20
2 files changed, 16 insertions, 11 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py
index ed06df77..ffb73f5b 100644
--- a/psutil/tests/__init__.py
+++ b/psutil/tests/__init__.py
@@ -874,17 +874,14 @@ class PsutilTestCase(TestCase):
self.addCleanup(terminate, sproc) # executed first
return sproc
- def assertPidGone(self, pid):
- assert not psutil.pid_exists(pid), pid
- self.assertNotIn(pid, psutil.pids())
-
def assertProcessGone(self, proc):
self.assertRaises(psutil.NoSuchProcess, psutil.Process, proc.pid)
if isinstance(proc, (psutil.Process, psutil.Popen)):
assert not proc.is_running()
self.assertRaises(psutil.NoSuchProcess, proc.status)
proc.wait(timeout=0) # assert not raise TimeoutExpired
- self.assertPidGone(proc.pid)
+ assert not psutil.pid_exists(proc.pid), proc.pid
+ self.assertNotIn(proc.pid, psutil.pids())
@unittest.skipIf(PYPY, "unreliable on PYPY")
diff --git a/psutil/tests/test_misc.py b/psutil/tests/test_misc.py
index 4fb8ba5a..959d12e5 100755
--- a/psutil/tests/test_misc.py
+++ b/psutil/tests/test_misc.py
@@ -57,20 +57,25 @@ import psutil.tests
class TestMisc(PsutilTestCase):
def test_process__repr__(self, func=repr):
- p = psutil.Process()
+ p = psutil.Process(self.spawn_testproc().pid)
r = func(p)
self.assertIn("psutil.Process", r)
self.assertIn("pid=%s" % p.pid, r)
- self.assertIn("name=", r)
+ self.assertIn("name='%s'" % p.name(), r)
self.assertIn("status=", r)
- self.assertIn(p.name(), r)
- self.assertIn("status='running'", r)
+ self.assertNotIn("exitcode=", r)
+ p.terminate()
+ code = p.wait()
+ r = func(p)
+ self.assertIn("status='terminated'", r)
+ self.assertIn("exitcode=%s" % code, r)
+
with mock.patch.object(psutil.Process, "name",
side_effect=psutil.ZombieProcess(os.getpid())):
p = psutil.Process()
r = func(p)
self.assertIn("pid=%s" % p.pid, r)
- self.assertIn("zombie", r)
+ self.assertIn("status='zombie'", r)
self.assertNotIn("name=", r)
with mock.patch.object(psutil.Process, "name",
side_effect=psutil.NoSuchProcess(os.getpid())):
@@ -303,7 +308,10 @@ class TestMisc(PsutilTestCase):
else:
with self.assertRaises(Exception):
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
- sock.bind(("::1", 0))
+ try:
+ sock.bind(("::1", 0))
+ finally:
+ sock.close()
def test_isfile_strict(self):
from psutil._common import isfile_strict