Пример #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)
Пример #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))
Пример #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
Пример #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'
Пример #5
0
def test_map_invalid_coro():
    with pytest.raises(TypeError):
        run_in_loop(map(None))
Пример #6
0
def test_map_invalid_input():
    with pytest.raises(TypeError):
        run_in_loop(map(coro, None))
Пример #7
0
def test_map_empty():
    assert run_in_loop(map(coro, [])) == []
Пример #8
0
def test_map():
    task = map(coro, [1, 2, 3, 4, 5])
    assert run_in_loop(task) == [2, 4, 6, 8, 10]
Пример #9
0
async def task(numbers):
    return await (numbers
                   | paco.filter(filterer)
                   | paco.map(mapper)
                   | paco.dropwhile(drop)
                   | paco.reduce(reducer, initializer=0))  # noqa
Пример #10
0
 def task(numbers):
     return (yield from (AsyncGenerator(numbers)
                         | paco.map(mapper)
                         | paco.reduce(reducer, initializer=0)))
Пример #11
0
 def task(numbers):
     return (yield from (numbers
                         | paco.filter(filterer)
                         | paco.map(mapper)
                         | paco.dropwhile(drop)
                         | paco.reduce(reducer, initializer=0)))