Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions Lib/test/test_coroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -1981,27 +1981,33 @@ def wrap(gen):

with self.assertWarns(DeprecationWarning):
sys.set_coroutine_wrapper(wrap)
self.assertIs(sys.get_coroutine_wrapper(), wrap)
with self.assertWarns(DeprecationWarning):
self.assertIs(sys.get_coroutine_wrapper(), wrap)
try:
f = foo()
self.assertTrue(wrapped)

self.assertEqual(run_async(f), ([], 'spam'))
finally:
sys.set_coroutine_wrapper(None)
with self.assertWarns(DeprecationWarning):
sys.set_coroutine_wrapper(None)

self.assertIsNone(sys.get_coroutine_wrapper())
with self.assertWarns(DeprecationWarning):
self.assertIsNone(sys.get_coroutine_wrapper())

wrapped = None
with silence_coro_gc():
foo()
self.assertFalse(wrapped)

def test_set_wrapper_2(self):
self.assertIsNone(sys.get_coroutine_wrapper())
with self.assertWarns(DeprecationWarning):
self.assertIsNone(sys.get_coroutine_wrapper())
with self.assertRaisesRegex(TypeError, "callable expected, got int"):
sys.set_coroutine_wrapper(1)
self.assertIsNone(sys.get_coroutine_wrapper())
with self.assertWarns(DeprecationWarning):
sys.set_coroutine_wrapper(1)
with self.assertWarns(DeprecationWarning):
self.assertIsNone(sys.get_coroutine_wrapper())

def test_set_wrapper_3(self):
async def foo():
Expand All @@ -2012,7 +2018,8 @@ async def wrap(coro):
return await coro
return wrap(coro)

sys.set_coroutine_wrapper(wrapper)
with self.assertWarns(DeprecationWarning):
sys.set_coroutine_wrapper(wrapper)
try:
with silence_coro_gc(), self.assertRaisesRegex(
RuntimeError,
Expand All @@ -2021,7 +2028,8 @@ async def wrap(coro):

foo()
finally:
sys.set_coroutine_wrapper(None)
with self.assertWarns(DeprecationWarning):
sys.set_coroutine_wrapper(None)

def test_set_wrapper_4(self):
@types.coroutine
Expand All @@ -2034,15 +2042,17 @@ def wrap(gen):
wrapped = gen
return gen

sys.set_coroutine_wrapper(wrap)
with self.assertWarns(DeprecationWarning):
sys.set_coroutine_wrapper(wrap)
try:
foo()
self.assertIs(
wrapped, None,
"generator-based coroutine was wrapped via "
"sys.set_coroutine_wrapper")
finally:
sys.set_coroutine_wrapper(None)
with self.assertWarns(DeprecationWarning):
sys.set_coroutine_wrapper(None)


class OriginTrackingTest(unittest.TestCase):
Expand Down