Exemplo n.º 1
0
    async def test_set(self, loop: Any) -> None:
        ev = EventResultOrError(loop=loop)

        async def c() -> int:
            await ev.wait()
            return 1

        t = loop.create_task(c())
        await asyncio.sleep(0, loop=loop)
        ev.set()
        assert (await t) == 1
Exemplo n.º 2
0
    async def test_set(self, loop) -> None:
        ev = EventResultOrError(loop=loop)

        async def c():
            await ev.wait()
            return 1

        t = loop.create_task(c())
        await asyncio.sleep(0, loop=loop)
        ev.set()
        assert (await t) == 1
Exemplo n.º 3
0
    async def test_set(self, loop):
        ev = EventResultOrError(loop=loop)

        async def c():
            await ev.wait()
            return 1

        t = asyncio.ensure_future(c(), loop=loop)
        await asyncio.sleep(0, loop=loop)
        ev.set()
        assert (await t) == 1
Exemplo n.º 4
0
    def test_set(self, loop):
        ev = EventResultOrError(loop=loop)

        @asyncio.coroutine
        def c():
            yield from ev.wait()
            return 1

        t = helpers.ensure_future(c(), loop=loop)
        yield from asyncio.sleep(0, loop=loop)
        ev.set()
        assert (yield from t) == 1
Exemplo n.º 5
0
    def test_set(self, loop):
        ev = EventResultOrError(loop=loop)

        @asyncio.coroutine
        def c():
            yield from ev.wait()
            return 1

        t = asyncio.ensure_future(c(), loop=loop)
        yield from asyncio.sleep(0, loop=loop)
        ev.set()
        assert (yield from t) == 1
Exemplo n.º 6
0
    async def test_set_exception(self, loop: Any) -> None:
        ev = EventResultOrError(loop=loop)

        async def c() -> Union[int, Exception]:
            try:
                await ev.wait()
            except Exception as e:
                return e
            return 1

        t = loop.create_task(c())
        await asyncio.sleep(0, loop=loop)
        e = Exception()
        ev.set(exc=e)
        assert (await t) == e
Exemplo n.º 7
0
    async def test_set_exception(self, loop):
        ev = EventResultOrError(loop=loop)

        async def c():
            try:
                await ev.wait()
            except Exception as e:
                return e
            return 1

        t = asyncio.ensure_future(c(), loop=loop)
        await asyncio.sleep(0, loop=loop)
        e = Exception()
        ev.set(exc=e)
        assert (await t) == e
Exemplo n.º 8
0
    async def test_set_exception(self, loop) -> None:
        ev = EventResultOrError(loop=loop)

        async def c():
            try:
                await ev.wait()
            except Exception as e:
                return e
            return 1

        t = loop.create_task(c())
        await asyncio.sleep(0, loop=loop)
        e = Exception()
        ev.set(exc=e)
        assert (await t) == e
Exemplo n.º 9
0
    def test_set_exception(self, loop):
        ev = EventResultOrError(loop=loop)

        @asyncio.coroutine
        def c():
            try:
                yield from ev.wait()
            except Exception as e:
                return e
            return 1

        t = helpers.ensure_future(c(), loop=loop)
        yield from asyncio.sleep(0, loop=loop)
        e = Exception()
        ev.set(exc=e)
        assert (yield from t) == e
Exemplo n.º 10
0
    def test_set_exception(self, loop):
        ev = EventResultOrError(loop=loop)

        @asyncio.coroutine
        def c():
            try:
                yield from ev.wait()
            except Exception as e:
                return e
            return 1

        t = asyncio.ensure_future(c(), loop=loop)
        yield from asyncio.sleep(0, loop=loop)
        e = Exception()
        ev.set(exc=e)
        assert (yield from t) == e
Exemplo n.º 11
0
    async def test_cancel_waiters(self, loop) -> None:
        ev = EventResultOrError(loop=loop)

        async def c():
            await ev.wait()

        t1 = loop.create_task(c())
        t2 = loop.create_task(c())
        await asyncio.sleep(0, loop=loop)
        ev.cancel()
        ev.set()

        with pytest.raises(asyncio.CancelledError):
            await t1

        with pytest.raises(asyncio.CancelledError):
            await t2
Exemplo n.º 12
0
    def test_cancel_waiters(self, loop):
        ev = EventResultOrError(loop=loop)

        @asyncio.coroutine
        def c():
            yield from ev.wait()

        t1 = helpers.ensure_future(c(), loop=loop)
        t2 = helpers.ensure_future(c(), loop=loop)
        yield from asyncio.sleep(0, loop=loop)
        ev.cancel()
        ev.set()

        with pytest.raises(asyncio.futures.CancelledError):
            yield from t1

        with pytest.raises(asyncio.futures.CancelledError):
            yield from t2
Exemplo n.º 13
0
    async def test_cancel_waiters(self, loop: Any) -> None:
        ev = EventResultOrError(loop=loop)

        async def c() -> None:
            await ev.wait()

        t1 = loop.create_task(c())
        t2 = loop.create_task(c())
        await asyncio.sleep(0, loop=loop)
        ev.cancel()
        ev.set()

        with pytest.raises(asyncio.CancelledError):
            await t1

        with pytest.raises(asyncio.CancelledError):
            await t2
Exemplo n.º 14
0
    async def test_cancel_waiters(self, loop):
        ev = EventResultOrError(loop=loop)

        async def c():
            await ev.wait()

        t1 = asyncio.ensure_future(c(), loop=loop)
        t2 = asyncio.ensure_future(c(), loop=loop)
        await asyncio.sleep(0, loop=loop)
        ev.cancel()
        ev.set()

        with pytest.raises(asyncio.CancelledError):
            await t1

        with pytest.raises(asyncio.CancelledError):
            await t2
Exemplo n.º 15
0
    def test_cancel_waiters(self, loop):
        ev = EventResultOrError(loop=loop)

        @asyncio.coroutine
        def c():
            yield from ev.wait()

        t1 = asyncio.ensure_future(c(), loop=loop)
        t2 = asyncio.ensure_future(c(), loop=loop)
        yield from asyncio.sleep(0, loop=loop)
        ev.cancel()
        ev.set()

        with pytest.raises(asyncio.futures.CancelledError):
            yield from t1

        with pytest.raises(asyncio.futures.CancelledError):
            yield from t2