Skip to content

Commit 313cfaf

Browse files
committed
Revert "First stab at fixing the tests"
This reverts commit 21c5916. We should still be explicitly passing the loop to avoid any mistakes.
1 parent 1d1783e commit 313cfaf

6 files changed

Lines changed: 55 additions & 53 deletions

File tree

tests/aiotest/test_callback.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ async def test_close(self, loop, config):
4545
await loop.stop().wait()
4646
loop.close()
4747

48-
async def test():
48+
@config.asyncio.coroutine
49+
def test():
4950
pass
5051

5152
func = lambda: False

tests/aiotest/test_coroutine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
async def hello_world(asyncio, result, delay, loop):
88
result.append("Hello")
99
# retrieve the event loop from the policy
10-
await asyncio.sleep(delay)
10+
await asyncio.sleep(delay, loop=loop)
1111
result.append('World')
1212
return "."
1313

tests/interop/test_adapter.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,33 @@ async def dly_trio_depr(self):
5757
async def dly_asyncio_depr(self):
5858
if sys.version_info >= (3, 7):
5959
assert sniffio.current_async_library() == "asyncio"
60-
await asyncio.sleep(0.01)
60+
await asyncio.sleep(0.01, loop=self.loop)
6161
self.flag |= 1
6262
return 4
6363

6464
@aio_as_trio
6565
async def dly_asyncio_adapted(self):
6666
if sys.version_info >= (3, 7):
6767
assert sniffio.current_async_library() == "asyncio"
68-
await asyncio.sleep(0.01)
68+
await asyncio.sleep(0.01, loop=self.loop)
6969
self.flag |= 1
7070
return 4
7171

7272
async def dly_asyncio(self, do_test=True):
7373
if do_test and sys.version_info >= (3, 7):
7474
assert sniffio.current_async_library() == "asyncio"
75-
await asyncio.sleep(0.01)
75+
await asyncio.sleep(0.01, loop=self.loop)
7676
self.flag |= 1
7777
return 4
7878

7979
async def iter_asyncio(self, do_test=True):
8080
if do_test and sys.version_info >= (3, 7):
8181
assert sniffio.current_async_library() == "asyncio"
82-
await asyncio.sleep(0.01)
82+
await asyncio.sleep(0.01, loop=self.loop)
8383
yield 1
84-
await asyncio.sleep(0.01)
84+
await asyncio.sleep(0.01, loop=self.loop)
8585
yield 2
86-
await asyncio.sleep(0.01)
86+
await asyncio.sleep(0.01, loop=self.loop)
8787
self.flag |= 1
8888

8989
async def iter_trio(self):
@@ -98,10 +98,10 @@ async def iter_trio(self):
9898

9999
@asynccontextmanager
100100
async def ctx_asyncio(self):
101-
await asyncio.sleep(0.01)
101+
await asyncio.sleep(0.01, loop=self.loop)
102102
self.flag |= 1
103103
yield self
104-
await asyncio.sleep(0.01)
104+
await asyncio.sleep(0.01, loop=self.loop)
105105
self.flag |= 2
106106

107107
@asynccontextmanager

tests/interop/test_calls.py

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def __aenter__(self):
4848
self.parent.did_it = 1
4949
if sys.version_info >= (3, 7):
5050
assert sniffio.current_async_library() == "asyncio"
51-
await asyncio.sleep(0.01)
51+
await asyncio.sleep(0.01, loop=self.loop)
5252
self.parent.did_it = 2
5353
return self
5454

@@ -60,7 +60,7 @@ async def __aexit__(self, *tb):
6060
class TestCalls(aiotest.TestCase):
6161
async def call_t_a(self, proc, *args, loop=None):
6262
"""called from Trio"""
63-
return await aio_as_trio(proc)(*args)
63+
return await aio_as_trio(proc, loop=loop)(*args)
6464

6565
async def call_t_a_depr(self, proc, *args, loop=None):
6666
"""called from Trio"""
@@ -69,7 +69,7 @@ async def call_t_a_depr(self, proc, *args, loop=None):
6969

7070
async def call_a_t(self, proc, *args, loop=None):
7171
"""call from asyncio to an async trio function"""
72-
return await trio_as_aio(proc)(*args)
72+
return await trio_as_aio(proc, loop=loop)(*args)
7373

7474
async def call_a_t_depr(self, proc, *args, loop=None):
7575
"""call from asyncio to an async trio function"""
@@ -83,17 +83,17 @@ async def call_a_ts(self, proc, *args, loop=None):
8383
@pytest.mark.trio
8484
async def test_call_at(self, loop):
8585
async def delay(t):
86-
done = asyncio.Event()
86+
done = asyncio.Event(loop=loop)
8787
loop.call_at(t, done.set)
8888
await done.wait()
8989

9090
t = loop.time() + 0.1
91-
await aio_as_trio(delay)(t)
91+
await aio_as_trio(delay, loop=loop)(t)
9292

9393
@pytest.mark.trio
9494
async def test_call_at_depr(self, loop):
9595
async def delay(t):
96-
done = asyncio.Event()
96+
done = asyncio.Event(loop=loop)
9797
loop.call_at(t, done.set)
9898
await done.wait()
9999

@@ -111,7 +111,7 @@ async def dly_trio(seen):
111111
return 8
112112

113113
seen = Seen()
114-
res = await aio_as_trio(partial(self.call_a_t, loop=loop))(dly_trio, seen)
114+
res = await aio_as_trio(partial(self.call_a_t, loop=loop), loop=loop)(dly_trio, seen)
115115
assert res == 8
116116
assert seen.flag == 2
117117

@@ -125,14 +125,14 @@ async def dly_trio(seen):
125125
return 8
126126

127127
seen = Seen()
128-
res = await aio_as_trio(partial(self.call_a_t_depr, loop=loop))(dly_trio, seen)
128+
res = await aio_as_trio(partial(self.call_a_t_depr, loop=loop), loop=loop)(dly_trio, seen)
129129
assert res == 8
130130
assert seen.flag == 2
131131

132132
@pytest.mark.trio
133133
async def test_call_asyncio_ctx(self, loop):
134134
self.did_it = 0
135-
async with aio_as_trio(AioContext(self, loop)) as ctx:
135+
async with aio_as_trio(AioContext(self, loop), loop=loop) as ctx:
136136
assert ctx.parent is self
137137
assert self.did_it == 2
138138
self.did_it = 3
@@ -148,7 +148,7 @@ async def _call_trio_ctx():
148148
self.did_it = 3
149149
assert self.did_it == 4
150150

151-
await aio_as_trio(_call_trio_ctx)()
151+
await aio_as_trio(_call_trio_ctx, loop=loop)()
152152

153153
@pytest.mark.trio
154154
async def test_call_trio_ctx_depr(self, loop):
@@ -172,7 +172,7 @@ def dly_trio(seen):
172172
return 8
173173

174174
seen = Seen()
175-
res = await aio_as_trio(partial(self.call_a_ts, loop=loop))(dly_trio, seen)
175+
res = await aio_as_trio(partial(self.call_a_ts, loop=loop), loop=loop)(dly_trio, seen)
176176
assert res == 8
177177
assert seen.flag == 2
178178

@@ -193,7 +193,7 @@ def dly_trio(seen):
193193
@pytest.mark.trio
194194
async def test_trio_asyncio(self, loop):
195195
async def dly_asyncio(seen):
196-
await asyncio.sleep(0.01)
196+
await asyncio.sleep(0.01, loop=loop)
197197
seen.flag |= 1
198198
return 4
199199

@@ -205,7 +205,7 @@ async def dly_asyncio(seen):
205205
@pytest.mark.trio
206206
async def test_trio_asyncio_depr(self, loop):
207207
async def dly_asyncio(seen):
208-
await asyncio.sleep(0.01)
208+
await asyncio.sleep(0.01, loop=loop)
209209
seen.flag |= 1
210210
return 4
211211

@@ -221,7 +221,7 @@ async def err_trio():
221221
raise RuntimeError("I has another owie")
222222

223223
with pytest.raises(RuntimeError) as err:
224-
await aio_as_trio(partial(self.call_a_t, loop=loop))(err_trio)
224+
await aio_as_trio(partial(self.call_a_t, loop=loop), loop=loop)(err_trio)
225225
assert err.value.args[0] == "I has another owie"
226226

227227
@pytest.mark.trio
@@ -231,7 +231,7 @@ async def err_trio():
231231
raise RuntimeError("I has another owie")
232232

233233
with pytest.raises(RuntimeError) as err:
234-
await aio_as_trio(partial(self.call_a_t_depr, loop=loop))(err_trio)
234+
await aio_as_trio(partial(self.call_a_t_depr, loop=loop), loop=loop)(err_trio)
235235
assert err.value.args[0] == "I has another owie"
236236

237237
@pytest.mark.trio
@@ -253,8 +253,7 @@ async def err_trio():
253253

254254
with pytest.raises(RuntimeError) as err:
255255
with test_utils.deprecate(self):
256-
await loop.run_asyncio(partial(self.call_a_t_depr,
257-
loop=loop), err_trio)
256+
await loop.run_asyncio(partial(self.call_a_t_depr, loop=loop), err_trio)
258257
assert err.value.args[0] == "I has another owie"
259258

260259
@pytest.mark.trio
@@ -264,7 +263,7 @@ def err_trio_sync():
264263
raise RuntimeError("I has more owie")
265264

266265
with pytest.raises(RuntimeError) as err:
267-
await aio_as_trio(partial(self.call_a_ts, loop=loop))(err_trio_sync)
266+
await aio_as_trio(partial(self.call_a_ts, loop=loop), loop=loop)(err_trio_sync)
268267
assert err.value.args[0] == "I has more owie"
269268

270269
@pytest.mark.trio
@@ -281,7 +280,7 @@ def err_trio_sync():
281280
@pytest.mark.trio
282281
async def test_trio_asyncio_error(self, loop):
283282
async def err_asyncio():
284-
await asyncio.sleep(0.01)
283+
await asyncio.sleep(0.01, loop=loop)
285284
raise RuntimeError("I has an owie")
286285

287286
with pytest.raises(RuntimeError) as err:
@@ -291,7 +290,7 @@ async def err_asyncio():
291290
@pytest.mark.trio
292291
async def test_trio_asyncio_error_depr(self, loop):
293292
async def err_asyncio():
294-
await asyncio.sleep(0.01)
293+
await asyncio.sleep(0.01, loop=loop)
295294
raise RuntimeError("I has an owie")
296295

297296
with pytest.raises(RuntimeError) as err:
@@ -311,21 +310,21 @@ async def cancelled_trio(seen):
311310

312311
seen = Seen()
313312
with pytest.raises(asyncio.CancelledError):
314-
await aio_as_trio(partial(self.call_a_t, loop=loop))(cancelled_trio, seen)
313+
await aio_as_trio(partial(self.call_a_t, loop=loop), loop=loop)(cancelled_trio, seen)
315314
assert seen.flag == 3
316315

317316
@pytest.mark.trio
318317
async def test_trio_asyncio_cancel_out(self, loop):
319318
async def cancelled_asyncio(seen):
320319
seen.flag |= 1
321-
await asyncio.sleep(0.01)
322-
f = asyncio.Future()
320+
await asyncio.sleep(0.01, loop=loop)
321+
f = asyncio.Future(loop=loop)
323322
f.cancel()
324323
return f.result() # raises error
325324

326325
def cancelled_future(seen):
327326
seen.flag |= 1
328-
f = asyncio.Future()
327+
f = asyncio.Future(loop=loop)
329328
f.cancel()
330329
return f # contains error
331330

@@ -348,14 +347,14 @@ async def check_cancel(proc, seen):
348347
async def test_trio_asyncio_cancel_out_depr(self, loop):
349348
async def cancelled_asyncio(seen):
350349
seen.flag |= 1
351-
await asyncio.sleep(0.01)
352-
f = asyncio.Future()
350+
await asyncio.sleep(0.01, loop=loop)
351+
f = asyncio.Future(loop=loop)
353352
f.cancel()
354353
return f.result() # raises error
355354

356355
def cancelled_future(seen):
357356
seen.flag |= 1
358-
f = asyncio.Future()
357+
f = asyncio.Future(loop=loop)
359358
f.cancel()
360359
return f # contains error
361360

@@ -388,7 +387,7 @@ async def in_trio(started, seen):
388387
seen.flag |= 2
389388

390389
async def cancel_asyncio(seen):
391-
started = asyncio.Event()
390+
started = asyncio.Event(loop=loop)
392391
f = asyncio.ensure_future(self.call_a_t(in_trio, started, seen, loop=loop))
393392
await started.wait()
394393
f.cancel()
@@ -397,15 +396,15 @@ async def cancel_asyncio(seen):
397396
seen.flag |= 8
398397

399398
seen = Seen()
400-
await aio_as_trio(cancel_asyncio)(seen)
399+
await aio_as_trio(cancel_asyncio, loop=loop)(seen)
401400
assert seen.flag == 1 | 2 | 8
402401

403402
@pytest.mark.trio
404403
async def test_trio_asyncio_cancel_in(self, loop):
405404
async def in_asyncio(started, seen):
406405
started.set()
407406
try:
408-
await asyncio.sleep(9999)
407+
await asyncio.sleep(9999, loop=loop)
409408
except asyncio.CancelledError:
410409
seen.flag |= 1
411410
except trio.Cancelled:
@@ -432,7 +431,7 @@ async def test_trio_asyncio_cancel_in_depr(self, loop):
432431
async def in_asyncio(started, seen):
433432
started.set()
434433
try:
435-
await asyncio.sleep(9999)
434+
await asyncio.sleep(9999, loop=loop)
436435
except asyncio.CancelledError:
437436
seen.flag |= 1
438437
except trio.Cancelled:
@@ -528,7 +527,7 @@ def err_asyncio():
528527
async def test_trio_asyncio_generator(self, loop):
529528
async def dly_asyncio():
530529
yield 1
531-
await asyncio.sleep(0.01)
530+
await asyncio.sleep(0.01, loop=loop)
532531
yield 2
533532

534533
with test_utils.deprecate(self):
@@ -558,7 +557,7 @@ async def cancel_soon(nursery):
558557
await trio.sleep(0.01)
559558
nursery.cancel_scope.cancel()
560559

561-
hold = asyncio.Event()
560+
hold = asyncio.Event(loop=loop)
562561
seen = Seen()
563562

564563
with test_utils.deprecate(self):
@@ -572,7 +571,7 @@ async def cancel_soon(nursery):
572571
async def test_trio_asyncio_iterator(self, loop):
573572
async def slow_nums():
574573
for n in range(1, 6):
575-
await asyncio.sleep(0.01)
574+
await asyncio.sleep(0.01, loop=loop)
576575
yield n
577576

578577
sum = 0
@@ -584,11 +583,13 @@ async def slow_nums():
584583
async def test_trio_asyncio_iterator_depr(self, loop):
585584
async def slow_nums():
586585
for n in range(1, 6):
587-
await asyncio.sleep(0.01)
586+
await asyncio.sleep(0.01, loop=loop)
588587
yield n
589588

590589
sum = 0
591590
# with test_utils.deprecate(self): ## not yet
592-
async for n in aio_as_trio(slow_nums()):
591+
async for n in aio_as_trio(
592+
slow_nums(), loop=loop
593+
):
593594
sum += n
594595
assert sum == 15

tests/test_aio_subprocess.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class MySubprocessProtocol(asyncio.SubprocessProtocol):
2020
def __init__(self, loop):
2121
self.state = 'INITIAL'
2222
self.transport = None
23-
self.connected = asyncio.Future()
24-
self.completed = asyncio.Future()
25-
self.disconnects = {fd: asyncio.Future() for fd in range(3)}
23+
self.connected = asyncio.Future(loop=loop)
24+
self.completed = asyncio.Future(loop=loop)
25+
self.disconnects = {fd: asyncio.Future(loop=loop) for fd in range(3)}
2626
self.data = {1: b'', 2: b''}
2727
self.returncode = None
28-
self.got_data = {1: asyncio.Event(), 2: asyncio.Event()}
28+
self.got_data = {1: asyncio.Event(loop=loop), 2: asyncio.Event(loop=loop)}
2929

3030
def connection_made(self, transport):
3131
self.transport = transport

tests/test_misc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ async def nest(x):
167167
with pytest.raises(RuntimeError):
168168
trio_asyncio.run_trio_task(nest, 100)
169169

170-
with pytest.raises(AttributeError):
170+
with pytest.raises(RuntimeError):
171171
with trio_asyncio.open_loop():
172172
nest(1000)
173173

@@ -263,9 +263,9 @@ def do_not_run():
263263

264264
async def cancel_sleep():
265265
h = loop.call_later(0.2, do_not_run)
266-
await asyncio.sleep(0.1)
266+
await asyncio.sleep(0.1, loop=loop)
267267
h.cancel()
268-
await asyncio.sleep(0.3)
268+
await asyncio.sleep(0.3, loop=loop)
269269

270270
await trio_asyncio.aio_as_trio(cancel_sleep, loop=loop)()
271271
assert owch == 0

0 commit comments

Comments
 (0)