mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Issue #28652: Make loop methods reject socket kinds they do not support.
This commit is contained in:
parent
d2fd3599ab
commit
a1a8b7d3d7
6 changed files with 139 additions and 24 deletions
|
@ -280,6 +280,33 @@ class SelectorEventLoopUnixSocketTests(test_utils.TestCase):
|
|||
'A UNIX Domain Stream.*was expected'):
|
||||
self.loop.run_until_complete(coro)
|
||||
|
||||
def test_create_unix_server_path_dgram(self):
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||
with sock:
|
||||
coro = self.loop.create_unix_server(lambda: None, path=None,
|
||||
sock=sock)
|
||||
with self.assertRaisesRegex(ValueError,
|
||||
'A UNIX Domain Stream.*was expected'):
|
||||
self.loop.run_until_complete(coro)
|
||||
|
||||
@unittest.skipUnless(hasattr(socket, 'SOCK_NONBLOCK'),
|
||||
'no socket.SOCK_NONBLOCK (linux only)')
|
||||
def test_create_unix_server_path_stream_bittype(self):
|
||||
sock = socket.socket(
|
||||
socket.AF_UNIX, socket.SOCK_STREAM | socket.SOCK_NONBLOCK)
|
||||
with tempfile.NamedTemporaryFile() as file:
|
||||
fn = file.name
|
||||
try:
|
||||
with sock:
|
||||
sock.bind(fn)
|
||||
coro = self.loop.create_unix_server(lambda: None, path=None,
|
||||
sock=sock)
|
||||
srv = self.loop.run_until_complete(coro)
|
||||
srv.close()
|
||||
self.loop.run_until_complete(srv.wait_closed())
|
||||
finally:
|
||||
os.unlink(fn)
|
||||
|
||||
def test_create_unix_connection_path_inetsock(self):
|
||||
sock = socket.socket()
|
||||
with sock:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue