Exemple #1
0
def test_map_return_exceptions():
    @asyncio.coroutine
    def coro(num):
        raise ValueError('foo')

    task = map(coro, [1, 2, 3, 4, 5], return_exceptions=True)
    for exp in run_in_loop(task):
        assert isinstance(exp, ValueError)
Exemple #2
0
def test_map_raise_exceptions():
    @asyncio.coroutine
    def coro(num):
        if num > 3:
            raise ValueError('foo')
        return num * 2

    with pytest.raises(ValueError):
        run_in_loop(map(coro, [1, 2, 3, 4, 5], return_exceptions=False))
Exemple #3
0
def test_map_sequential():
    @asyncio.coroutine
    def _coro(num):
        yield from asyncio.sleep(0.1)
        return (yield from coro(num))

    init = time.time()
    task = map(_coro, [1, 2, 3, 4, 5], limit=1)
    assert run_in_loop(task) == [2, 4, 6, 8, 10]
    assert time.time() - init >= 0.5
Exemple #4
0
def test_map_return_exceptions():
    @asyncio.coroutine
    def coro(num):
        raise ValueError('foo')

    task = map(coro, [1, 2, 3, 4, 5], return_exceptions=True)
    results = run_in_loop(task)
    assert len(results) == 5

    for err in results:
        assert str(err) == 'foo'
Exemple #5
0
def test_map_invalid_coro():
    with pytest.raises(TypeError):
        run_in_loop(map(None))
Exemple #6
0
def test_map_invalid_input():
    with pytest.raises(TypeError):
        run_in_loop(map(coro, None))
Exemple #7
0
def test_map_empty():
    assert run_in_loop(map(coro, [])) == []
Exemple #8
0
def test_map():
    task = map(coro, [1, 2, 3, 4, 5])
    assert run_in_loop(task) == [2, 4, 6, 8, 10]
Exemple #9
0
async def task(numbers):
    return await (numbers
                   | paco.filter(filterer)
                   | paco.map(mapper)
                   | paco.dropwhile(drop)
                   | paco.reduce(reducer, initializer=0))  # noqa
Exemple #10
0
 def task(numbers):
     return (yield from (AsyncGenerator(numbers)
                         | paco.map(mapper)
                         | paco.reduce(reducer, initializer=0)))
Exemple #11
0
 def task(numbers):
     return (yield from (numbers
                         | paco.filter(filterer)
                         | paco.map(mapper)
                         | paco.dropwhile(drop)
                         | paco.reduce(reducer, initializer=0)))