summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-06-20 02:25:11 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2015-06-20 02:25:11 +0200
commit48f898afa584ac9eed209b63e46a93f1876278f4 (patch)
treef41959a9b21c85045edf05d9e880261c7e808277
parent46be64c0bfa7abc51522ea0a00ee57518f68f13d (diff)
downloadpsutil-48f898afa584ac9eed209b63e46a93f1876278f4.tar.gz
improve linux test coverage
-rw-r--r--psutil/_pslinux.py17
-rw-r--r--test/_linux.py14
-rw-r--r--test/test_psutil.py2
3 files changed, 26 insertions, 7 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index a0a4d350..3f1ff721 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -329,7 +329,7 @@ def boot_time():
ret = float(line.strip().split()[1])
BOOT_TIME = ret
return ret
- raise RuntimeError("line 'btime' not found")
+ raise RuntimeError("line 'btime' not found in /proc/stat")
# --- processes
@@ -1148,27 +1148,30 @@ class Process(object):
@wrap_exceptions
def ppid(self):
- with open("/proc/%s/status" % self.pid, 'rb') as f:
+ fpath = "/proc/%s/status" % self.pid
+ with open(fpath, 'rb') as f:
for line in f:
if line.startswith(b"PPid:"):
# PPid: nnnn
return int(line.split()[1])
- raise NotImplementedError("line not found")
+ raise NotImplementedError("line 'PPid' not found in %s" % fpath)
@wrap_exceptions
def uids(self):
- with open("/proc/%s/status" % self.pid, 'rb') as f:
+ fpath = "/proc/%s/status" % self.pid
+ with open(fpath, 'rb') as f:
for line in f:
if line.startswith(b'Uid:'):
_, real, effective, saved, fs = line.split()
return _common.puids(int(real), int(effective), int(saved))
- raise NotImplementedError("line not found")
+ raise NotImplementedError("line 'Uid' not found in %s" % fpath)
@wrap_exceptions
def gids(self):
- with open("/proc/%s/status" % self.pid, 'rb') as f:
+ fpath = "/proc/%s/status" % self.pid
+ with open(fpath, 'rb') as f:
for line in f:
if line.startswith(b'Gid:'):
_, real, effective, saved, fs = line.split()
return _common.pgids(int(real), int(effective), int(saved))
- raise NotImplementedError("line not found")
+ raise NotImplementedError("line 'Gid' not found in %s" % fpath)
diff --git a/test/_linux.py b/test/_linux.py
index 5d7f0521..57e37bd2 100644
--- a/test/_linux.py
+++ b/test/_linux.py
@@ -321,6 +321,20 @@ class LinuxSpecificTestCase(unittest.TestCase):
psutil._pslinux.Process(os.getpid()).gids)
assert m.called
+ def test_proc_io_counters_mocked(self):
+ with mock.patch('psutil._pslinux.open', create=True) as m:
+ self.assertRaises(
+ NotImplementedError,
+ psutil._pslinux.Process(os.getpid()).io_counters)
+ assert m.called
+
+ def test_boot_time_mocked(self):
+ with mock.patch('psutil._pslinux.open', create=True) as m:
+ self.assertRaises(
+ RuntimeError,
+ psutil._pslinux.boot_time)
+ assert m.called
+
# --- tests for specific kernel versions
@unittest.skipUnless(
diff --git a/test/test_psutil.py b/test/test_psutil.py
index b93cd863..842fff78 100644
--- a/test/test_psutil.py
+++ b/test/test_psutil.py
@@ -675,6 +675,8 @@ class TestSystemAPIs(unittest.TestCase):
self.assertFalse(psutil.pid_exists(sproc.pid))
self.assertFalse(psutil.pid_exists(-1))
self.assertEqual(psutil.pid_exists(0), 0 in psutil.pids())
+ # pid 0
+ psutil.pid_exists(0) == 0 in psutil.pids()
def test_pid_exists_2(self):
reap_children()