aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_socket.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r--Lib/test/test_socket.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index ace97ce0cbe..3dd67b2a2ab 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -2,8 +2,9 @@ import unittest
from unittest import mock
from test import support
from test.support import (
- is_apple, os_helper, refleak_helper, socket_helper, threading_helper
+ cpython_only, is_apple, os_helper, refleak_helper, socket_helper, threading_helper
)
+from test.support.import_helper import ensure_lazy_imports
import _thread as thread
import array
import contextlib
@@ -257,6 +258,12 @@ HAVE_SOCKET_HYPERV = _have_socket_hyperv()
# Size in bytes of the int type
SIZEOF_INT = array.array("i").itemsize
+class TestLazyImport(unittest.TestCase):
+ @cpython_only
+ def test_lazy_import(self):
+ ensure_lazy_imports("socket", {"array", "selectors"})
+
+
class SocketTCPTest(unittest.TestCase):
def setUp(self):
@@ -1078,9 +1085,7 @@ class GeneralModuleTests(unittest.TestCase):
'IPV6_USE_MIN_MTU',
}
for opt in opts:
- self.assertTrue(
- hasattr(socket, opt), f"Missing RFC3542 socket option '{opt}'"
- )
+ self.assertHasAttr(socket, opt)
def testHostnameRes(self):
# Testing hostname resolution mechanisms
@@ -1586,11 +1591,11 @@ class GeneralModuleTests(unittest.TestCase):
@unittest.skipUnless(os.name == "nt", "Windows specific")
def test_sock_ioctl(self):
- self.assertTrue(hasattr(socket.socket, 'ioctl'))
- self.assertTrue(hasattr(socket, 'SIO_RCVALL'))
- self.assertTrue(hasattr(socket, 'RCVALL_ON'))
- self.assertTrue(hasattr(socket, 'RCVALL_OFF'))
- self.assertTrue(hasattr(socket, 'SIO_KEEPALIVE_VALS'))
+ self.assertHasAttr(socket.socket, 'ioctl')
+ self.assertHasAttr(socket, 'SIO_RCVALL')
+ self.assertHasAttr(socket, 'RCVALL_ON')
+ self.assertHasAttr(socket, 'RCVALL_OFF')
+ self.assertHasAttr(socket, 'SIO_KEEPALIVE_VALS')
s = socket.socket()
self.addCleanup(s.close)
self.assertRaises(ValueError, s.ioctl, -1, None)
@@ -6075,10 +6080,10 @@ class UDPLITETimeoutTest(SocketUDPLITETest):
class TestExceptions(unittest.TestCase):
def testExceptionTree(self):
- self.assertTrue(issubclass(OSError, Exception))
- self.assertTrue(issubclass(socket.herror, OSError))
- self.assertTrue(issubclass(socket.gaierror, OSError))
- self.assertTrue(issubclass(socket.timeout, OSError))
+ self.assertIsSubclass(OSError, Exception)
+ self.assertIsSubclass(socket.herror, OSError)
+ self.assertIsSubclass(socket.gaierror, OSError)
+ self.assertIsSubclass(socket.timeout, OSError)
self.assertIs(socket.error, OSError)
self.assertIs(socket.timeout, TimeoutError)