forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sync.py
More file actions
34 lines (25 loc) · 799 Bytes
/
test_sync.py
File metadata and controls
34 lines (25 loc) · 799 Bytes
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
import asyncio
from unittest import TestCase
from piccolo.utils.sync import run_sync
class TestSync(TestCase):
def test_sync_simple(self):
"""
Test calling a simple coroutine.
"""
run_sync(asyncio.sleep(0.1))
def test_sync_nested(self):
"""
Test calling a coroutine, which contains a call to `run_sync`.
"""
async def test():
run_sync(asyncio.sleep(0.1))
run_sync(test())
def test_sync_stopped_event_loop(self):
"""
Test calling a coroutine, when the current thread has an event loop,
but it isn't running.
"""
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
run_sync(asyncio.sleep(0.1))
asyncio.set_event_loop(None)