-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to pytest and jupyter-server for testing
- Loading branch information
1 parent
5d69e11
commit 9519843
Showing
5 changed files
with
1,666 additions
and
1,680 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,8 @@ | ||
import pytest | ||
|
||
pytest_plugins = ["jupyter_server.pytest_plugin"] | ||
|
||
|
||
@pytest.fixture | ||
def jp_server_config(jp_server_config): | ||
return {"ServerApp": {"jpserver_extensions": {"mamba_gator": True}}} |
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,42 @@ | ||
import asyncio | ||
import datetime | ||
import logging | ||
import re | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
import tornado | ||
from mamba_gator.handlers import NS | ||
|
||
TIMEOUT = 150 | ||
SLEEP = 1 | ||
|
||
|
||
@pytest.fixture | ||
def wait_task(jp_fetch): | ||
async def foo(endpoint: str): | ||
start_time = datetime.datetime.now() | ||
|
||
while (datetime.datetime.now() - start_time).total_seconds() < TIMEOUT: | ||
await asyncio.sleep(SLEEP) | ||
response = await jp_fetch(endpoint.lstrip("/"), method="GET") | ||
if not (200 <= response.code < 300): | ||
raise tornado.web.HTTPError(response.code, str(response)) | ||
elif response.code != 202: | ||
return response | ||
|
||
raise RuntimeError("Request {} timed out.".format(endpoint)) | ||
|
||
return foo | ||
|
||
|
||
@pytest.fixture | ||
def wait_for_task(wait_task, jp_fetch): | ||
async def foo(*args, **kwargs): | ||
r = await jp_fetch(*args, **kwargs) | ||
assert r.code == 202 | ||
location = r.headers["Location"] | ||
assert re.match(r"^/conda/tasks/\d+$", location) is not None | ||
return await wait_task(location) | ||
|
||
return foo |
Oops, something went wrong.