Skip to content

Commit a23ab7b

Browse files
bpo-23819: Fix asyncio tests on python optimized mode (GH-30195)
1 parent f9a4352 commit a23ab7b

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
@@ -1285,8 +1285,8 @@ async def create_datagram_endpoint(self, protocol_factory,
12851285
addr_infos = {} # Using order preserving dict
12861286
for idx, addr in ((0, local_addr), (1, remote_addr)):
12871287
if addr is not None:
1288-
assert isinstance(addr, tuple) and len(addr) == 2, (
1289-
'2-tuple is expected')
1288+
if not (isinstance(addr, tuple) and len(addr) == 2):
1289+
raise TypeError('2-tuple is expected')
12901290

12911291
infos = await self._ensure_resolved(
12921292
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
@@ -1603,11 +1603,11 @@ def test_create_datagram_endpoint_addr_error(self):
16031603
coro = self.loop.create_datagram_endpoint(
16041604
MyDatagramProto, local_addr='localhost')
16051605
self.assertRaises(
1606-
AssertionError, self.loop.run_until_complete, coro)
1606+
TypeError, self.loop.run_until_complete, coro)
16071607
coro = self.loop.create_datagram_endpoint(
16081608
MyDatagramProto, local_addr=('localhost', 1, 2, 3))
16091609
self.assertRaises(
1610-
AssertionError, self.loop.run_until_complete, coro)
1610+
TypeError, self.loop.run_until_complete, coro)
16111611

16121612
def test_create_datagram_endpoint_connect_err(self):
16131613
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
@@ -77,6 +77,7 @@ def test_loop_reading_data(self):
7777
self.loop._proactor.recv_into.assert_called_with(self.sock, called_buf)
7878
self.protocol.data_received.assert_called_with(bytearray(buf))
7979

80+
@unittest.skipIf(sys.flags.optimize, "Assertions are disabled in optimized mode")
8081
def test_loop_reading_no_data(self):
8182
res = self.loop.create_future()
8283
res.set_result(0)
@@ -869,6 +870,7 @@ def test_datagram_loop_reading_data(self):
869870
self.protocol.datagram_received.assert_called_with(b'data', ('127.0.0.1', 12068))
870871
close_transport(tr)
871872

873+
@unittest.skipIf(sys.flags.optimize, "Assertions are disabled in optimized mode")
872874
def test_datagram_loop_reading_no_data(self):
873875
res = self.loop.create_future()
874876
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)