-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
71 additions
and
42 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
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
This file was deleted.
Oops, something went wrong.
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,56 @@ | ||
"""Tests for utils""" | ||
|
||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
import asyncio | ||
import os | ||
import tempfile | ||
|
||
import pytest | ||
|
||
from jupyter_core.utils import deprecation, ensure_async, ensure_dir_exists, run_sync | ||
|
||
|
||
def test_ensure_dir_exists(): | ||
with tempfile.TemporaryDirectory() as td: | ||
ensure_dir_exists(td) | ||
ensure_dir_exists(os.path.join(str(td), "foo"), 0o777) | ||
|
||
|
||
def test_deprecation(): | ||
with pytest.deprecated_call(): | ||
deprecation("foo") | ||
|
||
|
||
async def afunc(): | ||
return "afunc" | ||
|
||
|
||
def func(): | ||
return "func" | ||
|
||
|
||
sync_afunc = run_sync(afunc) | ||
|
||
|
||
def test_run_sync(): | ||
async def foo(): | ||
return 1 | ||
|
||
foo_sync = run_sync(foo) | ||
assert foo_sync() == 1 | ||
assert foo_sync() == 1 | ||
|
||
asyncio.set_event_loop(None) | ||
assert foo_sync() == 1 | ||
|
||
asyncio.run(foo()) | ||
|
||
|
||
def test_ensure_async(): | ||
async def main(): | ||
assert await ensure_async(afunc()) == "afunc" | ||
assert await ensure_async(func()) == "func" | ||
|
||
asyncio.run(main()) |