summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola' <g.rodola@gmail.com>2013-03-14 13:53:19 +0000
committerGiampaolo Rodola' <g.rodola@gmail.com>2013-03-14 13:53:19 +0000
commit40d0172bf998425e965d72c0b74302ed1ef79d7b (patch)
tree283a8b83f4e54c60de71b71cc7335ea453e2f92b
parent1b12bbd0c1e454d4757392bb60ba147224caba98 (diff)
downloadpsutil-40d0172bf998425e965d72c0b74302ed1ef79d7b.tar.gz
fix some test failures on BSD
-rwxr-xr-xtest/_posix.py4
-rw-r--r--test/test_psutil.py29
2 files changed, 22 insertions, 11 deletions
diff --git a/test/_posix.py b/test/_posix.py
index 2673349c..b8afb3f9 100755
--- a/test/_posix.py
+++ b/test/_posix.py
@@ -70,7 +70,7 @@ class PosixSpecificTestCase(unittest.TestCase):
username_psutil = psutil.Process(self.pid).username
self.assertEqual(username_ps, username_psutil)
- @skip_on_access_denied
+ @skip_on_access_denied()
def test_process_rss_memory(self):
# give python interpreter some time to properly initialize
# so that the results are the same
@@ -79,7 +79,7 @@ class PosixSpecificTestCase(unittest.TestCase):
rss_psutil = psutil.Process(self.pid).get_memory_info()[0] / 1024
self.assertEqual(rss_ps, rss_psutil)
- @skip_on_access_denied
+ @skip_on_access_denied()
def test_process_vsz_memory(self):
# give python interpreter some time to properly initialize
# so that the results are the same
diff --git a/test/test_psutil.py b/test/test_psutil.py
index c67bc569..52468ae5 100644
--- a/test/test_psutil.py
+++ b/test/test_psutil.py
@@ -214,16 +214,22 @@ def skipUnless(condition, reason="", warn=False):
return skipIf(True, reason, warn)
return skipIf(False)
-def skip_on_access_denied(fun):
+def skip_on_access_denied(only_if=None):
"""Decorator to Ignore AccessDenied exceptions."""
- @functools.wraps(fun)
- def wrapper(*args, **kwargs):
- try:
- return fun(*args, **kwargs)
- except psutil.AccessDenied:
- warn("%r was skipped because it raised AccessDenied" \
- % fun.__name__)
- return wrapper
+ def decorator(fun):
+ @functools.wraps(fun)
+ def wrapper(*args, **kwargs):
+ try:
+ return fun(*args, **kwargs)
+ except psutil.AccessDenied:
+ if only_if is not None:
+ if not only_if:
+ raise
+ atexit.register(warn, "%r was skipped because it raised " \
+ "AccessDenied" % fun.__name__)
+ return wrapper
+ return decorator
+
def supports_ipv6():
"""Return True if IPv6 is supported on this platform."""
@@ -1226,6 +1232,7 @@ class TestCase(unittest.TestCase):
fileobj.close()
self.assertTrue(fileobj.name not in p.get_open_files())
+ @skip_on_access_denied(only_if=BSD)
def test_get_connections(self):
arg = "import socket, time;" \
"s = socket.socket();" \
@@ -1263,6 +1270,7 @@ class TestCase(unittest.TestCase):
self.assertRaises(ValueError, p.get_connections, 'foo')
@skipUnless(supports_ipv6())
+ @skip_on_access_denied(only_if=BSD)
def test_get_connections_ipv6(self):
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
s.bind(('::1', 0))
@@ -1273,6 +1281,7 @@ class TestCase(unittest.TestCase):
self.assertEqual(cons[0].local_address[0], '::1')
@skipUnless(hasattr(socket, 'AF_UNIX'))
+ @skip_on_access_denied(only_if=BSD)
def test_get_connections_unix(self):
# tcp
safe_remove(TESTFN)
@@ -1295,6 +1304,7 @@ class TestCase(unittest.TestCase):
sock.close()
@skipUnless(hasattr(socket, "fromfd") and not WINDOWS)
+ @skip_on_access_denied(only_if=BSD)
def test_connection_fromfd(self):
sock = socket.socket()
sock.bind(('localhost', 0))
@@ -1314,6 +1324,7 @@ class TestCase(unittest.TestCase):
sock.close()
dupsock.close()
+ @skip_on_access_denied(only_if=BSD)
def test_get_connections_all(self):
tcp_template = "import socket;" \
"s = socket.socket($family, socket.SOCK_STREAM);" \