From 1259ee3edb8ab121b2c02e435d716b23d0983590 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Mon, 20 Dec 2021 12:56:10 +0530 Subject: [PATCH 1/5] bpo-23819: Fix asyncio tests on python optimized mode --- Lib/test/test_asyncio/test_base_events.py | 3 ++- Lib/test/test_asyncio/test_proactor_events.py | 2 ++ Lib/test/test_asyncio/test_selector_events.py | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py index d812bc9edea571..1097ba6dd22e9d 100644 --- a/Lib/test/test_asyncio/test_base_events.py +++ b/Lib/test/test_asyncio/test_base_events.py @@ -1590,7 +1590,8 @@ def test_create_datagram_endpoint_no_addrinfo(self, m_socket): MyDatagramProto, local_addr=('localhost', 0)) self.assertRaises( OSError, self.loop.run_until_complete, coro) - + + @unittest.skipIf(sys.flags.optimize, "Assertions are disabled in optimized mode") def test_create_datagram_endpoint_addr_error(self): coro = self.loop.create_datagram_endpoint( MyDatagramProto, local_addr='localhost') diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py index 4c8906d531ce5c..45af8101a00932 100644 --- a/Lib/test/test_asyncio/test_proactor_events.py +++ b/Lib/test/test_asyncio/test_proactor_events.py @@ -77,6 +77,7 @@ def test_loop_reading_data(self): self.loop._proactor.recv_into.assert_called_with(self.sock, called_buf) self.protocol.data_received.assert_called_with(bytearray(buf)) + @unittest.skipIf(sys.flags.optimize, "Assertions are disabled in optimized mode") def test_loop_reading_no_data(self): res = self.loop.create_future() res.set_result(0) @@ -869,6 +870,7 @@ def test_datagram_loop_reading_data(self): self.protocol.datagram_received.assert_called_with(b'data', ('127.0.0.1', 12068)) close_transport(tr) + @unittest.skipIf(sys.flags.optimize, "Assertions are disabled in optimized mode") def test_datagram_loop_reading_no_data(self): res = self.loop.create_future() res.set_result((b'', ('127.0.0.1', 12068))) diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py index 1613c753c26ee5..b684fab2771f20 100644 --- a/Lib/test/test_asyncio/test_selector_events.py +++ b/Lib/test/test_asyncio/test_selector_events.py @@ -1,5 +1,6 @@ """Tests for selector_events.py""" +import sys import selectors import socket import unittest @@ -804,6 +805,7 @@ def test_write_ready_closing(self): self.sock.close.assert_called_with() self.protocol.connection_lost.assert_called_with(None) + @unittest.skipIf(sys.flags.optimize, "Assertions are disabled in optimized mode") def test_write_ready_no_data(self): transport = self.socket_transport() # This is an internal error. From 2e9318b97a71b938731dfb606ce81fab89cd8e8b Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 19 Dec 2021 08:44:33 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Misc/NEWS.d/next/Tests/2021-12-19-08-44-32.bpo-23819.9ueiII.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tests/2021-12-19-08-44-32.bpo-23819.9ueiII.rst diff --git a/Misc/NEWS.d/next/Tests/2021-12-19-08-44-32.bpo-23819.9ueiII.rst b/Misc/NEWS.d/next/Tests/2021-12-19-08-44-32.bpo-23819.9ueiII.rst new file mode 100644 index 00000000000000..4ef0fe6f6d5fa4 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2021-12-19-08-44-32.bpo-23819.9ueiII.rst @@ -0,0 +1 @@ +Fixed :mod:`asyncio` tests in python optimized mode. Patch by Kumar Aditya. \ No newline at end of file From 969f7615ea434a1bf1206a158ef64819b32deb67 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Tue, 21 Dec 2021 15:23:54 +0530 Subject: [PATCH 3/5] core review --- Lib/asyncio/base_events.py | 4 ++-- Lib/test/test_asyncio/test_base_events.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index cbf6d5db0a0023..56ea7ba44e2eac 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -1285,8 +1285,8 @@ async def create_datagram_endpoint(self, protocol_factory, addr_infos = {} # Using order preserving dict for idx, addr in ((0, local_addr), (1, remote_addr)): if addr is not None: - assert isinstance(addr, tuple) and len(addr) == 2, ( - '2-tuple is expected') + if not (isinstance(addr, tuple) and len(addr) == 2): + raise TypeError('2-tuple is expected') infos = await self._ensure_resolved( addr, family=family, type=socket.SOCK_DGRAM, diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py index 1097ba6dd22e9d..aefc59c0bb1589 100644 --- a/Lib/test/test_asyncio/test_base_events.py +++ b/Lib/test/test_asyncio/test_base_events.py @@ -1591,16 +1591,15 @@ def test_create_datagram_endpoint_no_addrinfo(self, m_socket): self.assertRaises( OSError, self.loop.run_until_complete, coro) - @unittest.skipIf(sys.flags.optimize, "Assertions are disabled in optimized mode") def test_create_datagram_endpoint_addr_error(self): coro = self.loop.create_datagram_endpoint( MyDatagramProto, local_addr='localhost') self.assertRaises( - AssertionError, self.loop.run_until_complete, coro) + TypeError, self.loop.run_until_complete, coro) coro = self.loop.create_datagram_endpoint( MyDatagramProto, local_addr=('localhost', 1, 2, 3)) self.assertRaises( - AssertionError, self.loop.run_until_complete, coro) + TypeError, self.loop.run_until_complete, coro) def test_create_datagram_endpoint_connect_err(self): self.loop.sock_connect = mock.Mock() From d5837b5a546f3b8d1f80d4e87c837ba85298f677 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 21 Dec 2021 11:59:21 +0200 Subject: [PATCH 4/5] Update Lib/test/test_asyncio/test_base_events.py --- Lib/test/test_asyncio/test_base_events.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py index aefc59c0bb1589..832f626ea69fd2 100644 --- a/Lib/test/test_asyncio/test_base_events.py +++ b/Lib/test/test_asyncio/test_base_events.py @@ -1590,7 +1590,6 @@ def test_create_datagram_endpoint_no_addrinfo(self, m_socket): MyDatagramProto, local_addr=('localhost', 0)) self.assertRaises( OSError, self.loop.run_until_complete, coro) - def test_create_datagram_endpoint_addr_error(self): coro = self.loop.create_datagram_endpoint( MyDatagramProto, local_addr='localhost') From eb7cecf953b8aba3498bf5ba06b4ed6aa744f0df Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 21 Dec 2021 12:00:24 +0200 Subject: [PATCH 5/5] Update test_base_events.py --- Lib/test/test_asyncio/test_base_events.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py index 832f626ea69fd2..5a8010344e83dc 100644 --- a/Lib/test/test_asyncio/test_base_events.py +++ b/Lib/test/test_asyncio/test_base_events.py @@ -1590,6 +1590,7 @@ def test_create_datagram_endpoint_no_addrinfo(self, m_socket): MyDatagramProto, local_addr=('localhost', 0)) self.assertRaises( OSError, self.loop.run_until_complete, coro) + def test_create_datagram_endpoint_addr_error(self): coro = self.loop.create_datagram_endpoint( MyDatagramProto, local_addr='localhost')