# Path: paco/wraps.py
# def wraps(fn):
#     """
#     Wraps a given function as coroutine function.
# 
#     This function can be used as decorator.
# 
#     Arguments:
#         fn (function): function object to wrap.
# 
#     Returns:
#         coroutinefunction: wrapped function as coroutine.
# 
#     Usage::
# 
#         def mul_2(num):
#             return num * 2
# 
#         # Use as function wrapper
#         coro = paco.wraps(mul_2)
#         await coro(2)
#         # => 4
# 
#         # Use as decorator
#         @paco.wraps
#         def mul_2(num):
#             return num * 2
# 
#         await mul_2(2)
#         # => 4
# 
#     """
#     return asyncio.coroutine(fn)
# 
# 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 wraps
from .helpers import run_in_loop
# -*- coding: utf-8 -*-


def task(*args, **kw):
    return args, kw


def test_wraps():
    coro = wraps(task)

    args, kw = run_in_loop(coro, 1, 2, foo='bar')
    assert args == (1, 2)
    assert kw == {'foo': 'bar'}


# Path: paco/wraps.py
# def wraps(fn):
#     """
#     Wraps a given function as coroutine function.
# 
#     This function can be used as decorator.
# 
#     Arguments:
#         fn (function): function object to wrap.
# 
#     Returns:
#         coroutinefunction: wrapped function as coroutine.
# 
#     Usage::
# 
#         def mul_2(num):
#             return num * 2
# 
#         # Use as function wrapper
#         coro = paco.wraps(mul_2)
#         await coro(2)
#         # => 4
# 
#         # Use as decorator
#         @paco.wraps
#         def mul_2(num):
#             return num * 2
# 
#         await mul_2(2)
#         # => 4
# 
#     """
#     return asyncio.coroutine(fn)
# 
# 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/wraps_test.py
import asyncio
from paco import wraps
from .helpers import run_in_loop

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


def task(*args, **kw):
    return args, kw


def test_wraps():
    coro = wraps(task)

    args, kw = run_in_loop(coro, 1, 2, foo='bar')
    assert args == (1, 2)
    assert kw == {'foo': 'bar'}


    args, kw = run_in_loop(coro, 3, 4, foo='baz')