File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments