summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-05-10 21:37:42 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-05-10 21:37:42 (GMT)
commit74b4885cc9e57dd0526da0bf8b84040f8e26bbc2 (patch)
treeb7de26bfbbb30a732ff238f43b5f03bdfd2ab4a0
parent316e02be83bf871e21d04aabb7d225333840864f (diff)
parentccc87b53dba9ca3558ce8d333d9eb9274c16b0f4 (diff)
downloadcpython-74b4885cc9e57dd0526da0bf8b84040f8e26bbc2.zip
cpython-74b4885cc9e57dd0526da0bf8b84040f8e26bbc2.tar.gz
cpython-74b4885cc9e57dd0526da0bf8b84040f8e26bbc2.tar.bz2
Issue #12054: use support.find_unused_port() instead of reinventing the wheel
-rw-r--r--Lib/test/test_socket.py18
1 files changed, 2 insertions, 16 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 3efe1bb..2602b22 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -567,23 +567,9 @@ class GeneralModuleTests(unittest.TestCase):
# XXX The following don't test module-level functionality...
- def _get_unused_port(self, bind_address='0.0.0.0'):
- """Use a temporary socket to elicit an unused ephemeral port.
-
- Args:
- bind_address: Hostname or IP address to search for a port on.
-
- Returns: A most likely to be unused port.
- """
- tempsock = socket.socket()
- tempsock.bind((bind_address, 0))
- host, port = tempsock.getsockname()
- tempsock.close()
- return port
-
def testSockName(self):
# Testing getsockname()
- port = self._get_unused_port()
+ port = support.find_unused_port()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.addCleanup(sock.close)
sock.bind(("0.0.0.0", port))
@@ -632,7 +618,7 @@ class GeneralModuleTests(unittest.TestCase):
def test_getsockaddrarg(self):
host = '0.0.0.0'
- port = self._get_unused_port(bind_address=host)
+ port = support.find_unused_port()
big_port = port + 65536
neg_port = port - 65536
sock = socket.socket()