bpo-40275: Avoid importing socket in test.support (GH-19603)

* Move socket related functions from test.support to socket_helper.
* Import socket, nntplib and urllib.error lazily in transient_internet().
* Remove importing multiprocess.
This commit is contained in:
Serhiy Storchaka 2020-04-25 10:06:29 +03:00 committed by GitHub
parent 3c8a5b459d
commit 16994912c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 472 additions and 429 deletions

View file

@ -3,6 +3,7 @@
import functools
import unittest
from test import support
from test.support import socket_helper
# This requires the 'network' resource as given on the regrtest command line.
skip_expected = not support.is_resource_enabled('network')
@ -110,7 +111,7 @@ class TimeoutTestCase(unittest.TestCase):
# solution.
fuzz = 2.0
localhost = support.HOST
localhost = socket_helper.HOST
def setUp(self):
raise NotImplementedError()
@ -240,14 +241,14 @@ class TCPTimeoutTestCase(TimeoutTestCase):
def testAcceptTimeout(self):
# Test accept() timeout
support.bind_port(self.sock, self.localhost)
socket_helper.bind_port(self.sock, self.localhost)
self.sock.listen()
self._sock_operation(1, 1.5, 'accept')
def testSend(self):
# Test send() timeout
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
support.bind_port(serv, self.localhost)
socket_helper.bind_port(serv, self.localhost)
serv.listen()
self.sock.connect(serv.getsockname())
# Send a lot of data in order to bypass buffering in the TCP stack.
@ -256,7 +257,7 @@ class TCPTimeoutTestCase(TimeoutTestCase):
def testSendto(self):
# Test sendto() timeout
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
support.bind_port(serv, self.localhost)
socket_helper.bind_port(serv, self.localhost)
serv.listen()
self.sock.connect(serv.getsockname())
# The address argument is ignored since we already connected.
@ -266,7 +267,7 @@ class TCPTimeoutTestCase(TimeoutTestCase):
def testSendall(self):
# Test sendall() timeout
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
support.bind_port(serv, self.localhost)
socket_helper.bind_port(serv, self.localhost)
serv.listen()
self.sock.connect(serv.getsockname())
# Send a lot of data in order to bypass buffering in the TCP stack.
@ -285,7 +286,7 @@ class UDPTimeoutTestCase(TimeoutTestCase):
def testRecvfromTimeout(self):
# Test recvfrom() timeout
# Prevent "Address already in use" socket exceptions
support.bind_port(self.sock, self.localhost)
socket_helper.bind_port(self.sock, self.localhost)
self._sock_operation(1, 1.5, 'recvfrom', 1024)