summaryrefslogtreecommitdiff
path: root/tests/test_coroutine.py
blob: 3dbe5dbcdd91c7c38b4e2f83e433a97d08a61910 (plain)
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
import tests

try:
    import asyncio

    exec('''if 1:
        def hello_world(result, delay):
            result.append("Hello")
            # retrieve the event loop from the policy
            yield from asyncio.sleep(delay)
            result.append('World')
    ''')
except ImportError:
    import trollius as asyncio
    from trollius import From

    def hello_world(result, delay):
        result.append("Hello")
        # retrieve the event loop from the policy
        yield From(asyncio.sleep(delay))
        result.append('World')

class CallbackTests(tests.TestCase):
    def test_hello_world(self):
        result = []
        self.loop.run_until_complete(hello_world(result, 0.001))
        self.assertEqual(result, ['Hello', 'World'])