summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-11-05 01:43:44 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2016-11-05 01:43:44 +0100
commitcc81692688d8502d9fc455effe9e00a6ea495d0a (patch)
tree577a7e81c251404f6468d0ef94b241782507ff6d
parente2cacdad028a02dccc5962a7043a1c113d202619 (diff)
downloadpsutil-cc81692688d8502d9fc455effe9e00a6ea495d0a.tar.gz
add simple test case for oneshot() ctx manager
-rwxr-xr-xpsutil/tests/test_process.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py
index c189b1a0..d2b700e5 100755
--- a/psutil/tests/test_process.py
+++ b/psutil/tests/test_process.py
@@ -1236,6 +1236,19 @@ class TestProcess(unittest.TestCase):
with self.assertRaises(ValueError):
p.as_dict(['foo', 'bar'])
+ def test_oneshot(self):
+ with mock.patch("psutil._psplatform.Process.cpu_times") as m:
+ p = psutil.Process()
+ with p.oneshot():
+ p.cpu_times()
+ p.cpu_times()
+ self.assertEqual(m.call_count, 1)
+
+ with mock.patch("psutil._psplatform.Process.cpu_times") as m:
+ p.cpu_times()
+ p.cpu_times()
+ self.assertEqual(m.call_count, 2)
+
def test_halfway_terminated_process(self):
# Test that NoSuchProcess exception gets raised in case the
# process dies after we create the Process object.