diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2015-06-20 15:07:46 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2015-06-20 15:07:46 +0200 |
commit | fcf5ca3e938045c72d26495353446eabea70d4e3 (patch) | |
tree | 7da295fd86cd06b7bcdac6e56f0bf25af216548b | |
parent | 5cd6fcac01e442b5022d223e3e366dfae456ad64 (diff) | |
download | psutil-fcf5ca3e938045c72d26495353446eabea70d4e3.tar.gz |
enhance test coverage
-rw-r--r-- | psutil/__init__.py | 10 | ||||
-rw-r--r-- | test/test_psutil.py | 10 |
2 files changed, 11 insertions, 9 deletions
diff --git a/psutil/__init__.py b/psutil/__init__.py index 64a8d691..16314476 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -681,7 +681,7 @@ class Process(object): """ if ioclass is None: if value is not None: - raise ValueError("'ioclass' must be specified") + raise ValueError("'ioclass' argument must be specified") return self._proc.ionice_get() else: return self._proc.ionice_set(ioclass, value) @@ -1853,14 +1853,6 @@ def test(): time.localtime(sum(pinfo['cpu_times']))) try: user = p.username() - except KeyError: - if _POSIX: - if pinfo['uids']: - user = str(pinfo['uids'].real) - else: - user = '' - else: - raise except Error: user = '' if _WINDOWS and '\\' in user: diff --git a/test/test_psutil.py b/test/test_psutil.py index 7609d35d..b6dc1348 100644 --- a/test/test_psutil.py +++ b/test/test_psutil.py @@ -584,6 +584,7 @@ class TestSystemAPIs(unittest.TestCase): sproc3 = get_test_subprocess() procs = [psutil.Process(x.pid) for x in (sproc1, sproc2, sproc3)] self.assertRaises(ValueError, psutil.wait_procs, procs, timeout=-1) + self.assertRaises(TypeError, psutil.wait_procs, procs, callback=1) t = time.time() gone, alive = psutil.wait_procs(procs, timeout=0.01, callback=callback) @@ -1371,6 +1372,9 @@ class TestProcess(unittest.TestCase): self.assertRaisesRegexp( ValueError, "can't specify value with IOPRIO_CLASS_IDLE", p.ionice, psutil.IOPRIO_CLASS_IDLE, 1) + self.assertRaisesRegexp( + ValueError, "'ioclass' argument must be specified", + p.ionice, value=1) finally: p.ionice(IOPRIO_CLASS_NONE) else: @@ -1661,6 +1665,11 @@ class TestProcess(unittest.TestCase): if POSIX: import pwd self.assertEqual(p.username(), pwd.getpwuid(os.getuid()).pw_name) + with mock.patch("psutil.pwd.getpwuid", + side_effect=KeyError) as fun: + p.username() == str(p.uids().real) + assert fun.called + elif WINDOWS and 'USERNAME' in os.environ: expected_username = os.environ['USERNAME'] expected_domain = os.environ['USERDOMAIN'] @@ -2247,6 +2256,7 @@ class TestProcess(unittest.TestCase): proc.stdin self.assertTrue(hasattr(proc, 'name')) self.assertTrue(hasattr(proc, 'stdin')) + self.assertTrue(dir(proc)) self.assertRaises(AttributeError, getattr, proc, 'foo') finally: proc.kill() |