]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] bpo-23819: Fix asyncio tests on python optimized mode (GH-30195) (GH-30265)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 26 Dec 2021 11:54:18 +0000 (03:54 -0800)
committerGitHub <noreply@github.com>
Sun, 26 Dec 2021 11:54:18 +0000 (13:54 +0200)
(cherry picked from commit a23ab7b6d8b3ae3a47747c0c4bceb2370cc48dcc)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Lib/asyncio/base_events.py
Lib/test/test_asyncio/test_base_events.py
Lib/test/test_asyncio/test_proactor_events.py
Lib/test/test_asyncio/test_selector_events.py
Misc/NEWS.d/next/Tests/2021-12-19-08-44-32.bpo-23819.9ueiII.rst [new file with mode: 0644]

index bb2f99150b115aa4706cb2aa70672ab7b073ad89..8c1fb496948750e5adb312503591bce61974974b 100644 (file)
@@ -1290,8 +1290,8 @@ class BaseEventLoop(events.AbstractEventLoop):
                 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,
index 533d5cc7f503827b970dbc8412b0431b127f2c19..4886da28bdf14235df26c9fce928866ea7244ae5 100644 (file)
@@ -1592,11 +1592,11 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
         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()
index 451f86ae0274fd6a10059c98addacae88a1431da..59d5e5b6ccb631a42ec6d6958dfe9b0ca10301fe 100644 (file)
@@ -72,6 +72,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
         self.loop._proactor.recv.assert_called_with(self.sock, 32768)
         self.protocol.data_received.assert_called_with(b'data')
 
+    @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(b'')
@@ -853,6 +854,7 @@ class BaseProactorEventLoopTests(test_utils.TestCase):
         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)))
index 1613c753c26ee56b4e7acee19e31e0fa6c19372a..b684fab2771f20d6edbaaaabfb8c6d7f077092df 100644 (file)
@@ -1,5 +1,6 @@
 """Tests for selector_events.py"""
 
+import sys
 import selectors
 import socket
 import unittest
@@ -804,6 +805,7 @@ class SelectorSocketTransportTests(test_utils.TestCase):
         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.
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 (file)
index 0000000..4ef0fe6
--- /dev/null
@@ -0,0 +1 @@
+Fixed :mod:`asyncio` tests in python optimized mode. Patch by Kumar Aditya.
\ No newline at end of file