diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2015-06-20 03:15:10 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2015-06-20 03:15:10 +0200 |
commit | 4bd1596035b2d0b1beb795b98dce662054639d48 (patch) | |
tree | 62bb3d3b271a7a369125a1effa74352712fd9921 | |
parent | 3163e7ec7df88b6fdfd9b1fcdec29aa0fef695e8 (diff) | |
download | psutil-4bd1596035b2d0b1beb795b98dce662054639d48.tar.gz |
improve test coverage
-rw-r--r-- | psutil/_pslinux.py | 8 | ||||
-rw-r--r-- | test/test_psutil.py | 6 |
2 files changed, 11 insertions, 3 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index f3b5b080..6c84faf2 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -1078,8 +1078,9 @@ class Process(object): if HAS_PRLIMIT: @wrap_exceptions def rlimit(self, resource, limits=None): - # if pid is 0 prlimit() applies to the calling process and - # we don't want that + # If pid is 0 prlimit() applies to the calling process and + # we don't want that. We should never get here though as + # PID 0 is not supported on Linux. if self.pid == 0: raise ValueError("can't use prlimit() against PID 0 process") try: @@ -1090,7 +1091,8 @@ class Process(object): # set if len(limits) != 2: raise ValueError( - "second argument must be a (soft, hard) tuple") + "second argument must be a (soft, hard) tuple, " + "got %s" % repr(limits)) soft, hard = limits cext.linux_prlimit(self.pid, resource, soft, hard) except OSError as err: diff --git a/test/test_psutil.py b/test/test_psutil.py index bc750fdc..0db9beb2 100644 --- a/test/test_psutil.py +++ b/test/test_psutil.py @@ -1411,6 +1411,12 @@ class TestProcess(unittest.TestCase): p = psutil.Process(sproc.pid) p.rlimit(psutil.RLIMIT_NOFILE, (5, 5)) self.assertEqual(p.rlimit(psutil.RLIMIT_NOFILE), (5, 5)) + # If pid is 0 prlimit() applies to the calling process and + # we don't want that. + with self.assertRaises(ValueError): + psutil._psplatform.Process(0).rlimit(0) + with self.assertRaises(ValueError): + p.rlimit(psutil.RLIMIT_NOFILE, (5, 5, 5)) def test_num_threads(self): # on certain platforms such as Linux we might test for exact |