summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-05-17 18:11:23 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-05-17 18:11:23 +0200
commitf698d84da2d880fcb9b27f16e599517b09cea5b8 (patch)
tree9c6846b9b3bc0876698b47402dbb95813c6c38dd
parent3b50e3a31b5c759e824b7212e51e986862883874 (diff)
downloadpsutil-f698d84da2d880fcb9b27f16e599517b09cea5b8.tar.gz
add Popen test for making sure NSP is raised on kill() and terminate()
-rwxr-xr-xpsutil/tests/test_process.py33
1 files changed, 24 insertions, 9 deletions
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py
index b9b13c58..7f358170 100755
--- a/psutil/tests/test_process.py
+++ b/psutil/tests/test_process.py
@@ -1504,34 +1504,49 @@ class TestPopen(unittest.TestCase):
def tearDown(self):
reap_children()
- def test_it(self):
+ def test_misc(self):
# XXX this test causes a ResourceWarning on Python 3 because
# psutil.__subproc instance doesn't get propertly freed.
# Not sure what to do though.
cmd = [PYTHON, "-c", "import time; time.sleep(60);"]
- proc = psutil.Popen(cmd, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- try:
+ with psutil.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE) as proc:
proc.name()
proc.cpu_times()
proc.stdin
self.assertTrue(dir(proc))
self.assertRaises(AttributeError, getattr, proc, 'foo')
- finally:
proc.terminate()
- proc.stdout.close()
- proc.stderr.close()
- proc.wait()
def test_ctx_manager(self):
with psutil.Popen([PYTHON, "-V"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE) as proc:
- pass
+ proc.communicate()
assert proc.stdout.closed
assert proc.stderr.closed
assert proc.stdin.closed
+ self.assertEqual(proc.returncode, 0)
+
+ def test_kill_terminate(self):
+ # subprocess.Popen()'s terminate(), kill() and send_signal() do
+ # not raise exception after the process is gone. psutil.Popen
+ # diverges from that.
+ cmd = [PYTHON, "-c", "import time; time.sleep(60);"]
+ with psutil.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE) as proc:
+ proc.terminate()
+ proc.wait()
+ self.assertRaises(psutil.NoSuchProcess, proc.terminate)
+ self.assertRaises(psutil.NoSuchProcess, proc.kill)
+ self.assertRaises(psutil.NoSuchProcess, proc.send_signal,
+ signal.SIGTERM)
+ if WINDOWS:
+ self.assertRaises(psutil.NoSuchProcess, proc.send_signal,
+ signal.CTRL_C_EVENT)
+ self.assertRaises(psutil.NoSuchProcess, proc.send_signal,
+ signal.CTRL_BREAK_EVENT)
if __name__ == '__main__':