Skip to content

Commit

Permalink
refact tests
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Aug 2, 2023
1 parent 2b883e4 commit 4a95cd1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
26 changes: 25 additions & 1 deletion psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,17 +964,41 @@ def assertProcessZombie(self, proc):
self.assertEqual(proc.status(), psutil.STATUS_ZOMBIE)
# It should be considered 'running'.
assert proc.is_running()
assert psutil.pid_exists(proc.pid)
# as_dict() shouldn't crash.
proc.as_dict()
# It should show up in pids() and process_iter().
self.assertIn(proc.pid, psutil.pids())
self.assertIn(proc.pid, [x.pid for x in psutil.process_iter()])
# It cannot be signaled or terminated.
psutil._pmap = {}
self.assertIn(proc.pid, [x.pid for x in psutil.process_iter()])
# Call all methods.
ns = process_namespace(proc)
for fun, name in ns.iter(ns.all):
with self.subTest(name):
try:
fun()
except (psutil.ZombieProcess, psutil.AccessDenied):
pass
# Make sure getters does not return 'null' values.
for fun, name in ns.iter(ns.getters):
with self.subTest(name):
try:
retval = fun()
self.assertNotIn(retval, ("", None, []))
except (psutil.ZombieProcess, psutil.AccessDenied):
pass
# Zombie cannot be signaled or terminated.
proc.suspend()
proc.resume()
proc.terminate()
proc.kill()
assert proc.is_running()
assert psutil.pid_exists(proc.pid)
self.assertIn(proc.pid, psutil.pids())
self.assertIn(proc.pid, [x.pid for x in psutil.process_iter()])
psutil._pmap = {}
self.assertIn(proc.pid, [x.pid for x in psutil.process_iter()])

# Its parent should 'see' it (edit: not true on BSD and MACOS).
# descendants = [x.pid for x in psutil.Process().children(
Expand Down
21 changes: 0 additions & 21 deletions psutil/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,27 +1322,6 @@ def assert_raises_nsp(fun, fun_name):
def test_zombie_process(self):
parent, zombie = self.spawn_zombie()
self.assertProcessZombie(zombie)
ns = process_namespace(zombie)
for fun, name in ns.iter(ns.all):
with self.subTest(name):
try:
fun()
except (psutil.ZombieProcess, psutil.AccessDenied):
pass

for fun, name in ns.iter(ns.getters):
with self.subTest(name):
try:
retval = fun()
self.assertNotIn(retval, ("", None, []))
except (psutil.ZombieProcess, psutil.AccessDenied):
pass

assert psutil.pid_exists(zombie.pid)
self.assertIn(zombie.pid, psutil.pids())
self.assertIn(zombie.pid, [x.pid for x in psutil.process_iter()])
psutil._pmap = {}
self.assertIn(zombie.pid, [x.pid for x in psutil.process_iter()])

@unittest.skipIf(not POSIX, 'POSIX only')
def test_zombie_process_is_running_w_exc(self):
Expand Down

0 comments on commit 4a95cd1

Please sign in to comment.