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