Skip to content

Commit 9519843

Browse files
committed
Switch to pytest and jupyter-server for testing
1 parent 5d69e11 commit 9519843

File tree

5 files changed

+1666
-1680
lines changed

5 files changed

+1666
-1680
lines changed

conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import pytest
2+
3+
pytest_plugins = ["jupyter_server.pytest_plugin"]
4+
5+
6+
@pytest.fixture
7+
def jp_server_config(jp_server_config):
8+
return {"ServerApp": {"jpserver_extensions": {"mamba_gator": True}}}

mamba_gator/tests/conftest.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import asyncio
2+
import datetime
3+
import logging
4+
import re
5+
from unittest.mock import patch
6+
7+
import pytest
8+
import tornado
9+
from mamba_gator.handlers import NS
10+
11+
TIMEOUT = 150
12+
SLEEP = 1
13+
14+
15+
@pytest.fixture
16+
def wait_task(jp_fetch):
17+
async def foo(endpoint: str):
18+
start_time = datetime.datetime.now()
19+
20+
while (datetime.datetime.now() - start_time).total_seconds() < TIMEOUT:
21+
await asyncio.sleep(SLEEP)
22+
response = await jp_fetch(endpoint.lstrip("/"), method="GET")
23+
if not (200 <= response.code < 300):
24+
raise tornado.web.HTTPError(response.code, str(response))
25+
elif response.code != 202:
26+
return response
27+
28+
raise RuntimeError("Request {} timed out.".format(endpoint))
29+
30+
return foo
31+
32+
33+
@pytest.fixture
34+
def wait_for_task(wait_task, jp_fetch):
35+
async def foo(*args, **kwargs):
36+
r = await jp_fetch(*args, **kwargs)
37+
assert r.code == 202
38+
location = r.headers["Location"]
39+
assert re.match(r"^/conda/tasks/\d+$", location) is not None
40+
return await wait_task(location)
41+
42+
return foo

0 commit comments

Comments
 (0)