def test_cpu_times(self):
# Check type, value >= 0, str().
total = 0
times = psutil.cpu_times()
sum(times)
for cp_time in times:
self.assertIsInstance(cp_time, float)
self.assertGreaterEqual(cp_time, 0.0)
total += cp_time
self.assertEqual(total, sum(times))
str(times)
# CPU times are always supposed to increase over time
# or at least remain the same and that's because time
# cannot go backwards.
# Surprisingly sometimes this might not be the case (at
# least on Windows and Linux), see:
# https://github.com/giampaolo/psutil/issues/392
# https://github.com/giampaolo/psutil/issues/645
# if not WINDOWS:
# last = psutil.cpu_times()
# for x in range(100):
# new = psutil.cpu_times()
# for field in new._fields:
# new_t = getattr(new, field)
# last_t = getattr(last, field)
# self.assertGreaterEqual(new_t, last_t,
# msg="%s %s" % (new_t, last_t))
# last = new
评论列表
文章目录