Esempio n. 1
0
def test_kwargs_loop(loop):
    c = 0

    @armor(kwargs=True, loop='_loop')
    @asyncio.coroutine
    def coro(*, _loop):
        nonlocal c
        yield from asyncio.sleep(SLEEP, loop=_loop)
        c = 1

    task = ensure_future(coro(_loop=loop), loop=loop)
    task.cancel()

    armor.close()
    yield from armor.wait_closed(loop=loop)

    assert c == 1
Esempio n. 2
0
def test_explicit_loop(loop):
    c = 0

    @armor(loop=loop)
    @asyncio.coroutine
    def coro():
        nonlocal c
        yield from asyncio.sleep(SLEEP, loop=loop)
        c = 1

    task = ensure_future(coro(), loop=loop)
    task.cancel()

    armor.close()
    yield from armor.wait_closed(loop=loop)

    assert c == 1
Esempio n. 3
0
def test_default_loop(loop):
    asyncio.set_event_loop(loop)

    c = 0

    @armor
    @asyncio.coroutine
    def coro():
        nonlocal c
        yield from asyncio.sleep(SLEEP)
        c = 1

    task = ensure_future(coro())
    task.cancel()

    armor.close()
    yield from armor.wait_closed()

    assert c == 1
Esempio n. 4
0
def test_cls_loop(loop):
    c = 0

    class Obj:
        def __init__(self, *, loop):
            self._loop = loop

        @armor(cls=True, loop='_loop')
        @asyncio.coroutine
        def coro(self):
            nonlocal c
            yield from asyncio.sleep(SLEEP, loop=self._loop)
            c = 1

    task = ensure_future(Obj(loop=loop).coro(), loop=loop)
    task.cancel()

    armor.close()
    yield from armor.wait_closed(loop=loop)

    assert c == 1
Esempio n. 5
0
def test_shield_inner(loop):
    asyncio.set_event_loop(loop)

    c = 0

    @asyncio.coroutine
    def coro():
        nonlocal c
        yield from asyncio.sleep(SLEEP)
        c = 1

    @asyncio.coroutine
    def inner():
        yield from armor(coro())

    task = ensure_future(inner())
    yield from asyncio.sleep(SLEEP / 2)
    task.cancel()

    armor.close()
    yield from armor.wait_closed()

    assert c == 1