Skip to content

Commit e3f57d2

Browse files
committed
added additional tests for run_sync
1 parent eacbae7 commit e3f57d2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/utils/test_sync.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import asyncio
2+
from unittest import TestCase
3+
4+
from piccolo.utils.sync import run_sync
5+
6+
7+
class TestSync(TestCase):
8+
def test_sync_simple(self):
9+
"""
10+
Test calling a simple coroutine.
11+
"""
12+
run_sync(asyncio.sleep(0.1))
13+
14+
def test_sync_nested(self):
15+
"""
16+
Test calling a coroutine, which contains a call to `run_sync`.
17+
"""
18+
19+
async def test():
20+
run_sync(asyncio.sleep(0.1))
21+
22+
run_sync(test())
23+
24+
def test_sync_stopped_event_loop(self):
25+
"""
26+
Test calling a coroutine, when the current thread has an event loop,
27+
but it isn't running.
28+
"""
29+
loop = asyncio.new_event_loop()
30+
asyncio.set_event_loop(loop)
31+
32+
run_sync(asyncio.sleep(0.1))
33+
34+
asyncio.set_event_loop(None)

0 commit comments

Comments
 (0)