diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2015-01-06 16:16:11 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2015-01-06 16:16:11 +0100 |
commit | e4d0aa990d1c8802b262a1af4c23af47922ff89b (patch) | |
tree | 9f96f451cc556d086ccb46dafad0f68b8e49b940 | |
parent | 029f05154f373e934586d7ca9f1c2b11f0c0dffe (diff) | |
download | psutil-e4d0aa990d1c8802b262a1af4c23af47922ff89b.tar.gz |
fix #570: test_memory_leaks test for error conditions
-rw-r--r-- | test/test_memory_leaks.py | 27 | ||||
-rw-r--r-- | test/test_psutil.py | 1 |
2 files changed, 23 insertions, 5 deletions
diff --git a/test/test_memory_leaks.py b/test/test_memory_leaks.py index 614a82c6..3fbd8289 100644 --- a/test/test_memory_leaks.py +++ b/test/test_memory_leaks.py @@ -85,6 +85,10 @@ class Base(unittest.TestCase): self.fail("rss2=%s, rss3=%s, difference=%s" % (rss2, rss3, difference)) + def execute_w_exc(self, exc, function, *args, **kwargs): + kwargs['_exc'] = exc + self.execute(function, *args, **kwargs) + def get_mem(self): return psutil.Process().memory_info()[0] @@ -102,11 +106,15 @@ class TestProcessObjectLeaks(Base): reap_children() def call(self, function, *args, **kwargs): - try: - meth = getattr(self.proc, function) - meth(*args, **kwargs) - except psutil.Error: - pass + meth = getattr(self.proc, function) + if '_exc' in kwargs: + exc = kwargs.pop('_exc') + self.assertRaises(exc, meth, *args, **kwargs) + else: + try: + meth(*args, **kwargs) + except psutil.Error: + pass @skip_if_linux() def test_name(self): @@ -158,6 +166,7 @@ class TestProcessObjectLeaks(Base): self.execute('ionice', value) else: self.execute('ionice', psutil.IOPRIO_CLASS_NONE) + self.execute_w_exc(OSError, 'ionice', -1) @unittest.skipIf(OSX, "feature not supported on this platform") @skip_if_linux() @@ -225,6 +234,7 @@ class TestProcessObjectLeaks(Base): def test_cpu_affinity_set(self): affinity = psutil.Process().cpu_affinity() self.execute('cpu_affinity', affinity) + self.execute_w_exc(ValueError, 'cpu_affinity', [9999]) @skip_if_linux() def test_open_files(self): @@ -250,6 +260,7 @@ class TestProcessObjectLeaks(Base): def test_rlimit_set(self): limit = psutil.Process().rlimit(psutil.RLIMIT_NOFILE) self.execute('rlimit', psutil.RLIMIT_NOFILE, limit) + self.execute_w_exc(OSError, 'rlimit', -1) @skip_if_linux() # Windows implementation is based on a single system-wide function @@ -300,6 +311,12 @@ class TestProcessObjectLeaksZombie(TestProcessObjectLeaks): """ proc = DEAD_PROC + def call(self, *args, **kwargs): + try: + TestProcessObjectLeaks.call(self, *args, **kwargs) + except psutil.NoSuchProcess: + pass + if not POSIX: def test_kill(self): self.execute('kill') diff --git a/test/test_psutil.py b/test/test_psutil.py index 67fe80bc..c8e14e87 100644 --- a/test/test_psutil.py +++ b/test/test_psutil.py @@ -968,6 +968,7 @@ class TestSystemAPIs(unittest.TestCase): self.assertIn(mount, mounts) psutil.disk_usage(mount) + @skip_on_access_denied() def test_net_connections(self): def check(cons, families, types_): for conn in cons: |