# Path: paco/repeat.py
# @asyncio.coroutine
# def repeat(coro, times=1, step=1, limit=1, loop=None):
#     """
#     Executes the coroutine function ``x`` number of  times,
#     and accumulates results in order as you would use with ``map``.
# 
#     Execution concurrency is configurable using ``limit`` param.
# 
#     This function is a coroutine.
# 
#     Arguments:
#         coro (coroutinefunction): coroutine function to schedule.
#         times (int): number of times to execute the coroutine.
#         step (int): increment iteration step, as with ``range()``.
#         limit (int): concurrency execution limit. Defaults to 10.
#         loop (asyncio.BaseEventLoop): optional event loop to use.
# 
#     Raises:
#         TypeError: if coro is not a coroutine function.
# 
#     Returns:
#         list: accumulated yielded values returned by coroutine.
# 
#     Usage::
# 
#         async def mul_2(num):
#             return num * 2
# 
#         await paco.repeat(mul_2, times=5)
#         # => [2, 4, 6, 8, 10]
# 
#     """
#     assert_corofunction(coro=coro)
# 
#     # Iterate and attach coroutine for defer scheduling
#     times = max(int(times), 1)
#     iterable = range(1, times + 1, step)
# 
#     # Run iterable times
#     return (yield from map(coro, iterable, limit=limit, loop=loop))
# 
# Path: tests/helpers.py
# def run_in_loop(coro, *args, **kw):
#     loop = asyncio.get_event_loop()
#     if asyncio.iscoroutinefunction(coro) or isfunction(coro):
#         coro = coro(*args, **kw)
#     return loop.run_until_complete(coro)


import pytest
import asyncio
from paco import repeat
from .helpers import run_in_loop
    calls = 0

    @asyncio.coroutine
    def coro(num):
        nonlocal calls
        calls += 1
        return num * 2

    assert run_in_loop(repeat(coro, 5)) == [2, 4, 6, 8, 10]
    assert calls == 5


def test_repeat_defaults():
    @asyncio.coroutine
    def coro(num):
        return num * 2

    assert run_in_loop(repeat(coro)) == [2]


def test_repeat_concurrency():
    @asyncio.coroutine
    def coro(num):
        return num * 2

    assert run_in_loop(repeat(coro, 5), limit=5) == [2, 4, 6, 8, 10]


def test_repeat_invalid_input():
    with pytest.raises(TypeError):

# Path: paco/repeat.py
# @asyncio.coroutine
# def repeat(coro, times=1, step=1, limit=1, loop=None):
#     """
#     Executes the coroutine function ``x`` number of  times,
#     and accumulates results in order as you would use with ``map``.
# 
#     Execution concurrency is configurable using ``limit`` param.
# 
#     This function is a coroutine.
# 
#     Arguments:
#         coro (coroutinefunction): coroutine function to schedule.
#         times (int): number of times to execute the coroutine.
#         step (int): increment iteration step, as with ``range()``.
#         limit (int): concurrency execution limit. Defaults to 10.
#         loop (asyncio.BaseEventLoop): optional event loop to use.
# 
#     Raises:
#         TypeError: if coro is not a coroutine function.
# 
#     Returns:
#         list: accumulated yielded values returned by coroutine.
# 
#     Usage::
# 
#         async def mul_2(num):
#             return num * 2
# 
#         await paco.repeat(mul_2, times=5)
#         # => [2, 4, 6, 8, 10]
# 
#     """
#     assert_corofunction(coro=coro)
# 
#     # Iterate and attach coroutine for defer scheduling
#     times = max(int(times), 1)
#     iterable = range(1, times + 1, step)
# 
#     # Run iterable times
#     return (yield from map(coro, iterable, limit=limit, loop=loop))
# 
# Path: tests/helpers.py
# def run_in_loop(coro, *args, **kw):
#     loop = asyncio.get_event_loop()
#     if asyncio.iscoroutinefunction(coro) or isfunction(coro):
#         coro = coro(*args, **kw)
#     return loop.run_until_complete(coro)


# Path: tests/repeat_test.py
import pytest
import asyncio
from paco import repeat
from .helpers import run_in_loop

    calls = 0

    @asyncio.coroutine
    def coro(num):
        nonlocal calls
        calls += 1
        return num * 2

    assert run_in_loop(repeat(coro, 5)) == [2, 4, 6, 8, 10]
    assert calls == 5


def test_repeat_defaults():
    @asyncio.coroutine
    def coro(num):
        return num * 2

    assert run_in_loop(repeat(coro)) == [2]


def test_repeat_concurrency():
    @asyncio.coroutine
    def coro(num):
        return num * 2

    assert run_in_loop(repeat(coro, 5), limit=5) == [2, 4, 6, 8, 10]


def test_repeat_invalid_input():
    with pytest.raises(TypeError):

        run_in_loop(repeat(None))