Skip to content

Commit

Permalink
Switch to pytest and jupyter-server for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Feb 28, 2021
1 parent 5d69e11 commit 9519843
Show file tree
Hide file tree
Showing 5 changed files with 1,666 additions and 1,680 deletions.
8 changes: 8 additions & 0 deletions conftest.py
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}}}
42 changes: 42 additions & 0 deletions mamba_gator/tests/conftest.py
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
Loading

0 comments on commit 9519843

Please sign in to comment.