summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_socket.py
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-09-17 20:22:06 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-09-17 20:22:06 (GMT)
commitbcfb35f80d9d1f87d9fa6993c1d3bc35dd5db865 (patch)
tree8210a1031ab648ac60c6fa391f89e8964cec1bb2 /Lib/test/test_socket.py
parent9a1c91a10d16b603d57fbc97bc54699acee3f052 (diff)
downloadcpython-bcfb35f80d9d1f87d9fa6993c1d3bc35dd5db865.zip
cpython-bcfb35f80d9d1f87d9fa6993c1d3bc35dd5db865.tar.gz
cpython-bcfb35f80d9d1f87d9fa6993c1d3bc35dd5db865.tar.bz2
Issue #26384: Fix UnboundLocalError in socket._sendfile_use_sendfile
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r--Lib/test/test_socket.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 4b047ee..c5975c8 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -1447,6 +1447,25 @@ class GeneralModuleTests(unittest.TestCase):
self.assertEqual(s.family, 42424)
self.assertEqual(s.type, 13331)
+ @unittest.skipUnless(hasattr(os, 'sendfile'), 'test needs os.sendfile()')
+ def test__sendfile_use_sendfile(self):
+ class File:
+ def __init__(self, fd):
+ self.fd = fd
+
+ def fileno(self):
+ return self.fd
+ with socket.socket() as sock:
+ fd = os.open(os.curdir, os.O_RDONLY)
+ os.close(fd)
+ with self.assertRaises(socket._GiveupOnSendfile):
+ sock._sendfile_use_sendfile(File(fd))
+ with self.assertRaises(OverflowError):
+ sock._sendfile_use_sendfile(File(2**1000))
+ with self.assertRaises(TypeError):
+ sock._sendfile_use_sendfile(File(None))
+
+
@unittest.skipUnless(HAVE_SOCKET_CAN, 'SocketCan required for this test.')
class BasicCANTest(unittest.TestCase):