forked from jupyter/jupyter_core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add run_sync and ensure_async functions (jupyter#315)
- Loading branch information
1 parent
f7e1f00
commit 51b8a12
Showing
2 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Tests for async helper functions""" | ||
|
||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
import asyncio | ||
|
||
from jupyter_core.utils import ensure_async, run_sync | ||
|
||
|
||
async def afunc(): | ||
return "afunc" | ||
|
||
|
||
def func(): | ||
return "func" | ||
|
||
|
||
sync_afunc = run_sync(afunc) | ||
|
||
|
||
def test_ensure_async(): | ||
async def main(): | ||
assert await ensure_async(afunc()) == "afunc" | ||
assert await ensure_async(func()) == "func" | ||
|
||
asyncio.run(main()) | ||
|
||
|
||
def test_run_sync(): | ||
async def main(): | ||
assert sync_afunc() == "afunc" | ||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters