Total Complexity | 5 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from curio import run |
||
2 | |||
3 | from libellule.control_flow.common import ( |
||
4 | FAILURE, |
||
5 | SUCCESS, |
||
6 | ControlFlowException, |
||
7 | afilter, |
||
8 | amap, |
||
9 | ) |
||
10 | |||
11 | |||
12 | def test_truthy(): |
||
13 | assert SUCCESS |
||
14 | assert Exception() |
||
15 | assert [1, 2] |
||
16 | |||
17 | |||
18 | def test_falsy(): |
||
19 | assert not [] |
||
20 | assert not bool([]) |
||
21 | assert not FAILURE |
||
22 | assert not bool(FAILURE) |
||
23 | assert not bool(ControlFlowException(Exception())) |
||
24 | |||
25 | |||
26 | def test_amap(): |
||
27 | async def inc(a): |
||
28 | return a + 1 |
||
29 | |||
30 | async def process(): |
||
31 | return [i async for i in amap(inc, [1, 2])] |
||
32 | |||
33 | assert run(process) == [2, 3] |
||
34 | |||
35 | |||
36 | def test_afilter(): |
||
37 | async def even(a): |
||
38 | return a % 2 == 0 |
||
39 | |||
40 | async def process(): |
||
41 | return [i async for i in afilter(even, [0, 1, 2, 3, 4])] |
||
42 | |||
43 | assert run(process) == [0, 2, 4] |
||
44 | |||
45 | |||
46 | def test_afilter_amap_aiter(): |
||
47 | async def inc(a): |
||
48 | return a + 1 |
||
49 | |||
50 | async def even(a): |
||
51 | return a % 2 == 0 |
||
52 | |||
53 | async def process1(): |
||
54 | return [i async for i in afilter(even, amap(inc, [0, 1, 2, 3, 4]))] |
||
55 | |||
56 | async def process2(): |
||
57 | return [i async for i in amap(inc, afilter(even, [0, 1, 2, 3, 4]))] |
||
58 | |||
59 | assert run(process1) == [2, 4] |
||
60 | assert run(process2) == [1, 3, 5] |
||
61 |