summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-04-28 07:40:29 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-04-28 07:40:29 +0200
commit9f34016db45a960286c5a3d842d260d5076b04f3 (patch)
tree185b6b61bd6243b22c68cdb2e946526099d5a709
parent4ec6c5431f936c31af43d4d2f637e06d2c3b7619 (diff)
downloadpsutil-9f34016db45a960286c5a3d842d260d5076b04f3.tar.gz
fix test; C: reuse variable
-rw-r--r--psutil/arch/bsd/freebsd_socks.c10
-rwxr-xr-xpsutil/tests/test_process.py27
-rw-r--r--psutil/tests/test_unicode.py10
3 files changed, 25 insertions, 22 deletions
diff --git a/psutil/arch/bsd/freebsd_socks.c b/psutil/arch/bsd/freebsd_socks.c
index 2a8a5440..b30fa8f8 100644
--- a/psutil/arch/bsd/freebsd_socks.c
+++ b/psutil/arch/bsd/freebsd_socks.c
@@ -487,7 +487,6 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
PyObject *py_type_filter = NULL;
PyObject *py_family = NULL;
PyObject *py_type = NULL;
- PyObject *py_unix_path = NULL;
if (py_retlist == NULL)
return NULL;
@@ -598,11 +597,11 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
sun->sun_path);
#if PY_MAJOR_VERSION >= 3
- py_unix_path = PyUnicode_DecodeFSDefault(path);
+ py_laddr = PyUnicode_DecodeFSDefault(path);
#else
- py_unix_path = Py_BuildValue("s", path);
+ py_laddr = Py_BuildValue("s", path);
#endif
- if (! py_unix_path)
+ if (! py_laddr)
goto error;
py_tuple = Py_BuildValue(
@@ -610,7 +609,7 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
kif->kf_fd,
kif->kf_sock_domain,
kif->kf_sock_type,
- py_unix_path,
+ py_laddr,
Py_None,
PSUTIL_CONN_NONE
);
@@ -631,7 +630,6 @@ error:
Py_XDECREF(py_tuple);
Py_XDECREF(py_laddr);
Py_XDECREF(py_raddr);
- Py_XDECREF(py_unix_path);
Py_DECREF(py_retlist);
if (freep != NULL)
free(freep);
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py
index 78d01ae6..75b92767 100755
--- a/psutil/tests/test_process.py
+++ b/psutil/tests/test_process.py
@@ -1103,20 +1103,21 @@ class TestProcess(unittest.TestCase):
safe_rmpath(TESTFN)
sock, name = bind_unix_socket(
type=type, name=None if OSX else TESTFN)
- self.addCleanup(sock.close)
self.addCleanup(safe_rmpath, name)
- cons = psutil.Process().connections(kind='unix')
- conn = cons[0]
- check_connection_ntuple(conn)
- if conn.fd != -1: # != sunos and windows
- self.assertEqual(conn.fd, sock.fileno())
- self.assertEqual(conn.family, socket.AF_UNIX)
- self.assertEqual(conn.type, type)
- self.assertEqual(conn.laddr, name)
- if not SUNOS:
- # XXX Solaris can't retrieve system-wide UNIX
- # sockets.
- self.compare_proc_sys_cons(os.getpid(), cons)
+ with contextlib.closing(sock):
+ cons = psutil.Process().connections(kind='unix')
+ self.assertEqual(len(cons), 1)
+ conn = cons[0]
+ check_connection_ntuple(conn)
+ if conn.fd != -1: # != sunos and windows
+ self.assertEqual(conn.fd, sock.fileno())
+ self.assertEqual(conn.family, socket.AF_UNIX)
+ self.assertEqual(conn.type, type)
+ self.assertEqual(conn.laddr, name)
+ if not SUNOS:
+ # XXX Solaris can't retrieve system-wide UNIX
+ # sockets.
+ self.compare_proc_sys_cons(os.getpid(), cons)
check(SOCK_STREAM)
check(SOCK_DGRAM)
diff --git a/psutil/tests/test_unicode.py b/psutil/tests/test_unicode.py
index 31e29b17..e036507d 100644
--- a/psutil/tests/test_unicode.py
+++ b/psutil/tests/test_unicode.py
@@ -149,9 +149,13 @@ class _BaseFSAPIsTests(object):
@unittest.skipUnless(hasattr(socket, "AF_UNIX"), "AF_UNIX not supported")
def test_proc_connections(self):
try:
- sock, name = bind_unix_socket(suffix=self.funky_name)
- except (socket.error, UnicodeEncodeError):
- raise unittest.SkipTest("not supported")
+ sock, name = bind_unix_socket(
+ suffix=os.path.basename(self.funky_name))
+ except UnicodeDecodeError:
+ if PY3:
+ raise
+ else:
+ raise unittest.SkipTest("not supported")
self.addCleanup(safe_rmpath, name)
self.addCleanup(sock.close)
conn = psutil.Process().connections(kind='unix')[0]