From d6c77cd63ac0c541df5df1b9346d1ccb75ce40fd Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Mon, 24 Oct 2022 08:02:50 +0000 Subject: [PATCH] fix check on other platforms --- Lib/asyncio/selector_events.py | 6 +++++- Lib/test/test_asyncio/test_selector_events.py | 17 +++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index 4b36c194cb3c3c..b96cc64f7d1772 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -33,7 +33,11 @@ HAVE_SENDMSG = hasattr(socket.socket, 'sendmsg') if HAVE_SENDMSG: - SC_IOV_MAX = os.sysconf('SC_IOV_MAX') + try: + SC_IOV_MAX = os.sysconf('SC_IOV_MAX') + except OSError: + # Fallback to send + HAVE_SENDMSG = False def _test_selector_event(selector, fd, event): # Test if the selector is monitoring 'event' events diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py index b20e4bce17c27c..8075312026342b 100644 --- a/Lib/test/test_asyncio/test_selector_events.py +++ b/Lib/test/test_asyncio/test_selector_events.py @@ -1,24 +1,25 @@ """Tests for selector_events.py""" import collections -import sys import selectors import socket +import sys import unittest +from asyncio import selector_events from unittest import mock + try: import ssl except ImportError: ssl = None import asyncio -from asyncio.selector_events import BaseSelectorEventLoop -from asyncio.selector_events import _SelectorTransport -from asyncio.selector_events import _SelectorSocketTransport -from asyncio.selector_events import _SelectorDatagramTransport +from asyncio.selector_events import (BaseSelectorEventLoop, + _SelectorDatagramTransport, + _SelectorSocketTransport, + _SelectorTransport) from test.test_asyncio import utils as test_utils - MOCK_ANY = mock.ANY @@ -746,7 +747,7 @@ def test_write_sendmsg_no_data(self): self.assertFalse(self.sock.sendmsg.called) self.assertEqual(list_to_buffer([b'data']), transport._buffer) - @unittest.skipUnless(hasattr(socket.socket, 'sendmsg'), 'no sendmsg') + @unittest.skipUnless(selector_events.HAVE_SENDMSG, 'no sendmsg') def test_write_sendmsg_full(self): data = memoryview(b'data') self.sock.sendmsg = mock.Mock() @@ -759,7 +760,7 @@ def test_write_sendmsg_full(self): self.assertTrue(self.sock.sendmsg.called) self.assertFalse(self.loop.writers) - @unittest.skipUnless(hasattr(socket.socket, 'sendmsg'), 'no sendmsg') + @unittest.skipUnless(selector_events.HAVE_SENDMSG, 'no sendmsg') def test_write_sendmsg_partial(self): data = memoryview(b'data')