Skip to content

Commit 0722905

Browse files
[3.9] bpo-23819: Fix asyncio tests on python optimized mode (GH-30195) (GH-30265)
(cherry picked from commit a23ab7b) Co-authored-by: Kumar Aditya <[email protected]>
1 parent f1f54c8 commit 0722905

File tree

5 files changed

+9
-4
lines changed

5 files changed

+9
-4
lines changed

Lib/asyncio/base_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,8 +1290,8 @@ async def create_datagram_endpoint(self, protocol_factory,
12901290
addr_infos = {} # Using order preserving dict
12911291
for idx, addr in ((0, local_addr), (1, remote_addr)):
12921292
if addr is not None:
1293-
assert isinstance(addr, tuple) and len(addr) == 2, (
1294-
'2-tuple is expected')
1293+
if not (isinstance(addr, tuple) and len(addr) == 2):
1294+
raise TypeError('2-tuple is expected')
12951295

12961296
infos = await self._ensure_resolved(
12971297
addr, family=family, type=socket.SOCK_DGRAM,

Lib/test/test_asyncio/test_base_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,11 +1592,11 @@ def test_create_datagram_endpoint_addr_error(self):
15921592
coro = self.loop.create_datagram_endpoint(
15931593
MyDatagramProto, local_addr='localhost')
15941594
self.assertRaises(
1595-
AssertionError, self.loop.run_until_complete, coro)
1595+
TypeError, self.loop.run_until_complete, coro)
15961596
coro = self.loop.create_datagram_endpoint(
15971597
MyDatagramProto, local_addr=('localhost', 1, 2, 3))
15981598
self.assertRaises(
1599-
AssertionError, self.loop.run_until_complete, coro)
1599+
TypeError, self.loop.run_until_complete, coro)
16001600

16011601
def test_create_datagram_endpoint_connect_err(self):
16021602
self.loop.sock_connect = mock.Mock()

Lib/test/test_asyncio/test_proactor_events.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def test_loop_reading_data(self):
7272
self.loop._proactor.recv.assert_called_with(self.sock, 32768)
7373
self.protocol.data_received.assert_called_with(b'data')
7474

75+
@unittest.skipIf(sys.flags.optimize, "Assertions are disabled in optimized mode")
7576
def test_loop_reading_no_data(self):
7677
res = self.loop.create_future()
7778
res.set_result(b'')
@@ -853,6 +854,7 @@ def test_datagram_loop_reading_data(self):
853854
self.protocol.datagram_received.assert_called_with(b'data', ('127.0.0.1', 12068))
854855
close_transport(tr)
855856

857+
@unittest.skipIf(sys.flags.optimize, "Assertions are disabled in optimized mode")
856858
def test_datagram_loop_reading_no_data(self):
857859
res = self.loop.create_future()
858860
res.set_result((b'', ('127.0.0.1', 12068)))

Lib/test/test_asyncio/test_selector_events.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for selector_events.py"""
22

3+
import sys
34
import selectors
45
import socket
56
import unittest
@@ -804,6 +805,7 @@ def test_write_ready_closing(self):
804805
self.sock.close.assert_called_with()
805806
self.protocol.connection_lost.assert_called_with(None)
806807

808+
@unittest.skipIf(sys.flags.optimize, "Assertions are disabled in optimized mode")
807809
def test_write_ready_no_data(self):
808810
transport = self.socket_transport()
809811
# This is an internal error.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed :mod:`asyncio` tests in python optimized mode. Patch by Kumar Aditya.

0 commit comments

Comments
 (0)