Passed
Pull Request — master (#3)
by Guibert
53s
created

test_common.test_amap()   A

Complexity

Conditions 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nop 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