From bcd5ab837a770baea8f946674135ef36fe5891cd Mon Sep 17 00:00:00 2001 From: Alexey Shamrin Date: Tue, 5 Jan 2021 10:54:36 +0200 Subject: [PATCH] Revert "de-`loop=loop`-ification required for for Python 3.10+" This reverts (cherry-picked) commits 8930bf284d937a3709bb99fd001b5d260cdde99c and d1051b0efa410607e20cf9d2037913104b7f39fa. We will do the de-`loop=`-ification in PR #94. --- tests/aiotest/test_coroutine.py | 6 +++--- tests/interop/test_adapter.py | 14 +++++++------- tests/interop/test_calls.py | 26 +++++++++++++------------- tests/test_aio_subprocess.py | 8 ++++---- tests/test_misc.py | 4 ++-- trio_asyncio/_adapter.py | 2 +- trio_asyncio/_util.py | 2 +- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/tests/aiotest/test_coroutine.py b/tests/aiotest/test_coroutine.py index 557d1afe..0ab30549 100644 --- a/tests/aiotest/test_coroutine.py +++ b/tests/aiotest/test_coroutine.py @@ -7,7 +7,7 @@ async def hello_world(asyncio, result, delay, loop): result.append("Hello") # retrieve the event loop from the policy - await asyncio.sleep(delay) + await asyncio.sleep(delay, loop=loop) result.append('World') return "." @@ -17,7 +17,7 @@ class TestCoroutine(aiotest.TestCase): async def test_hello_world(self, loop, config): result = [] coro = hello_world(config.asyncio, result, 0.001, loop) - await loop.run_aio_coroutine(config.asyncio.ensure_future(coro)) + await loop.run_aio_coroutine(config.asyncio.ensure_future(coro, loop=loop)) assert result == ['Hello', 'World'] @pytest.mark.trio @@ -37,7 +37,7 @@ async def run_hello_world(self, loop, config): @pytest.mark.trio async def test_waiter(self, loop, config): async def waiter(asyncio, hello_world, result): - fut = asyncio.Future() + fut = asyncio.Future(loop=loop) loop.call_soon(fut.set_result, "Future") value = await fut diff --git a/tests/interop/test_adapter.py b/tests/interop/test_adapter.py index f6679694..0c8bf48b 100644 --- a/tests/interop/test_adapter.py +++ b/tests/interop/test_adapter.py @@ -65,25 +65,25 @@ async def dly_asyncio_depr(self): async def dly_asyncio_adapted(self): if sys.version_info >= (3, 7): assert sniffio.current_async_library() == "asyncio" - await asyncio.sleep(0.01) + await asyncio.sleep(0.01, loop=self.loop) self.flag |= 1 return 4 async def dly_asyncio(self, do_test=True): if do_test and sys.version_info >= (3, 7): assert sniffio.current_async_library() == "asyncio" - await asyncio.sleep(0.01) + await asyncio.sleep(0.01, loop=self.loop) self.flag |= 1 return 4 async def iter_asyncio(self, do_test=True): if do_test and sys.version_info >= (3, 7): assert sniffio.current_async_library() == "asyncio" - await asyncio.sleep(0.01) + await asyncio.sleep(0.01, loop=self.loop) yield 1 - await asyncio.sleep(0.01) + await asyncio.sleep(0.01, loop=self.loop) yield 2 - await asyncio.sleep(0.01) + await asyncio.sleep(0.01, loop=self.loop) self.flag |= 1 async def iter_trio(self): @@ -98,10 +98,10 @@ async def iter_trio(self): @asynccontextmanager async def ctx_asyncio(self): - await asyncio.sleep(0.01) + await asyncio.sleep(0.01, loop=self.loop) self.flag |= 1 yield self - await asyncio.sleep(0.01) + await asyncio.sleep(0.01, loop=self.loop) self.flag |= 2 @asynccontextmanager diff --git a/tests/interop/test_calls.py b/tests/interop/test_calls.py index bfda5fd5..ef8dbfac 100644 --- a/tests/interop/test_calls.py +++ b/tests/interop/test_calls.py @@ -48,7 +48,7 @@ async def __aenter__(self): self.parent.did_it = 1 if sys.version_info >= (3, 7): assert sniffio.current_async_library() == "asyncio" - await asyncio.sleep(0.01) + await asyncio.sleep(0.01, loop=self.loop) self.parent.did_it = 2 return self @@ -83,7 +83,7 @@ async def call_a_ts(self, proc, *args, loop=None): @pytest.mark.trio async def test_call_at(self, loop): async def delay(t): - done = asyncio.Event() + done = asyncio.Event(loop=loop) loop.call_at(t, done.set) await done.wait() @@ -193,7 +193,7 @@ def dly_trio(seen): @pytest.mark.trio async def test_trio_asyncio(self, loop): async def dly_asyncio(seen): - await asyncio.sleep(0.01) + await asyncio.sleep(0.01, loop=loop) seen.flag |= 1 return 4 @@ -280,7 +280,7 @@ def err_trio_sync(): @pytest.mark.trio async def test_trio_asyncio_error(self, loop): async def err_asyncio(): - await asyncio.sleep(0.01) + await asyncio.sleep(0.01, loop=loop) raise RuntimeError("I has an owie") with pytest.raises(RuntimeError) as err: @@ -317,14 +317,14 @@ async def cancelled_trio(seen): async def test_trio_asyncio_cancel_out(self, loop): async def cancelled_asyncio(seen): seen.flag |= 1 - await asyncio.sleep(0.01) - f = asyncio.Future() + await asyncio.sleep(0.01, loop=loop) + f = asyncio.Future(loop=loop) f.cancel() return f.result() # raises error def cancelled_future(seen): seen.flag |= 1 - f = asyncio.Future() + f = asyncio.Future(loop=loop) f.cancel() return f # contains error @@ -387,7 +387,7 @@ async def in_trio(started, seen): seen.flag |= 2 async def cancel_asyncio(seen): - started = asyncio.Event() + started = asyncio.Event(loop=loop) f = asyncio.ensure_future(self.call_a_t(in_trio, started, seen, loop=loop)) await started.wait() f.cancel() @@ -404,7 +404,7 @@ async def test_trio_asyncio_cancel_in(self, loop): async def in_asyncio(started, seen): started.set() try: - await asyncio.sleep(9999) + await asyncio.sleep(9999, loop=loop) except asyncio.CancelledError: seen.flag |= 1 except trio.Cancelled: @@ -527,7 +527,7 @@ def err_asyncio(): async def test_trio_asyncio_generator(self, loop): async def dly_asyncio(): yield 1 - await asyncio.sleep(0.01) + await asyncio.sleep(0.01, loop=loop) yield 2 with test_utils.deprecate(self): @@ -557,7 +557,7 @@ async def cancel_soon(nursery): await trio.sleep(0.01) nursery.cancel_scope.cancel() - hold = asyncio.Event() + hold = asyncio.Event(loop=loop) seen = Seen() with test_utils.deprecate(self): @@ -571,7 +571,7 @@ async def cancel_soon(nursery): async def test_trio_asyncio_iterator(self, loop): async def slow_nums(): for n in range(1, 6): - await asyncio.sleep(0.01) + await asyncio.sleep(0.01, loop=loop) yield n sum = 0 @@ -583,7 +583,7 @@ async def slow_nums(): async def test_trio_asyncio_iterator_depr(self, loop): async def slow_nums(): for n in range(1, 6): - await asyncio.sleep(0.01) + await asyncio.sleep(0.01, loop=loop) yield n sum = 0 diff --git a/tests/test_aio_subprocess.py b/tests/test_aio_subprocess.py index 218d7399..55ec0dfc 100644 --- a/tests/test_aio_subprocess.py +++ b/tests/test_aio_subprocess.py @@ -20,12 +20,12 @@ class MySubprocessProtocol(asyncio.SubprocessProtocol): def __init__(self, loop): self.state = 'INITIAL' self.transport = None - self.connected = asyncio.Future() - self.completed = asyncio.Future() - self.disconnects = {fd: asyncio.Future() for fd in range(3)} + self.connected = asyncio.Future(loop=loop) + self.completed = asyncio.Future(loop=loop) + self.disconnects = {fd: asyncio.Future(loop=loop) for fd in range(3)} self.data = {1: b'', 2: b''} self.returncode = None - self.got_data = {1: asyncio.Event(), 2: asyncio.Event()} + self.got_data = {1: asyncio.Event(loop=loop), 2: asyncio.Event(loop=loop)} def connection_made(self, transport): self.transport = transport diff --git a/tests/test_misc.py b/tests/test_misc.py index e8c1a919..7ff0c6c3 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -263,9 +263,9 @@ def do_not_run(): async def cancel_sleep(): h = loop.call_later(0.2, do_not_run) - await asyncio.sleep(0.1) + await asyncio.sleep(0.1, loop=loop) h.cancel() - await asyncio.sleep(0.3) + await asyncio.sleep(0.3, loop=loop) await trio_asyncio.aio_as_trio(cancel_sleep, loop=loop)() assert owch == 0 diff --git a/trio_asyncio/_adapter.py b/trio_asyncio/_adapter.py index b16d60d0..a1145a9e 100644 --- a/trio_asyncio/_adapter.py +++ b/trio_asyncio/_adapter.py @@ -271,7 +271,7 @@ async def allow_asyncio(fn, *args): import trio_asyncio async def hello(loop): - await asyncio.sleep(1) + await asyncio.sleep(1, loop=loop) print("Hello") await trio.sleep(1) print("World") diff --git a/trio_asyncio/_util.py b/trio_asyncio/_util.py index e27a0178..cfadf56b 100644 --- a/trio_asyncio/_util.py +++ b/trio_asyncio/_util.py @@ -108,7 +108,7 @@ def abort_cb(raise_cancel_arg): try: while True: # Schedule in asyncio that we read the next item from the iterator - current_read = asyncio.ensure_future(consume_next()) + current_read = asyncio.ensure_future(consume_next(), loop=loop) item = await trio.lowlevel.wait_task_rescheduled(abort_cb)