diff options
| -rw-r--r-- | psutil/tests/__init__.py | 10 | ||||
| -rw-r--r-- | psutil/tests/test_connections.py | 4 | ||||
| -rwxr-xr-x | psutil/tests/test_misc.py | 7 |
3 files changed, 10 insertions, 11 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index fa01ea4c..0faecc86 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -816,15 +816,15 @@ def bind_unix_socket(name, type=socket.SOCK_STREAM): return sock -def inet_socketpair(family, type, addr=("", 0)): - """Build a pair of INET sockets connected to each other. +def tcp_socketpair(family, addr=("", 0)): + """Build a pair of TCP sockets connected to each other. Return a (server, client) tuple. """ - with contextlib.closing(socket.socket(family, type)) as ll: + with contextlib.closing(socket.socket(family, SOCK_STREAM)) as ll: ll.bind(addr) ll.listen(10) addr = ll.getsockname() - c = socket.socket(family, type) + c = socket.socket(family, SOCK_STREAM) try: c.connect(addr) caddr = c.getsockname() @@ -844,7 +844,7 @@ def unix_socketpair(name): the same UNIX file name. Return a (server, client) tuple. """ - assert psutil.POSIX, "not a POSIX system" + assert psutil.POSIX server = bind_unix_socket(name, type=socket.SOCK_STREAM) server.setblocking(0) client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) diff --git a/psutil/tests/test_connections.py b/psutil/tests/test_connections.py index cb5807c4..b30c65e2 100644 --- a/psutil/tests/test_connections.py +++ b/psutil/tests/test_connections.py @@ -29,12 +29,12 @@ from psutil.tests import bind_socket from psutil.tests import bind_unix_socket from psutil.tests import check_connection_ntuple from psutil.tests import get_free_port -from psutil.tests import inet_socketpair from psutil.tests import pyrun from psutil.tests import reap_children from psutil.tests import run_test_module_by_name from psutil.tests import safe_rmpath from psutil.tests import skip_on_access_denied +from psutil.tests import tcp_socketpair from psutil.tests import TESTFN from psutil.tests import unittest from psutil.tests import unix_socket_path @@ -203,7 +203,7 @@ class TestConnectedSocketPairs(Base, unittest.TestCase): def test_tcp(self): addr = ("127.0.0.1", get_free_port()) - server, client = inet_socketpair(AF_INET, SOCK_STREAM, addr=addr) + server, client = tcp_socketpair(AF_INET, addr=addr) with nested(closing(server), closing(client)): cons = psutil.Process().connections(kind='all') server_conn, client_conn = self.distinguish_tcp_socks(cons, addr) diff --git a/psutil/tests/test_misc.py b/psutil/tests/test_misc.py index 22dfc7d2..a0a7a0b1 100755 --- a/psutil/tests/test_misc.py +++ b/psutil/tests/test_misc.py @@ -37,7 +37,6 @@ from psutil.tests import create_proc_children_pair from psutil.tests import get_free_port from psutil.tests import get_test_subprocess from psutil.tests import importlib -from psutil.tests import inet_socketpair from psutil.tests import mock from psutil.tests import reap_children from psutil.tests import retry @@ -46,6 +45,7 @@ from psutil.tests import run_test_module_by_name from psutil.tests import safe_rmpath from psutil.tests import SCRIPTS_DIR from psutil.tests import sh +from psutil.tests import tcp_socketpair from psutil.tests import TESTFN from psutil.tests import TOX from psutil.tests import TRAVIS @@ -701,10 +701,9 @@ class TestNetUtils(unittest.TestCase): with contextlib.closing(sock): self.assertEqual(sock.type, socket.SOCK_DGRAM) - def test_inet_socketpair(self): + def tcp_tcp_socketpair(self): addr = ("127.0.0.1", get_free_port()) - server, client = inet_socketpair( - socket.AF_INET, socket.SOCK_STREAM, addr=addr) + server, client = tcp_socketpair(socket.AF_INET, addr=addr) with contextlib.closing(server): with contextlib.closing(client): # Ensure they are connected and the positions are |
