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

@ -19,7 +19,8 @@ except ImportError:
from unittest import TestCase, skipUnless
from test import support
from test.support import HOST, HOSTv6
from test.support import socket_helper
from test.support.socket_helper import HOST, HOSTv6
TIMEOUT = support.LOOPBACK_TIMEOUT
DEFAULT_ENCODING = 'utf-8'
@ -751,7 +752,7 @@ class TestFTPClass(TestCase):
def test_source_address(self):
self.client.quit()
port = support.find_unused_port()
port = socket_helper.find_unused_port()
try:
self.client.connect(self.server.host, self.server.port,
source_address=(HOST, port))
@ -763,7 +764,7 @@ class TestFTPClass(TestCase):
raise
def test_source_address_passive_connection(self):
port = support.find_unused_port()
port = socket_helper.find_unused_port()
self.client.source_address = (HOST, port)
try:
with self.client.transfercmd('list') as sock:
@ -816,7 +817,7 @@ class TestFTPClass(TestCase):
self.assertEqual(DEFAULT_ENCODING, client.encoding)
@skipUnless(support.IPV6_ENABLED, "IPv6 not enabled")
@skipUnless(socket_helper.IPV6_ENABLED, "IPv6 not enabled")
class TestIPv6Environment(TestCase):
def setUp(self):
@ -1007,7 +1008,7 @@ class TestTimeouts(TestCase):
self.evt = threading.Event()
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.settimeout(20)
self.port = support.bind_port(self.sock)
self.port = socket_helper.bind_port(self.sock)
self.server_thread = threading.Thread(target=self.server)
self.server_thread.daemon = True
self.server_thread.start()