Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to pytest and jupyter-server #128

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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