-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathtest_aio.py
More file actions
89 lines (64 loc) · 1.98 KB
/
test_aio.py
File metadata and controls
89 lines (64 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from graphql_server.utils.aio import (
aenumerate,
aislice,
asyncgen_to_list,
resolve_awaitable,
)
async def test_aenumerate():
async def gen():
yield "a"
yield "b"
yield "c"
yield "d"
res = [(i, v) async for i, v in aenumerate(gen())]
assert res == [(0, "a"), (1, "b"), (2, "c"), (3, "d")]
async def test_aslice():
async def gen():
yield "a"
yield "b"
raise AssertionError("should never be called") # pragma: no cover
yield "c" # pragma: no cover
res = []
async for v in aislice(gen(), 0, 2):
res.append(v) # noqa: PERF401
assert res == ["a", "b"]
async def test_aislice_empty_generator():
async def gen():
if False: # pragma: no cover
yield "should not be returned"
raise AssertionError("should never be called")
res = []
async for v in aislice(gen(), 0, 2):
res.append(v) # noqa: PERF401
assert res == []
async def test_aislice_empty_slice():
async def gen():
if False: # pragma: no cover
yield "should not be returned"
raise AssertionError("should never be called")
res = []
async for v in aislice(gen(), 0, 0):
res.append(v) # noqa: PERF401
assert res == []
async def test_aislice_with_step():
async def gen():
yield "a"
yield "b"
yield "c"
raise AssertionError("should never be called") # pragma: no cover
yield "d" # pragma: no cover
yield "e" # pragma: no cover
res = []
async for v in aislice(gen(), 0, 4, 2):
res.append(v) # noqa: PERF401
assert res == ["a", "c"]
async def test_asyncgen_to_list():
async def gen():
yield "a"
yield "b"
yield "c"
assert await asyncgen_to_list(gen()) == ["a", "b", "c"]
async def test_resolve_awaitable():
async def awaitable():
return 1
assert await resolve_awaitable(awaitable(), lambda v: v + 1) == 2