int(matchobj.group("cs")), delta=CPU_STATS_TOLERANCE) self.assertAlmostEqual( psutil_result.syscalls, int(matchobj.group("sysc")), delta=CPU_STATS_TOLERANCE) self.assertAlmostEqual( psutil_result.interrupts, int(matchobj.group("dev")), delta=CPU_STATS_TOLERANCE) self.assertAlmostEqual( psutil_result.soft_interrupts, int(matchobj.group("soft")), delta=CPU_STATS_TOLERANCE) def test_cpu_count_logical(self): out = sh('/usr/bin/mpstat -a') mpstat_lcpu = int(re.search("lcpu=(\d+)", out).group(1)) psutil_lcpu = psutil.cpu_count(logical=True) self.assertEqual(mpstat_lcpu, psutil_lcpu) def test_net_if_addrs_names(self): out = sh('/etc/ifconfig -l') ifconfig_names = set(out.split()) psutil_names = set(psutil.net_if_addrs().keys()) self.assertSetEqual(ifconfig_names, psutil_names) if __name__ == '__main__': run_test_module_by_name(__file__)
if POSIX: assert -20 <= ret <= 20, ret else: priorities = [ getattr(psutil, x) for x in dir(psutil) if x.endswith('_PRIORITY_CLASS') ] self.assertIn(ret, priorities) def num_ctx_switches(self, ret, proc): assert is_namedtuple(ret) for value in ret: self.assertIsInstance(value, (int, long)) self.assertGreaterEqual(value, 0) def rlimit(self, ret, proc): self.assertIsInstance(ret, tuple) self.assertEqual(len(ret), 2) self.assertGreaterEqual(ret[0], -1) self.assertGreaterEqual(ret[1], -1) def environ(self, ret, proc): self.assertIsInstance(ret, dict) for k, v in ret.items(): self.assertIsInstance(k, str) self.assertIsInstance(v, str) if __name__ == '__main__': run_test_module_by_name(__file__)