Skip to content

Commit 21c5916

Browse files
committed
First stab at fixing the tests
1 parent a810a76 commit 21c5916

7 files changed

Lines changed: 54 additions & 56 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
python_requires=">=3.6", # temporary, for RTD
7878
keywords=["async", "io", "trio", "asyncio", "trio-asyncio"],
7979
setup_requires=['pytest-runner'],
80-
tests_require=['pytest', 'outcome'],
80+
tests_require=['pytest >= 5.4', 'outcome'],
8181
classifiers=[
8282
"Development Status :: 4 - Beta",
8383
"Intended Audience :: Developers",

tests/aiotest/test_callback.py

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

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

5251
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, loop=loop)
10+
await asyncio.sleep(delay)
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, loop=self.loop)
60+
await asyncio.sleep(0.01)
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, loop=self.loop)
68+
await asyncio.sleep(0.01)
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, loop=self.loop)
75+
await asyncio.sleep(0.01)
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, loop=self.loop)
82+
await asyncio.sleep(0.01)
8383
yield 1
84-
await asyncio.sleep(0.01, loop=self.loop)
84+
await asyncio.sleep(0.01)
8585
yield 2
86-
await asyncio.sleep(0.01, loop=self.loop)
86+
await asyncio.sleep(0.01)
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, loop=self.loop)
101+
await asyncio.sleep(0.01)
102102
self.flag |= 1
103103
yield self
104-
await asyncio.sleep(0.01, loop=self.loop)
104+
await asyncio.sleep(0.01)
105105
self.flag |= 2
106106

107107
@asynccontextmanager

tests/interop/test_calls.py

Lines changed: 36 additions & 37 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, loop=self.loop)
51+
await asyncio.sleep(0.01)
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, loop=loop)(*args)
63+
return await aio_as_trio(proc)(*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, loop=loop)(*args)
72+
return await trio_as_aio(proc)(*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(loop=loop)
86+
done = asyncio.Event()
8787
loop.call_at(t, done.set)
8888
await done.wait()
8989

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

9393
@pytest.mark.trio
9494
async def test_call_at_depr(self, loop):
9595
async def delay(t):
96-
done = asyncio.Event(loop=loop)
96+
done = asyncio.Event()
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), loop=loop)(dly_trio, seen)
114+
res = await aio_as_trio(partial(self.call_a_t, 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), loop=loop)(dly_trio, seen)
128+
res = await aio_as_trio(partial(self.call_a_t_depr, 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), loop=loop) as ctx:
135+
async with aio_as_trio(AioContext(self, 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, loop=loop)()
151+
await aio_as_trio(_call_trio_ctx)()
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), loop=loop)(dly_trio, seen)
175+
res = await aio_as_trio(partial(self.call_a_ts, 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, loop=loop)
196+
await asyncio.sleep(0.01)
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, loop=loop)
208+
await asyncio.sleep(0.01)
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), loop=loop)(err_trio)
224+
await aio_as_trio(partial(self.call_a_t, 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), loop=loop)(err_trio)
234+
await aio_as_trio(partial(self.call_a_t_depr, loop=loop))(err_trio)
235235
assert err.value.args[0] == "I has another owie"
236236

237237
@pytest.mark.trio
@@ -253,7 +253,8 @@ 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, loop=loop), err_trio)
256+
await loop.run_asyncio(partial(self.call_a_t_depr,
257+
loop=loop), err_trio)
257258
assert err.value.args[0] == "I has another owie"
258259

259260
@pytest.mark.trio
@@ -263,7 +264,7 @@ def err_trio_sync():
263264
raise RuntimeError("I has more owie")
264265

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

269270
@pytest.mark.trio
@@ -280,7 +281,7 @@ def err_trio_sync():
280281
@pytest.mark.trio
281282
async def test_trio_asyncio_error(self, loop):
282283
async def err_asyncio():
283-
await asyncio.sleep(0.01, loop=loop)
284+
await asyncio.sleep(0.01)
284285
raise RuntimeError("I has an owie")
285286

286287
with pytest.raises(RuntimeError) as err:
@@ -290,7 +291,7 @@ async def err_asyncio():
290291
@pytest.mark.trio
291292
async def test_trio_asyncio_error_depr(self, loop):
292293
async def err_asyncio():
293-
await asyncio.sleep(0.01, loop=loop)
294+
await asyncio.sleep(0.01)
294295
raise RuntimeError("I has an owie")
295296

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

311312
seen = Seen()
312313
with pytest.raises(asyncio.CancelledError):
313-
await aio_as_trio(partial(self.call_a_t, loop=loop), loop=loop)(cancelled_trio, seen)
314+
await aio_as_trio(partial(self.call_a_t, loop=loop))(cancelled_trio, seen)
314315
assert seen.flag == 3
315316

316317
@pytest.mark.trio
317318
async def test_trio_asyncio_cancel_out(self, loop):
318319
async def cancelled_asyncio(seen):
319320
seen.flag |= 1
320-
await asyncio.sleep(0.01, loop=loop)
321-
f = asyncio.Future(loop=loop)
321+
await asyncio.sleep(0.01)
322+
f = asyncio.Future()
322323
f.cancel()
323324
return f.result() # raises error
324325

325326
def cancelled_future(seen):
326327
seen.flag |= 1
327-
f = asyncio.Future(loop=loop)
328+
f = asyncio.Future()
328329
f.cancel()
329330
return f # contains error
330331

@@ -347,14 +348,14 @@ async def check_cancel(proc, seen):
347348
async def test_trio_asyncio_cancel_out_depr(self, loop):
348349
async def cancelled_asyncio(seen):
349350
seen.flag |= 1
350-
await asyncio.sleep(0.01, loop=loop)
351-
f = asyncio.Future(loop=loop)
351+
await asyncio.sleep(0.01)
352+
f = asyncio.Future()
352353
f.cancel()
353354
return f.result() # raises error
354355

355356
def cancelled_future(seen):
356357
seen.flag |= 1
357-
f = asyncio.Future(loop=loop)
358+
f = asyncio.Future()
358359
f.cancel()
359360
return f # contains error
360361

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

389390
async def cancel_asyncio(seen):
390-
started = asyncio.Event(loop=loop)
391+
started = asyncio.Event()
391392
f = asyncio.ensure_future(self.call_a_t(in_trio, started, seen, loop=loop))
392393
await started.wait()
393394
f.cancel()
@@ -396,15 +397,15 @@ async def cancel_asyncio(seen):
396397
seen.flag |= 8
397398

398399
seen = Seen()
399-
await aio_as_trio(cancel_asyncio, loop=loop)(seen)
400+
await aio_as_trio(cancel_asyncio)(seen)
400401
assert seen.flag == 1 | 2 | 8
401402

402403
@pytest.mark.trio
403404
async def test_trio_asyncio_cancel_in(self, loop):
404405
async def in_asyncio(started, seen):
405406
started.set()
406407
try:
407-
await asyncio.sleep(9999, loop=loop)
408+
await asyncio.sleep(9999)
408409
except asyncio.CancelledError:
409410
seen.flag |= 1
410411
except trio.Cancelled:
@@ -431,7 +432,7 @@ async def test_trio_asyncio_cancel_in_depr(self, loop):
431432
async def in_asyncio(started, seen):
432433
started.set()
433434
try:
434-
await asyncio.sleep(9999, loop=loop)
435+
await asyncio.sleep(9999)
435436
except asyncio.CancelledError:
436437
seen.flag |= 1
437438
except trio.Cancelled:
@@ -527,7 +528,7 @@ def err_asyncio():
527528
async def test_trio_asyncio_generator(self, loop):
528529
async def dly_asyncio():
529530
yield 1
530-
await asyncio.sleep(0.01, loop=loop)
531+
await asyncio.sleep(0.01)
531532
yield 2
532533

533534
with test_utils.deprecate(self):
@@ -557,7 +558,7 @@ async def cancel_soon(nursery):
557558
await trio.sleep(0.01)
558559
nursery.cancel_scope.cancel()
559560

560-
hold = asyncio.Event(loop=loop)
561+
hold = asyncio.Event()
561562
seen = Seen()
562563

563564
with test_utils.deprecate(self):
@@ -571,7 +572,7 @@ async def cancel_soon(nursery):
571572
async def test_trio_asyncio_iterator(self, loop):
572573
async def slow_nums():
573574
for n in range(1, 6):
574-
await asyncio.sleep(0.01, loop=loop)
575+
await asyncio.sleep(0.01)
575576
yield n
576577

577578
sum = 0
@@ -583,13 +584,11 @@ async def slow_nums():
583584
async def test_trio_asyncio_iterator_depr(self, loop):
584585
async def slow_nums():
585586
for n in range(1, 6):
586-
await asyncio.sleep(0.01, loop=loop)
587+
await asyncio.sleep(0.01)
587588
yield n
588589

589590
sum = 0
590591
# with test_utils.deprecate(self): ## not yet
591-
async for n in aio_as_trio(
592-
slow_nums(), loop=loop
593-
):
592+
async for n in aio_as_trio(slow_nums()):
594593
sum += n
595594
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(loop=loop)
24-
self.completed = asyncio.Future(loop=loop)
25-
self.disconnects = {fd: asyncio.Future(loop=loop) for fd in range(3)}
23+
self.connected = asyncio.Future()
24+
self.completed = asyncio.Future()
25+
self.disconnects = {fd: asyncio.Future() for fd in range(3)}
2626
self.data = {1: b'', 2: b''}
2727
self.returncode = None
28-
self.got_data = {1: asyncio.Event(loop=loop), 2: asyncio.Event(loop=loop)}
28+
self.got_data = {1: asyncio.Event(), 2: asyncio.Event()}
2929

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

0 commit comments

Comments
 (0)