# Path: paco/partial.py
# @decorate
# def partial(coro, *args, **kw):
#     """
#     Partial function implementation designed
#     for coroutines, allowing variadic input arguments.
# 
#     This function can be used as decorator.
# 
#     arguments:
#         coro (coroutinefunction): coroutine function to wrap.
#         *args (mixed): mixed variadic arguments for partial application.
# 
#     Raises:
#         TypeError: if ``coro`` is not a coroutine function.
# 
#     Returns:
#         coroutinefunction
# 
#     Usage::
# 
#         async def pow(x, y):
#             return x ** y
# 
#         pow_2 = paco.partial(pow, 2)
#         await pow_2(4)
#         # => 16
# 
#     """
#     assert_corofunction(coro=coro)
# 
#     @asyncio.coroutine
#     def wrapper(*_args, **_kw):
#         call_args = args + _args
#         kw.update(_kw)
#         return (yield from coro(*call_args, **kw))
# 
#     return wrapper
# 
# 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 asyncio
from paco import partial
from .helpers import run_in_loop
# -*- coding: utf-8 -*-


@asyncio.coroutine
def coro(*args, **kw):
    return args, kw


def test_partial():
    task = partial(coro, 1, 2, foo='bar')
    args, kw = run_in_loop(task, 3, 4, bar='baz')

    assert len(args) == 4
    assert len(kw) == 2
    assert args == (1, 2, 3, 4)
    assert kw == {'foo': 'bar', 'bar': 'baz'}


def test_partial_variadic_arguments():

# Path: paco/partial.py
# @decorate
# def partial(coro, *args, **kw):
#     """
#     Partial function implementation designed
#     for coroutines, allowing variadic input arguments.
# 
#     This function can be used as decorator.
# 
#     arguments:
#         coro (coroutinefunction): coroutine function to wrap.
#         *args (mixed): mixed variadic arguments for partial application.
# 
#     Raises:
#         TypeError: if ``coro`` is not a coroutine function.
# 
#     Returns:
#         coroutinefunction
# 
#     Usage::
# 
#         async def pow(x, y):
#             return x ** y
# 
#         pow_2 = paco.partial(pow, 2)
#         await pow_2(4)
#         # => 16
# 
#     """
#     assert_corofunction(coro=coro)
# 
#     @asyncio.coroutine
#     def wrapper(*_args, **_kw):
#         call_args = args + _args
#         kw.update(_kw)
#         return (yield from coro(*call_args, **kw))
# 
#     return wrapper
# 
# 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/partial_test.py
import asyncio
from paco import partial
from .helpers import run_in_loop

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


@asyncio.coroutine
def coro(*args, **kw):
    return args, kw


def test_partial():
    task = partial(coro, 1, 2, foo='bar')
    args, kw = run_in_loop(task, 3, 4, bar='baz')

    assert len(args) == 4
    assert len(kw) == 2
    assert args == (1, 2, 3, 4)
    assert kw == {'foo': 'bar', 'bar': 'baz'}


def test_partial_variadic_arguments():

    task = partial(coro, 1)