diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-17 18:01:44 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-17 18:01:44 +0200 |
commit | 3b50e3a31b5c759e824b7212e51e986862883874 (patch) | |
tree | fec06bf37ca069e972d6749152368dc487bb8636 | |
parent | 0c2eb2ab9e644df8e012dd36e3d2994695bab1cc (diff) | |
download | psutil-3b50e3a31b5c759e824b7212e51e986862883874.tar.gz |
move psutil.Popen tests in their own class
-rwxr-xr-x | psutil/tests/test_process.py | 70 |
1 files changed, 41 insertions, 29 deletions
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 86ad136f..b9b13c58 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -1383,35 +1383,6 @@ class TestProcess(unittest.TestCase): self.assertIn(0, psutil.pids()) self.assertTrue(psutil.pid_exists(0)) - def test_Popen(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: - 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_Popen_ctx_manager(self): - with psutil.Popen([PYTHON, "-V"], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - stdin=subprocess.PIPE) as proc: - pass - assert proc.stdout.closed - assert proc.stderr.closed - assert proc.stdin.closed - @unittest.skipIf(not HAS_ENVIRON, "not supported") def test_environ(self): self.maxDiff = None @@ -1522,5 +1493,46 @@ if POSIX and os.getuid() == 0: pass +# =================================================================== +# --- psutil.Popen tests +# =================================================================== + + +class TestPopen(unittest.TestCase): + """Tests for psutil.Popen class.""" + + def tearDown(self): + reap_children() + + def test_it(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: + 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 + assert proc.stdout.closed + assert proc.stderr.closed + assert proc.stdin.closed + + if __name__ == '__main__': run_test_module_by_name(__file__) |