summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2018-01-27 08:54:13 (GMT)
committerGitHub <noreply@github.com>2018-01-27 08:54:13 (GMT)
commitd0e31b980f18101738d0ec518cb991a5fb73fe93 (patch)
treea8b9a117d4eca90bc3dc421bcec44e44691d6a14 /Lib
parent2f050c7e1b36bf641e7023f7b28b451454c6b98a (diff)
downloadcpython-d0e31b980f18101738d0ec518cb991a5fb73fe93.zip
cpython-d0e31b980f18101738d0ec518cb991a5fb73fe93.tar.gz
cpython-d0e31b980f18101738d0ec518cb991a5fb73fe93.tar.bz2
bpo-32454: socket closefd (#5048)
Add close(fd) function to the socket module Signed-off-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_socket.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 22d142c..275384c 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -1519,6 +1519,22 @@ class GeneralModuleTests(unittest.TestCase):
self.assertRaises(ValueError, fp.writable)
self.assertRaises(ValueError, fp.seekable)
+ def test_socket_close(self):
+ sock = socket.socket()
+ try:
+ sock.bind((HOST, 0))
+ socket.close(sock.fileno())
+ with self.assertRaises(OSError):
+ sock.listen(1)
+ finally:
+ with self.assertRaises(OSError):
+ # sock.close() fails with EBADF
+ sock.close()
+ with self.assertRaises(TypeError):
+ socket.close(None)
+ with self.assertRaises(OSError):
+ socket.close(-1)
+
def test_makefile_mode(self):
for mode in 'r', 'rb', 'rw', 'w', 'wb':
with self.subTest(mode=mode):