File: test_awaitable_35.py

package info (click to toggle)
python-promise 2.3.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 400 kB
  • sloc: python: 2,681; sh: 13; makefile: 4
file content (47 lines) | stat: -rw-r--r-- 980 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from asyncio import sleep, Future, wait, FIRST_COMPLETED
from pytest import mark
from promise import Promise, is_thenable


@mark.asyncio
async def test_await():
    assert await Promise.resolve(True)


@mark.asyncio
async def test_promisify_coroutine():
    async def my_coroutine():
        await sleep(.01)
        return True

    assert await Promise.resolve(my_coroutine())


@mark.asyncio
async def test_coroutine_is_thenable():
    async def my_coroutine():
        await sleep(.01)
        return True

    assert is_thenable(my_coroutine())


@mark.asyncio
async def test_promisify_future():
    future = Future()
    future.set_result(True)
    assert await Promise.resolve(future)


@mark.asyncio
async def test_await_in_safe_promise():
    async def inner():
        @Promise.safe
        def x():
            promise = Promise.resolve(True).then(lambda x: x)
            return promise

        return await x()

    result = await inner()
    assert result == True