summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-04-28 06:56:59 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-04-28 06:56:59 +0200
commit76dd68eecbcdce608dfc46b37a82f2ab83927b72 (patch)
treecde9ac9cea428c1f8a0860fdb7517f168c2cdaf3
parent60e11eb60b499e1485a4eea90e032ec9a688f9e1 (diff)
downloadpsutil-76dd68eecbcdce608dfc46b37a82f2ab83927b72.tar.gz
reuse bind_unix_socket()
-rw-r--r--psutil/tests/__init__.py3
-rwxr-xr-xpsutil/tests/test_process.py8
2 files changed, 5 insertions, 6 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py
index ea8e2e82..69ef2ba6 100644
--- a/psutil/tests/__init__.py
+++ b/psutil/tests/__init__.py
@@ -145,7 +145,6 @@ SCRIPTS_DIR = os.path.join(ROOT_DIR, 'scripts')
# --- misc
-AF_UNIX = getattr(socket, "AF_UNIX", None)
PYTHON = os.path.realpath(sys.executable)
DEVNULL = open(os.devnull, 'r+')
VALID_PROC_STATUSES = [getattr(psutil, x) for x in dir(psutil)
@@ -793,6 +792,7 @@ def check_net_address(addr, family):
def check_connection_ntuple(conn):
"""Check validity of a connection namedtuple."""
+ AF_UNIX = getattr(socket, "AF_UNIX", object())
valid_conn_states = [getattr(psutil, x) for x in dir(psutil) if
x.startswith('CONN_')]
assert conn[0] == conn.fd
@@ -869,6 +869,7 @@ def bind_unix_socket(type=socket.SOCK_STREAM, name=None, suffix="",
raise ValueError("name and suffix aregs are mutually exclusive")
assert not os.path.exists(name), name
sock = socket.socket(socket.AF_UNIX, type)
+ sock.settimeout(GLOBAL_TIMEOUT)
try:
sock.bind(name)
except Exception:
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py
index 683ac57c..78d01ae6 100755
--- a/psutil/tests/test_process.py
+++ b/psutil/tests/test_process.py
@@ -42,7 +42,6 @@ from psutil._compat import callable
from psutil._compat import long
from psutil._compat import PY3
from psutil._compat import unicode
-from psutil.tests import AF_UNIX
from psutil.tests import APPVEYOR
from psutil.tests import bind_unix_socket
from psutil.tests import call_until
@@ -1111,7 +1110,7 @@ class TestProcess(unittest.TestCase):
check_connection_ntuple(conn)
if conn.fd != -1: # != sunos and windows
self.assertEqual(conn.fd, sock.fileno())
- self.assertEqual(conn.family, AF_UNIX)
+ self.assertEqual(conn.family, socket.AF_UNIX)
self.assertEqual(conn.type, type)
self.assertEqual(conn.laddr, name)
if not SUNOS:
@@ -1448,10 +1447,9 @@ class TestProcess(unittest.TestCase):
pid = bytes(str(os.getpid()), 'ascii')
s.sendall(pid)
""" % unix_file)
- with contextlib.closing(socket.socket(socket.AF_UNIX)) as sock:
+ sock, _ = bind_unix_socket(name=unix_file)
+ with contextlib.closing(sock):
try:
- sock.settimeout(GLOBAL_TIMEOUT)
- sock.bind(unix_file)
sock.listen(1)
pyrun(src)
conn, _ = sock.accept()