Skip to content

Commit 558aa30

Browse files
author
Yury Selivanov
authored
bpo-32357: Fix tests in refleak mode (#4989)
1 parent c0919c2 commit 558aa30

2 files changed

Lines changed: 32 additions & 23 deletions

File tree

Lib/test/test_asyncio/test_events.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ async def doit():
6666
return loop.run_until_complete(doit())
6767

6868

69+
class CoroLike:
70+
def send(self, v):
71+
pass
72+
73+
def throw(self, *exc):
74+
pass
75+
76+
def close(self):
77+
pass
78+
79+
def __await__(self):
80+
pass
81+
82+
6983
ONLYCERT = data_file('ssl_cert.pem')
7084
ONLYKEY = data_file('ssl_key.pem')
7185
SIGNED_CERTFILE = data_file('keycert3.pem')
@@ -2365,20 +2379,7 @@ def test_coroutine_like_object_debug_formatting(self):
23652379
# collections.abc.Coroutine, but lack cr_core or gi_code attributes
23662380
# (such as ones compiled with Cython).
23672381

2368-
class Coro:
2369-
def send(self, v):
2370-
pass
2371-
2372-
def throw(self, *exc):
2373-
pass
2374-
2375-
def close(self):
2376-
pass
2377-
2378-
def __await__(self):
2379-
pass
2380-
2381-
coro = Coro()
2382+
coro = CoroLike()
23822383
coro.__name__ = 'AAA'
23832384
self.assertTrue(asyncio.iscoroutine(coro))
23842385
self.assertEqual(coroutines._format_coroutine(coro), 'AAA()')
@@ -2389,10 +2390,10 @@ def __await__(self):
23892390
coro.cr_running = True
23902391
self.assertEqual(coroutines._format_coroutine(coro), 'BBB() running')
23912392

2392-
coro = Coro()
2393+
coro = CoroLike()
23932394
# Some coroutines might not have '__name__', such as
23942395
# built-in async_gen.asend().
2395-
self.assertEqual(coroutines._format_coroutine(coro), 'Coro()')
2396+
self.assertEqual(coroutines._format_coroutine(coro), 'CoroLike()')
23962397

23972398

23982399
class TimerTests(unittest.TestCase):

Lib/test/test_asyncio/test_pep492.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@
1010
from test.test_asyncio import utils as test_utils
1111

1212

13+
# Test that asyncio.iscoroutine() uses collections.abc.Coroutine
14+
class FakeCoro:
15+
def send(self, value):
16+
pass
17+
18+
def throw(self, typ, val=None, tb=None):
19+
pass
20+
21+
def close(self):
22+
pass
23+
24+
def __await__(self):
25+
yield
26+
27+
1328
class BaseTest(test_utils.TestCase):
1429

1530
def setUp(self):
@@ -99,13 +114,6 @@ async def foo(): pass
99114
finally:
100115
f.close() # silence warning
101116

102-
# Test that asyncio.iscoroutine() uses collections.abc.Coroutine
103-
class FakeCoro:
104-
def send(self, value): pass
105-
def throw(self, typ, val=None, tb=None): pass
106-
def close(self): pass
107-
def __await__(self): yield
108-
109117
self.assertTrue(asyncio.iscoroutine(FakeCoro()))
110118

111119
def test_iscoroutinefunction(self):

0 commit comments

Comments
 (0)