# Path: paco/filterfalse.py
# @overload
# @asyncio.coroutine
# def filterfalse(coro, iterable, limit=0, loop=None):
#     """
#     Returns a list of all the values in coll which pass an asynchronous truth
#     test coroutine.
# 
#     Operations are executed concurrently by default, but results
#     will be in order.
# 
#     You can configure the concurrency via `limit` param.
# 
#     This function is the asynchronous equivalent port Python built-in
#     `filterfalse()` function.
# 
#     This function is a coroutine.
# 
#     This function can be composed in a pipeline chain with ``|`` operator.
# 
#     Arguments:
#         coro (coroutine function): coroutine filter function to call accepting
#             iterable values.
#         iterable (iterable): an iterable collection yielding
#             coroutines functions.
#         assert_fn (coroutinefunction): optional assertion function.
#         limit (int): max filtering concurrency limit. Use ``0`` for no limit.
#         loop (asyncio.BaseEventLoop): optional event loop to use.
# 
#     Raises:
#         TypeError: if coro argument is not a coroutine function.
# 
#     Returns:
#         filtered values (list): ordered list containing values that do not
#             passed the filter.
# 
#     Usage::
# 
#         async def iseven(num):
#             return num % 2 == 0
# 
#         await paco.filterfalse(coro, [1, 2, 3, 4, 5])
#         # => [1, 3, 5]
# 
#     """
#     return (yield from filter(coro, iterable,
#                               assert_fn=assert_false,
#                               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 time
import pytest
import asyncio
from paco import filterfalse
from .helpers import run_in_loop
# -*- coding: utf-8 -*-


@asyncio.coroutine
def even(num):
    return num % 2 == 0


def test_filterfalse():
    task = filterfalse(even, [1, 2, 3, 4, 5, 6])
    assert run_in_loop(task) == [1, 3, 5]


def test_filterfalse_collect_sequential():
    @asyncio.coroutine
    def coro(num):
        yield from asyncio.sleep(0.1)
        return (yield from even(num))

    init = time.time()
    task = filterfalse(coro, [1, 2, 3, 4, 5, 6], limit=1)
    assert run_in_loop(task) == [1, 3, 5]
    assert time.time() - init >= 0.5


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

# Path: paco/filterfalse.py
# @overload
# @asyncio.coroutine
# def filterfalse(coro, iterable, limit=0, loop=None):
#     """
#     Returns a list of all the values in coll which pass an asynchronous truth
#     test coroutine.
# 
#     Operations are executed concurrently by default, but results
#     will be in order.
# 
#     You can configure the concurrency via `limit` param.
# 
#     This function is the asynchronous equivalent port Python built-in
#     `filterfalse()` function.
# 
#     This function is a coroutine.
# 
#     This function can be composed in a pipeline chain with ``|`` operator.
# 
#     Arguments:
#         coro (coroutine function): coroutine filter function to call accepting
#             iterable values.
#         iterable (iterable): an iterable collection yielding
#             coroutines functions.
#         assert_fn (coroutinefunction): optional assertion function.
#         limit (int): max filtering concurrency limit. Use ``0`` for no limit.
#         loop (asyncio.BaseEventLoop): optional event loop to use.
# 
#     Raises:
#         TypeError: if coro argument is not a coroutine function.
# 
#     Returns:
#         filtered values (list): ordered list containing values that do not
#             passed the filter.
# 
#     Usage::
# 
#         async def iseven(num):
#             return num % 2 == 0
# 
#         await paco.filterfalse(coro, [1, 2, 3, 4, 5])
#         # => [1, 3, 5]
# 
#     """
#     return (yield from filter(coro, iterable,
#                               assert_fn=assert_false,
#                               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/filterfalse_test.py
import time
import pytest
import asyncio
from paco import filterfalse
from .helpers import run_in_loop

# -*- coding: utf-8 -*-


@asyncio.coroutine
def even(num):
    return num % 2 == 0


def test_filterfalse():
    task = filterfalse(even, [1, 2, 3, 4, 5, 6])
    assert run_in_loop(task) == [1, 3, 5]


def test_filterfalse_collect_sequential():
    @asyncio.coroutine
    def coro(num):
        yield from asyncio.sleep(0.1)
        return (yield from even(num))

    init = time.time()
    task = filterfalse(coro, [1, 2, 3, 4, 5, 6], limit=1)
    assert run_in_loop(task) == [1, 3, 5]
    assert time.time() - init >= 0.5


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

        run_in_loop(filterfalse(even, None))